diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 0000000..8c9ea49 --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,35 @@ +name: Build +on: push + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v6 + with: + persist-credentials: false + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v6 + + - name: Set up Java + uses: actions/setup-java@v5 + with: + distribution: 'temurin' + java-version: 25 + - name: Change wrapper permissions + run: chmod +x ./gradlew + - name: Build with Gradle + run: ./gradlew build + + - name: Release + uses: softprops/action-gh-release@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + tag_name: snapshot + name: Dev Build + prerelease: true + files: | + ./build/libs/*.jar diff --git a/.gitignore b/.gitignore index 1223828..b1e2e7c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ /.project /.factorypath /.classpath +/.idea/ diff --git a/build.gradle b/build.gradle index b52b805..9b0b669 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.12-SNAPSHOT' + id 'net.fabricmc.fabric-loom' version '1.17-SNAPSHOT' id 'maven-publish' } @@ -22,10 +22,9 @@ repositories { dependencies { // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + implementation "net.fabricmc:fabric-loader:${project.loader_version}" - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" } processResources { @@ -41,7 +40,7 @@ processResources { } } -def targetJavaVersion = 21 +def targetJavaVersion = 25 tasks.withType(JavaCompile).configureEach { // ensure that the encoding is set to UTF-8, no matter what the system default is // this fixes some edge cases with special characters not displaying correctly diff --git a/gradle.properties b/gradle.properties index 44de399..e73e29e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,13 +2,12 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://modmuss50.me/fabric.html -minecraft_version=1.21.10 -yarn_mappings=1.21.10+build.2 -loader_version=0.17.3 +minecraft_version=26.2 +loader_version=0.19.3 # Mod Properties -mod_version=1.21.10-1.0 +mod_version=16.2-1.0 maven_group=com.samxel archives_base_name=VillagerExplorer # Dependencies # check this on https://modmuss50.me/fabric.html -fabric_version=0.136.0+1.21.10 +fabric_version=0.155.2+26.2 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..b1b8ef5 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0ceb5e9..df6a6ad 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1 +1,9 @@ -distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-bin.zip +networkTimeout=10000 +retries=0 +retryBackOffMs=500 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..b9bb139 --- /dev/null +++ b/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..24c62d5 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,82 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables, and ensure extensions are enabled +setlocal EnableExtensions + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +"%COMSPEC%" /c exit 1 + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +"%COMSPEC%" /c exit 1 + +:execute +@rem Setup the command line + + + +@rem Execute Gradle +@rem endlocal doesn't take effect until after the line is parsed and variables are expanded +@rem which allows us to clear the local environment before executing the java command +endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel + +:exitWithErrorLevel +@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts +"%COMSPEC%" /c exit %ERRORLEVEL% diff --git a/src/main/java/com/samxel/villagerexplorer/VillagerExplorerScreen.java b/src/main/java/com/samxel/villagerexplorer/VillagerExplorerScreen.java index 513c80e..b00b579 100644 --- a/src/main/java/com/samxel/villagerexplorer/VillagerExplorerScreen.java +++ b/src/main/java/com/samxel/villagerexplorer/VillagerExplorerScreen.java @@ -1,24 +1,6 @@ package com.samxel.villagerexplorer; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.Click; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.widget.TextFieldWidget; -import net.minecraft.client.input.CharInput; -import net.minecraft.client.input.KeyInput; -import net.minecraft.client.render.entity.EntityRenderManager; -import net.minecraft.client.render.entity.EntityRenderer; -import net.minecraft.client.render.entity.state.EntityRenderState; -import net.minecraft.client.render.entity.state.LivingEntityRenderState; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.SpawnReason; -import net.minecraft.entity.passive.VillagerEntity; -import net.minecraft.registry.Registries; -import net.minecraft.registry.entry.RegistryEntry; -import net.minecraft.text.Text; -import net.minecraft.village.VillagerProfession; +import net.minecraft.world.entity.EntityTypes; import org.jetbrains.annotations.Nullable; import org.joml.Quaternionf; import org.joml.Vector3f; @@ -26,42 +8,60 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphicsExtractor; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.input.CharacterEvent; +import net.minecraft.client.input.KeyEvent; +import net.minecraft.client.input.MouseButtonEvent; +import net.minecraft.client.renderer.entity.EntityRenderDispatcher; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.client.renderer.entity.state.EntityRenderState; +import net.minecraft.client.renderer.entity.state.LivingEntityRenderState; +import net.minecraft.core.Holder; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.EntitySpawnReason; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.npc.villager.Villager; +import net.minecraft.world.entity.npc.villager.VillagerProfession; public class VillagerExplorerScreen extends Screen { private final List allVillagers = List.of( - "Farmer", - "Librarian", - "Cleric", "Armorer", "Butcher", "Cartographer", + "Cleric", + "Farmer", "Fisherman", "Fletcher", "Leatherworker", + "Librarian", "Mason", "Shepherd", "Toolsmith", "Weaponsmith"); private final int windowWidth = 420; - private final int windowHeight = 340; - private final int tileSize = 90; - private final int tileSpacing = 18; - private final int tilesPerRow = 3; - private final int tileAreaTop = 140; + private final int windowHeight = 320; + private final int tileSize = 65; + private final int tileSpacing = 5; + private final int tilesPerRow = 5; + private final int tileAreaTop = 80; private final int tileAreaBottom = windowHeight - 20; private final List visibleTiles = new ArrayList<>(); - private TextFieldWidget searchField; + private EditBox searchField; private List filteredVillagers = new ArrayList<>(); private int scrollOffset = 0; private int maxScroll = 0; public VillagerExplorerScreen() { - super(Text.of("Villager Explorer")); + super(Component.nullToEmpty("Villager kutss Explorer")); } public static void renderVillagerInBox( - DrawContext drawer, + GuiGraphicsExtractor drawer, int x1, int y1, int x2, int y2, float scale, Vector3f translation, @@ -69,19 +69,18 @@ public static void renderVillagerInBox( @Nullable Quaternionf overrideCameraAngle, LivingEntity entity ) { - EntityRenderManager entityRenderManager = MinecraftClient.getInstance().getEntityRenderDispatcher(); + EntityRenderDispatcher entityRenderManager = Minecraft.getInstance().getEntityRenderDispatcher(); EntityRenderer entityRenderer = entityRenderManager.getRenderer(entity); - EntityRenderState entityRenderState = entityRenderer.getAndUpdateRenderState(entity, 1.0F); + EntityRenderState entityRenderState = entityRenderer.createRenderState(entity, 1.0F); if (entityRenderState instanceof LivingEntityRenderState state) { - state.bodyYaw = yaw; - state.pitch = pitch; - state.relativeHeadYaw = yaw; + state.bodyRot = yaw; + state.xRot = pitch; + state.yRot = yaw; } - entityRenderState.light = 15728880; - entityRenderState.hitbox = null; + entityRenderState.lightCoords = 15728880; entityRenderState.shadowPieces.clear(); entityRenderState.outlineColor = 0; @@ -92,7 +91,7 @@ public static void renderVillagerInBox( .rotateX((float) Math.toRadians(pitch)); - drawer.addEntity(entityRenderState, scale, translation, rotation, overrideCameraAngle, x1, y1, x2, y2); + drawer.entity(entityRenderState, scale, translation, rotation, overrideCameraAngle, x1, y1, x2, y2); } @Override @@ -102,11 +101,11 @@ protected void init() { int windowY = this.height / 2 - windowHeight / 2; this.searchField = - new TextFieldWidget( - this.textRenderer, windowX + 20, windowY + 85, windowWidth - 40, 20, - Text.of("Search Villager")); - this.searchField.setChangedListener(this::updateFilter); - this.addDrawableChild(this.searchField); + new EditBox( + this.font, windowX + 30, windowY + 45, windowWidth - 60, 20, + Component.nullToEmpty("Search Villager")); + this.searchField.setResponder(this::updateFilter); + this.addRenderableWidget(this.searchField); this.setInitialFocus(this.searchField); this.updateFilter(""); @@ -142,7 +141,7 @@ public boolean mouseScrolled( } @Override - public boolean keyPressed(KeyInput input) { + public boolean keyPressed(KeyEvent input) { if (this.searchField.keyPressed(input)) { return true; } @@ -165,7 +164,7 @@ public boolean keyPressed(KeyInput input) { } @Override - public boolean charTyped(CharInput input) { + public boolean charTyped(CharacterEvent input) { if (this.searchField.charTyped(input)) { return true; } @@ -173,7 +172,7 @@ public boolean charTyped(CharInput input) { } @Override - public boolean mouseClicked(Click click, boolean doubled) { + public boolean mouseClicked(MouseButtonEvent click, boolean doubled) { if (super.mouseClicked(click, doubled)) { return true; } @@ -182,7 +181,7 @@ public boolean mouseClicked(Click click, boolean doubled) { double mouseY = click.y(); for (VillagerTile tile : visibleTiles) { if (tile.contains(mouseX, mouseY)) { - MinecraftClient.getInstance().setScreen(new VillagerInfoScreen(tile.name)); + Minecraft.getInstance().gui.setScreen(new VillagerInfoScreen(tile.name)); return true; } } @@ -191,8 +190,8 @@ public boolean mouseClicked(Click click, boolean doubled) { } @Override - public void render(DrawContext context, int mouseX, int mouseY, float delta) { - super.render(context, mouseX, mouseY, delta); + public void extractRenderState(GuiGraphicsExtractor context, int mouseX, int mouseY, float delta) { + super.extractRenderState(context, mouseX, mouseY, delta); int centerX = this.width / 2; int centerY = this.height / 2; @@ -202,14 +201,14 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { context.fill(windowX, windowY, windowX + windowWidth, windowY + windowHeight, 0xCC222222); - context.drawStrokedRectangle(windowX, windowY, windowWidth, windowHeight, 0xFF000000); + context.outline(windowX, windowY, windowWidth, windowHeight, 0xFF000000);; String titleText = "Villager Explorer"; - int titleWidth = this.textRenderer.getWidth(titleText); + int titleWidth = this.font.width(titleText); int titleX = windowX + (windowWidth - titleWidth) / 2; - int titleY = windowY + 55; - context.drawText(this.textRenderer, Text.of(titleText), titleX, titleY, 0xFFFFFFFF, false); + int titleY = windowY + 25; + context.text(this.font, Component.nullToEmpty(titleText), titleX, titleY, 0xFFFFFFFF, false); int startY = windowY + tileAreaTop; @@ -235,28 +234,31 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { context.fill(x, y, x + tileSize, y + tileSize, 0x10FFFFFF); - context.drawStrokedRectangle(x, y, tileSize, tileSize, 0xFFFFFFFF); + context.outline(x, y, tileSize, tileSize, 0xFFFFFFFF); String villagerName = filteredVillagers.get(idx); - MinecraftClient client = MinecraftClient.getInstance(); - if (client.world == null) continue; + Minecraft client = Minecraft.getInstance(); + if (client.level == null) continue; - VillagerEntity villager = - EntityType.VILLAGER.create(client.world, SpawnReason.TRIGGERED); - if (villager == null) continue; + Villager villager = + EntityTypes.VILLAGER.create(client.level, EntitySpawnReason.TRIGGERED); + + if (villager != null) { + villager.setId(client.level.getEntityCount()); + } VillagerProfession prof = VillagerUtils.getProfessionByName(villagerName); - RegistryEntry entry = - Registries.VILLAGER_PROFESSION.getEntry(prof); + Holder entry = + BuiltInRegistries.VILLAGER_PROFESSION.wrapAsHolder(prof); villager.setVillagerData(villager.getVillagerData().withProfession(entry)); int boxHalf = 28; int x1 = x + tileSize / 2 - boxHalf; - int y1 = y + 10; + int y1 = y - 10; int x2 = x + tileSize / 2 + boxHalf; int y2 = y + 10 + boxHalf * 2; @@ -268,20 +270,32 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { renderVillagerInBox( context, x1, y1, x2, y2, - 30.0f, - new Vector3f(0, 1, 0), + 28.0f, + new Vector3f(0, 1.2f, 0), yaw, pitch, null, villager ); - int nWidth = this.textRenderer.getWidth(villagerName); + float textScale = 0.8f; + + int nWidth = (int)(this.font.width(villagerName) * textScale); int NameTextX = x + (tileSize - nWidth) / 2; - context.drawText( - this.textRenderer, Text.of(villagerName), - NameTextX, y + tileSize - 18, 0xFFFFFFFF, false); + context.pose().pushMatrix(); + context.pose().scale(textScale, textScale); + + context.text( + this.font, + Component.nullToEmpty(villagerName), + (int)(NameTextX / textScale), + (int)((y + tileSize - 18) / textScale), + 0xFFFFFFFF, + false + ); + + context.pose().popMatrix(); visibleTiles.add(new VillagerTile(x, y, tileSize, tileSize, idx, villagerName)); } } @@ -300,7 +314,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { } - this.searchField.render(context, mouseX, mouseY, delta); + this.searchField.extractRenderState(context, mouseX, mouseY, delta); } private static class VillagerTile { diff --git a/src/main/java/com/samxel/villagerexplorer/VillagerInfoScreen.java b/src/main/java/com/samxel/villagerexplorer/VillagerInfoScreen.java index 6dc7410..9d8e15f 100644 --- a/src/main/java/com/samxel/villagerexplorer/VillagerInfoScreen.java +++ b/src/main/java/com/samxel/villagerexplorer/VillagerInfoScreen.java @@ -1,31 +1,38 @@ package com.samxel.villagerexplorer; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.client.gui.screen.ingame.InventoryScreen; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.SpawnReason; -import net.minecraft.entity.passive.VillagerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.registry.Registries; -import net.minecraft.registry.entry.RegistryEntry; -import net.minecraft.text.Text; -import net.minecraft.village.VillagerProfession; - import java.util.ArrayList; import java.util.List; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphicsExtractor; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.inventory.InventoryScreen; +import net.minecraft.client.renderer.entity.EntityRenderDispatcher; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.client.renderer.entity.state.EntityRenderState; +import net.minecraft.client.renderer.entity.state.LivingEntityRenderState; +import net.minecraft.core.Holder; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.EntitySpawnReason; +import net.minecraft.world.entity.EntityTypes; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.npc.villager.Villager; +import net.minecraft.world.entity.npc.villager.VillagerProfession; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import org.jetbrains.annotations.Nullable; +import org.joml.Quaternionf; +import org.joml.Vector3f; public class VillagerInfoScreen extends Screen { - private static final int TRADES_VISIBLE = 7; + private static final int TRADES_VISIBLE = 13; private final int windowWidth = 420; - private final int windowHeight = 340; + private final int windowHeight = 320; private final String villagerName; private int tradeScrollOffset = 0; public VillagerInfoScreen(String villagerName) { - super(Text.of("Villager Info")); + super(Component.nullToEmpty("Villager Info")); this.villagerName = villagerName; } @@ -49,8 +56,54 @@ public boolean mouseScrolled( return true; } + public static void renderVillagerInBoxx( + GuiGraphicsExtractor drawer, + int x1, int y1, int x2, int y2, + float scale, + Vector3f translation, + float yaw, + float pitch, + @Nullable Quaternionf overrideCameraAngle, + LivingEntity entity + ) { + EntityRenderDispatcher dispatcher = Minecraft.getInstance().getEntityRenderDispatcher(); + EntityRenderer renderer = dispatcher.getRenderer(entity); + + EntityRenderState renderState = renderer.createRenderState(entity, 1.0F); + + if (renderState instanceof LivingEntityRenderState living) { + living.bodyRot = 180.0F + yaw; + living.yRot = yaw; + living.xRot = -pitch; + } + + renderState.lightCoords = 15728880; + renderState.shadowPieces.clear(); + renderState.outlineColor = 0; + + Quaternionf rotation = new Quaternionf() + .rotateZ((float)Math.PI); + + rotation.mul( + new Quaternionf() + .rotateX((float)Math.toRadians(pitch)) + ); + + drawer.entity( + renderState, + scale, + translation, + rotation, + overrideCameraAngle, + x1, + y1, + x2, + y2 + ); + } + @Override - public void render(DrawContext context, int mouseX, int mouseY, float delta) { + public void extractRenderState(GuiGraphicsExtractor context, int mouseX, int mouseY, float delta) { int centerX = this.width / 2; @@ -60,24 +113,26 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { context.fill(windowX, windowY, windowX + windowWidth, windowY + windowHeight, 0xCC222222); - context.drawStrokedRectangle(windowX, windowY, windowWidth, windowHeight, 0xFF000000); + context.outline(windowX, windowY, windowWidth, windowHeight, 0xFF000000); - context.drawText(this.textRenderer, Text.of(this.villagerName), - windowX + 30, windowY + 70, 0xFFFFFFFF, false); + context.text(this.font, Component.nullToEmpty(this.villagerName), + windowX + 10, windowY + 5, 0xFFFFFFFF, false); int villagerX = windowX + windowWidth - 70; int villagerY = windowY + 150; int villagerScale = 45; - MinecraftClient client = MinecraftClient.getInstance(); - if (client.world != null) { - VillagerEntity villager = EntityType.VILLAGER.create(client.world, SpawnReason.TRIGGERED); + Minecraft client = Minecraft.getInstance(); + if (client.level != null) { + Villager villager = EntityTypes.VILLAGER.create(client.level, EntitySpawnReason.TRIGGERED); + if (villager != null) { + villager.setId(-1); VillagerProfession prof = VillagerUtils.getProfessionByName(this.villagerName); - RegistryEntry profEntry = Registries.VILLAGER_PROFESSION.getEntry(prof); + Holder profEntry = BuiltInRegistries.VILLAGER_PROFESSION.wrapAsHolder(prof); villager.setVillagerData(villager.getVillagerData().withProfession(profEntry)); @@ -86,25 +141,21 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { int x2 = villagerX + 25; int y2 = villagerY + 90; + int centerBoxX = (x1 + x2) / 2; + int centerBoxY = (y1 + y2) / 2; - float mouseYaw = (float) Math.atan((villagerX - mouseX) / 40.0F); - float mousePitch = (float) Math.atan((villagerY - mouseY) / 40.0F); + float yaw = (float)Math.atan((centerBoxX - mouseX) / 40.0F) * 20.0F; + float pitch = (float)Math.atan((centerBoxY - mouseY) / 40.0F) * 20.0F; - villager.setBodyYaw(180.0F + mouseYaw * 20.0F); - villager.setHeadYaw(180.0F + mouseYaw * 40.0F); - villager.setPitch(mousePitch * 20.0F); - - villager.lastBodyYaw = villager.getBodyYaw(); - villager.lastHeadYaw = villager.getHeadYaw(); - villager.lastPitch = villager.getPitch(); - - - InventoryScreen.drawEntity( + renderVillagerInBoxx( context, x1, y1, x2, y2, - villagerScale, 1.0f, - mouseX, mouseY, + villagerScale, + new Vector3f(0.0F, 1.0F, 0.0F), + yaw, + pitch, + null, villager ); } @@ -114,11 +165,11 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { List trades = VillagerTrades.getTradesForVillager(this.villagerName); int tableStartX = windowX + 50; - int tableStartY = windowY + 110; + int tableStartY = windowY + 20; int levelWidth = 60; int itemSlotSize = 18; int itemSpacing = 4; - int rowHeight = itemSlotSize + 6; + int rowHeight = itemSlotSize + 5; int start = tradeScrollOffset; int end = Math.min(trades.size(), start + TRADES_VISIBLE); @@ -130,7 +181,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { if (!trade.level().equals(lastLevel)) { - context.drawText(this.textRenderer, Text.of(trade.level()), tableStartX - 5, y + 4, 0xFFFFFFFF, false); + context.text(this.font, Component.nullToEmpty(trade.level()), tableStartX - 5, y + 4, 0xFFFFFFFF, false); lastLevel = trade.level(); } @@ -140,24 +191,24 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { ItemStack stack = trade.wanted().get(i); context.fill(slotX, y, slotX + itemSlotSize, y + itemSlotSize, 0xFF444444); - context.drawStrokedRectangle(slotX, y, itemSlotSize, itemSlotSize, 0xFF000000); - context.drawItem(stack, slotX + 1, y + 1); + context.outline(slotX, y, itemSlotSize, itemSlotSize, 0xFF000000); + context.item(stack, slotX + 1, y + 1); if (stack.getCount() > 1) { - context.drawText(this.textRenderer, - Text.of(Integer.toString(stack.getCount())), + context.text(this.font, + Component.nullToEmpty(Integer.toString(stack.getCount())), slotX + 2, y + itemSlotSize - 8, 0xFFFFFFFF, true); } if (mouseX >= slotX && mouseX < slotX + itemSlotSize && mouseY >= y && mouseY < y + itemSlotSize) { - context.drawItemTooltip(this.textRenderer, stack, slotX, y); + context.setTooltipForNextFrame(this.font, stack, slotX, y); } } int arrowX = tableStartX + levelWidth + trade.wanted().size() * (itemSlotSize + itemSpacing) + 2; - context.drawText(this.textRenderer, Text.of("→"), arrowX, y + 5, 0xFFFFFFFF, false); + context.text(this.font, Component.nullToEmpty("→"), arrowX, y + 5, 0xFFFFFFFF, false); for (int i = 0; i < trade.given().size(); i++) { @@ -165,17 +216,17 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { ItemStack stack = trade.given().get(i); context.fill(slotX, y, slotX + itemSlotSize, y + itemSlotSize, 0xFF444444); - context.drawStrokedRectangle(slotX, y, itemSlotSize, itemSlotSize, 0xFF000000); - context.drawItem(stack, slotX + 1, y + 1); + context.outline(slotX, y, itemSlotSize, itemSlotSize, 0xFF000000); + context.item(stack, slotX + 1, y + 1); if (stack.getCount() > 1) { - context.drawText(this.textRenderer, - Text.of(Integer.toString(stack.getCount())), + context.text(this.font, + Component.nullToEmpty(Integer.toString(stack.getCount())), slotX + 2, y + itemSlotSize - 8, 0xFFFFFFFF, true); } if (mouseX >= slotX && mouseX < slotX + itemSlotSize && mouseY >= y && mouseY < y + itemSlotSize) { - context.drawItemTooltip(this.textRenderer, stack, slotX, y); + context.setTooltipForNextFrame(this.font, stack, slotX, y); } } } @@ -200,7 +251,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { int slotX = gridX + c * gridSize; int slotY = gridY + r * gridSize; context.fill(slotX, slotY, slotX + gridSize, slotY + gridSize, 0xFF444444); - context.drawStrokedRectangle(slotX, slotY, gridSize, gridSize, 0xFF000000); + context.outline(slotX, slotY, gridSize, gridSize, 0xFF000000); } } @@ -208,16 +259,16 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { for (GridItem gridItem : gridItems) { int slotX = gridX + gridItem.col * gridSize; int slotY = gridY + gridItem.row * gridSize; - context.drawItem(gridItem.stack, slotX + 1, slotY + 1); + context.item(gridItem.stack, slotX + 1, slotY + 1); if (mouseX >= slotX && mouseX < slotX + gridSize && mouseY >= slotY && mouseY < slotY + gridSize) { - context.drawItemTooltip(this.textRenderer, gridItem.stack, slotX, slotY); + context.setTooltipForNextFrame(this.font, gridItem.stack, slotX, slotY); } } int arrowX = gridX + gridSize * 4; int arrowY = gridY + gridSize; - context.drawText(this.textRenderer, Text.of("→"), arrowX - 10, arrowY + 5, 0xFFFFFFFF, false); + context.text(this.font, Component.nullToEmpty("→"), arrowX - 10, arrowY + 5, 0xFFFFFFFF, false); ItemStack resultStack = switch (villagerName.toLowerCase()) { @@ -240,14 +291,18 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { if (!resultStack.isEmpty()) { int resultX = gridX + gridSize * 4 + 5; int resultY = gridY + gridSize; - context.drawItem(resultStack, resultX, resultY); + context.item(resultStack, resultX, resultY); if (mouseX >= resultX && mouseX < resultX + gridSize && mouseY >= resultY && mouseY < resultY + gridSize) { - context.drawItemTooltip(this.textRenderer, resultStack, resultX, resultY); + context.setTooltipForNextFrame(this.font, resultStack, resultX, resultY); } } - super.render(context, mouseX, mouseY, delta); + super.extractRenderState(context, mouseX, mouseY, delta); + } + @Override + public void onClose() { + Minecraft.getInstance().gui.setScreen(new VillagerExplorerScreen()); } private List getJobBlockRecipe(String profession) { diff --git a/src/main/java/com/samxel/villagerexplorer/VillagerTrades.java b/src/main/java/com/samxel/villagerexplorer/VillagerTrades.java index 37317a9..26909c6 100644 --- a/src/main/java/com/samxel/villagerexplorer/VillagerTrades.java +++ b/src/main/java/com/samxel/villagerexplorer/VillagerTrades.java @@ -1,24 +1,142 @@ package com.samxel.villagerexplorer; -import net.minecraft.component.ComponentType; -import net.minecraft.component.DataComponentTypes; -import net.minecraft.component.type.ItemEnchantmentsComponent; -import net.minecraft.component.type.TooltipDisplayComponent; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.enchantment.Enchantments; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.registry.RegistryKey; -import net.minecraft.registry.RegistryKeys; -import net.minecraft.registry.RegistryWrapper; -import net.minecraft.registry.entry.RegistryEntry; - import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.SequencedSet; +import net.minecraft.core.Holder; +import net.minecraft.core.HolderLookup; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.core.component.DataComponents; +import net.minecraft.core.registries.Registries; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.item.DyeColor; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.component.ItemLore; +import net.minecraft.world.item.component.TooltipDisplay; +import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraft.world.item.enchantment.Enchantments; +import net.minecraft.world.item.enchantment.ItemEnchantments; public class VillagerTrades { + private static ItemStack namedTerracotta() { + ItemStack stack = new ItemStack(Items.GLAZED_TERRACOTTA.pick(DyeColor.WHITE)); + stack.set(DataComponents.CUSTOM_NAME, Component.literal("Any Color Glazed Terracota")); + return stack; + } + private static ItemStack namedTerracottar() { + ItemStack stack = new ItemStack(Items.TERRACOTTA); + stack.set(DataComponents.CUSTOM_NAME, Component.literal("Any Color Terracota")); + return stack; + } + private static ItemStack Emeraldcount() { + ItemStack stack = new ItemStack(Items.EMERALD, 88); + stack.set(DataComponents.CUSTOM_NAME, Component.literal("Price Is Dependend on what variant of the item it is")); + return stack; + } + private static ItemStack Stef() { + ItemStack stack = new ItemStack(Items.SUSPICIOUS_STEW); + stack.set(DataComponents.CUSTOM_NAME, Component.literal("Can give Blindness (00:06), Jump Boost (00:08), Night Vision (00:05), Poison (00:14), Saturation (00:00.350), or Weakness (00:07)")); + return stack; + } + private static ItemStack exp() { + ItemStack stack = new ItemStack(Items.FILLED_MAP); + stack.set(DataComponents.CUSTOM_NAME, Component.literal("Explorer Map")); + stack.set( + DataComponents.LORE, + new ItemLore(List.of( + Component.literal("Villager Type - Structures"), + Component.literal("Desert - Savanna Village, Plains Village, Jungle Temple"), + Component.literal("Jungle - Savanna Village, Desert Village, Swamp Hut"), + Component.literal("Plains - Savanna Village, Taiga Village"), + Component.literal("Savanna - Desert Village, Plains Village, Jungle Temple"), + Component.literal("Snowy - Plains Village, Taiga Village, Swamp Hut"), + Component.literal("Taiga - Plains Village, Snowy Village, Swamp Hut"), + Component.literal("Swamp - Snowy Village, Taiga Village, Jungle Temple") + ))); + return stack; + } + private static ItemStack oexp() { + ItemStack stack = new ItemStack(Items.FILLED_MAP); + stack.set(DataComponents.CUSTOM_NAME, Component.literal("Ocean Explorer Map")); + return stack; + } + private static ItemStack texp() { + ItemStack stack = new ItemStack(Items.FILLED_MAP); + stack.set(DataComponents.CUSTOM_NAME, Component.literal("Trial Explorer Map")); + return stack; + } + private static ItemStack mexp() { + ItemStack stack = new ItemStack(Items.FILLED_MAP); + stack.set(DataComponents.CUSTOM_NAME, Component.literal("Woodland Explorer Map")); + return stack; + } + private static ItemStack bann() { + ItemStack stack = new ItemStack(Items.BANNER.pick(DyeColor.WHITE)); + stack.set(DataComponents.CUSTOM_NAME, Component.literal("Any Color Banner")); + return stack; + } + private static ItemStack ban() { + ItemStack stack = new ItemStack(Items.BANNER.pick(DyeColor.WHITE)); + stack.set(DataComponents.CUSTOM_NAME, Component.literal("Any Color Banner")); + stack.set( + DataComponents.LORE, + new ItemLore(List.of( + Component.literal("Villager Type - Banner Color"), + Component.literal("Desert - Cyan, Gray, Green, Lime, Orange"), + Component.literal("Jungle - Brown, Green, Yellow"), + Component.literal("Plains - Brown, Pink, White, Yellow"), + Component.literal("Savanna - Green, Magenta, Orange, Red"), + Component.literal("Snowy - Blue, Cyan, Light Blue, Red, White"), + Component.literal("Taiga - Blue, Lime, Pink, Purple"), + Component.literal("Swamp - Black, Light Blue, Purple") + ))); + + return stack; + } + private static ItemStack boak() { + ItemStack stack = new ItemStack(Items.OAK_BOAT); + stack.set( + DataComponents.CUSTOM_NAME, + Component.literal("Boat wood depends on Villager Biome") + ); + + stack.set( + DataComponents.LORE, + new ItemLore(List.of( + Component.literal("Villager Type - Wood Type"), + Component.literal("Desert, Jungle - Jungle Wood"), + Component.literal("Plains - Oak Wood"), + Component.literal("Savanna - Acacia Wood"), + Component.literal("Snowy, Taiga - Spruce Wood"), + Component.literal("Swamp - Dark Oak Wood") + )) + ); + + return stack; + } + private static ItemStack Arrowt() { + ItemStack stack = new ItemStack(Items.TIPPED_ARROW); + stack.set(DataComponents.CUSTOM_NAME, Component.literal("Any Craftable Tipped Arrow")); + return stack; + } + private static ItemStack wool() { + ItemStack stack = new ItemStack(Items.WOOL.pick(DyeColor.WHITE)); + stack.set(DataComponents.CUSTOM_NAME, Component.literal("Any Color Wool")); + return stack; + } + private static ItemStack carpet() { + ItemStack stack = new ItemStack(Items.CARPET.pick(DyeColor.WHITE), 4); + stack.set(DataComponents.CUSTOM_NAME, Component.literal("Any Color Carpet")); + return stack; + } + private static ItemStack bed() { + ItemStack stack = new ItemStack(Items.BED.pick(DyeColor.WHITE)); + stack.set(DataComponents.CUSTOM_NAME, Component.literal("Any Color Bed")); + return stack; + } public static final Map> TRADES = Map.ofEntries( @@ -97,7 +215,7 @@ public class VillagerTrades { ), new Trade( "Expert", - List.of(new ItemStack(Items.EMERALD, 19)), + List.of(Emeraldcount()), List.of( markGlint( new ItemStack( @@ -108,7 +226,7 @@ public class VillagerTrades { ), new Trade( "Expert", - List.of(new ItemStack(Items.EMERALD, 13)), + List.of(Emeraldcount()), List.of( markGlint( new ItemStack( @@ -119,7 +237,7 @@ public class VillagerTrades { ), new Trade( "Master", - List.of(new ItemStack(Items.EMERALD, 13)), + List.of(Emeraldcount()), List.of( markGlint( new ItemStack( @@ -130,7 +248,7 @@ public class VillagerTrades { ), new Trade( "Master", - List.of(new ItemStack(Items.EMERALD, 21)), + List.of(Emeraldcount()), List.of( markGlint( new ItemStack( @@ -235,7 +353,15 @@ public class VillagerTrades { new ItemStack(Items.EMERALD, 8), new ItemStack(Items.COMPASS) ), - List.of(new ItemStack(Items.FILLED_MAP)) + List.of(exp()) + ), + new Trade( + "Apprentice", + List.of( + new ItemStack(Items.EMERALD, 8), + new ItemStack(Items.COMPASS) + ), + List.of(exp()) ), new Trade( "Journeyman", @@ -248,7 +374,7 @@ public class VillagerTrades { new ItemStack(Items.EMERALD, 13), new ItemStack(Items.COMPASS) ), - List.of(new ItemStack(Items.FILLED_MAP)) + List.of(oexp()) ), new Trade( "Journeyman", @@ -256,7 +382,7 @@ public class VillagerTrades { new ItemStack(Items.EMERALD, 12), new ItemStack(Items.COMPASS) ), - List.of(new ItemStack(Items.FILLED_MAP)) + List.of(texp()) ), new Trade( "Expert", @@ -266,7 +392,12 @@ public class VillagerTrades { new Trade( "Expert", List.of(new ItemStack(Items.EMERALD, 3)), - List.of(new ItemStack(Items.WHITE_BANNER)) + List.of(ban()) + ), + new Trade( + "Expert", + List.of(new ItemStack(Items.EMERALD, 3)), + List.of(ban()) ), new Trade( "Master", @@ -283,7 +414,7 @@ public class VillagerTrades { new ItemStack(Items.EMERALD, 14), new ItemStack(Items.COMPASS) ), - List.of(new ItemStack(Items.FILLED_MAP)) + List.of(mexp()) ) ) ), @@ -407,32 +538,7 @@ public class VillagerTrades { new Trade( "Expert", List.of(new ItemStack(Items.EMERALD)), - List.of(new ItemStack(Items.SUSPICIOUS_STEW)) - ), - new Trade( - "Expert", - List.of(new ItemStack(Items.EMERALD)), - List.of(new ItemStack(Items.SUSPICIOUS_STEW)) - ), - new Trade( - "Expert", - List.of(new ItemStack(Items.EMERALD)), - List.of(new ItemStack(Items.SUSPICIOUS_STEW)) - ), - new Trade( - "Expert", - List.of(new ItemStack(Items.EMERALD)), - List.of(new ItemStack(Items.SUSPICIOUS_STEW)) - ), - new Trade( - "Expert", - List.of(new ItemStack(Items.EMERALD)), - List.of(new ItemStack(Items.SUSPICIOUS_STEW)) - ), - new Trade( - "Expert", - List.of(new ItemStack(Items.EMERALD)), - List.of(new ItemStack(Items.SUSPICIOUS_STEW)) + List.of(Stef()) ), new Trade( "Expert", @@ -511,7 +617,7 @@ public class VillagerTrades { ), new Trade( "Journeyman", - List.of(new ItemStack(Items.EMERALD, 8)), + List.of(Emeraldcount()), List.of( markGlint( new ItemStack( @@ -532,7 +638,7 @@ public class VillagerTrades { ), new Trade( "Master", - List.of(new ItemStack(Items.OAK_BOAT)), + List.of(boak()), List.of(new ItemStack(Items.EMERALD)) ) ) @@ -587,7 +693,7 @@ public class VillagerTrades { ), new Trade( "Expert", - List.of(new ItemStack(Items.EMERALD, 7)), + List.of(Emeraldcount()), List.of( markGlint( new ItemStack(Items.BOW) @@ -601,7 +707,7 @@ public class VillagerTrades { ), new Trade( "Master", - List.of(new ItemStack(Items.EMERALD, 8)), + List.of(Emeraldcount()), List.of( markGlint( new ItemStack(Items.CROSSBOW) @@ -614,9 +720,7 @@ public class VillagerTrades { new ItemStack(Items.EMERALD, 2), new ItemStack(Items.ARROW, 5) ), - List.of( - new ItemStack(Items.TIPPED_ARROW, 5) - ) + List.of(Arrowt()) ) ) ), @@ -705,7 +809,7 @@ public class VillagerTrades { new Trade( "Novice", List.of( - new ItemStack(Items.EMERALD, 5), + Emeraldcount(), new ItemStack(Items.BOOK) ), List.of(new ItemStack(Items.ENCHANTED_BOOK)) @@ -723,7 +827,7 @@ public class VillagerTrades { new Trade( "Apprentice", List.of( - new ItemStack(Items.EMERALD, 5), + Emeraldcount(), new ItemStack(Items.BOOK) ), List.of(new ItemStack(Items.ENCHANTED_BOOK)) @@ -741,14 +845,14 @@ public class VillagerTrades { new Trade( "Journeyman", List.of( - new ItemStack(Items.EMERALD, 5), + Emeraldcount(), new ItemStack(Items.BOOK) ), List.of(new ItemStack(Items.ENCHANTED_BOOK)) ), new Trade( "Expert", - List.of(new ItemStack(Items.WRITABLE_BOOK, 2)), + List.of(new ItemStack(Items.WRITABLE_BOOK, 1)), List.of(new ItemStack(Items.EMERALD)) ), new Trade( @@ -764,15 +868,20 @@ public class VillagerTrades { new Trade( "Expert", List.of( - new ItemStack(Items.EMERALD, 5), + Emeraldcount(), new ItemStack(Items.BOOK) ), List.of(new ItemStack(Items.ENCHANTED_BOOK)) ), new Trade( "Master", - List.of(new ItemStack(Items.EMERALD, 20)), - List.of(new ItemStack(Items.NAME_TAG)) + List.of(new ItemStack(Items.EMERALD, 3)), + List.of(new ItemStack(Items.DYED_CANDLE.pick(DyeColor.RED))) + ), + new Trade( + "Master", + List.of(new ItemStack(Items.EMERALD, 3)), + List.of(new ItemStack(Items.DYED_CANDLE.pick(DyeColor.YELLOW))) ) ) ), @@ -846,14 +955,12 @@ public class VillagerTrades { new Trade( "Expert", List.of(new ItemStack(Items.EMERALD)), - List.of(new ItemStack(Items.WHITE_TERRACOTTA)) + List.of(namedTerracottar()) ), new Trade( "Expert", List.of(new ItemStack(Items.EMERALD)), - List.of( - new ItemStack(Items.WHITE_GLAZED_TERRACOTTA) - ) + List.of(namedTerracotta()) ), new Trade( "Master", @@ -874,22 +981,22 @@ public class VillagerTrades { List.of( new Trade( "Novice", - List.of(new ItemStack(Items.WHITE_WOOL, 18)), + List.of(new ItemStack(Items.WOOL.pick(DyeColor.WHITE), 18)), List.of(new ItemStack(Items.EMERALD)) ), new Trade( "Novice", - List.of(new ItemStack(Items.BROWN_WOOL, 18)), + List.of(new ItemStack(Items.WOOL.pick(DyeColor.BROWN), 18)), List.of(new ItemStack(Items.EMERALD)) ), new Trade( "Novice", - List.of(new ItemStack(Items.BLACK_WOOL, 18)), + List.of(new ItemStack(Items.WOOL.pick(DyeColor.BLACK), 18)), List.of(new ItemStack(Items.EMERALD)) ), new Trade( "Novice", - List.of(new ItemStack(Items.GRAY_WOOL, 18)), + List.of(new ItemStack(Items.WOOL.pick(DyeColor.GRAY), 18)), List.of(new ItemStack(Items.EMERALD)) ), new Trade( @@ -899,103 +1006,103 @@ public class VillagerTrades { ), new Trade( "Apprentice", - List.of(new ItemStack(Items.WHITE_DYE, 12)), + List.of(new ItemStack(Items.DYE.pick(DyeColor.WHITE), 12)), List.of(new ItemStack(Items.EMERALD)) ), new Trade( "Apprentice", - List.of(new ItemStack(Items.GRAY_DYE, 12)), + List.of(new ItemStack(Items.DYE.pick(DyeColor.GRAY), 12)), List.of(new ItemStack(Items.EMERALD)) ), new Trade( "Apprentice", - List.of(new ItemStack(Items.BLACK_DYE, 12)), + List.of(new ItemStack(Items.DYE.pick(DyeColor.BLACK), 12)), List.of(new ItemStack(Items.EMERALD)) ), new Trade( "Apprentice", - List.of(new ItemStack(Items.LIGHT_BLUE_DYE, 12)), + List.of(new ItemStack(Items.DYE.pick(DyeColor.LIGHT_BLUE), 12)), List.of(new ItemStack(Items.EMERALD)) ), new Trade( "Apprentice", - List.of(new ItemStack(Items.LIME_DYE, 12)), + List.of(new ItemStack(Items.DYE.pick(DyeColor.LIME), 12)), List.of(new ItemStack(Items.EMERALD)) ), new Trade( "Apprentice", List.of(new ItemStack(Items.EMERALD)), - List.of(new ItemStack(Items.WHITE_WOOL)) + List.of(wool()) ), new Trade( "Apprentice", List.of(new ItemStack(Items.EMERALD)), - List.of(new ItemStack(Items.WHITE_CARPET, 4)) + List.of(carpet()) ), new Trade( "Journeyman", - List.of(new ItemStack(Items.YELLOW_DYE, 12)), + List.of(new ItemStack(Items.DYE.pick(DyeColor.YELLOW), 12)), List.of(new ItemStack(Items.EMERALD)) ), new Trade( "Journeyman", - List.of(new ItemStack(Items.LIGHT_GRAY_DYE, 12)), + List.of(new ItemStack(Items.DYE.pick(DyeColor.LIGHT_GRAY), 12)), List.of(new ItemStack(Items.EMERALD)) ), new Trade( "Journeyman", - List.of(new ItemStack(Items.ORANGE_DYE, 12)), + List.of(new ItemStack(Items.DYE.pick(DyeColor.ORANGE), 12)), List.of(new ItemStack(Items.EMERALD)) ), new Trade( "Journeyman", - List.of(new ItemStack(Items.RED_DYE, 12)), + List.of(new ItemStack(Items.DYE.pick(DyeColor.RED), 12)), List.of(new ItemStack(Items.EMERALD)) ), new Trade( "Journeyman", - List.of(new ItemStack(Items.PINK_DYE, 12)), + List.of(new ItemStack(Items.DYE.pick(DyeColor.PINK), 12)), List.of(new ItemStack(Items.EMERALD)) ), new Trade( "Journeyman", List.of(new ItemStack(Items.EMERALD, 3)), - List.of(new ItemStack(Items.WHITE_BED)) + List.of(bed()) ), new Trade( "Expert", - List.of(new ItemStack(Items.BROWN_DYE, 12)), + List.of(new ItemStack(Items.DYE.pick(DyeColor.BROWN), 12)), List.of(new ItemStack(Items.EMERALD)) ), new Trade( "Expert", - List.of(new ItemStack(Items.PURPLE_DYE, 12)), + List.of(new ItemStack(Items.DYE.pick(DyeColor.PURPLE), 12)), List.of(new ItemStack(Items.EMERALD)) ), new Trade( "Expert", - List.of(new ItemStack(Items.BLUE_DYE, 12)), + List.of(new ItemStack(Items.DYE.pick(DyeColor.BLUE), 12)), List.of(new ItemStack(Items.EMERALD)) ), new Trade( "Expert", - List.of(new ItemStack(Items.GREEN_DYE, 12)), + List.of(new ItemStack(Items.DYE.pick(DyeColor.GREEN), 12)), List.of(new ItemStack(Items.EMERALD)) ), new Trade( "Expert", - List.of(new ItemStack(Items.MAGENTA_DYE, 12)), + List.of(new ItemStack(Items.DYE.pick(DyeColor.GREEN), 12)), List.of(new ItemStack(Items.EMERALD)) ), new Trade( "Expert", - List.of(new ItemStack(Items.CYAN_DYE, 12)), + List.of(new ItemStack(Items.DYE.pick(DyeColor.CYAN), 12)), List.of(new ItemStack(Items.EMERALD)) ), new Trade( "Expert", List.of(new ItemStack(Items.EMERALD, 3)), - List.of(new ItemStack(Items.WHITE_BANNER)) + List.of(bann()) ), new Trade( "Master", @@ -1051,7 +1158,7 @@ public class VillagerTrades { ), new Trade( "Journeyman", - List.of(new ItemStack(Items.EMERALD, 6)), + List.of(Emeraldcount()), List.of( markGlint( new ItemStack(Items.IRON_AXE) @@ -1060,7 +1167,7 @@ public class VillagerTrades { ), new Trade( "Journeyman", - List.of(new ItemStack(Items.EMERALD, 7)), + List.of(Emeraldcount()), List.of( markGlint( new ItemStack(Items.IRON_SHOVEL) @@ -1069,7 +1176,7 @@ public class VillagerTrades { ), new Trade( "Journeyman", - List.of(new ItemStack(Items.EMERALD, 8)), + List.of(Emeraldcount()), List.of( markGlint( new ItemStack(Items.IRON_PICKAXE) @@ -1088,7 +1195,7 @@ public class VillagerTrades { ), new Trade( "Expert", - List.of(new ItemStack(Items.EMERALD, 17)), + List.of(Emeraldcount()), List.of( markGlint( new ItemStack(Items.DIAMOND_AXE) @@ -1097,7 +1204,7 @@ public class VillagerTrades { ), new Trade( "Expert", - List.of(new ItemStack(Items.EMERALD, 10)), + List.of(Emeraldcount()), List.of( markGlint( new ItemStack( @@ -1108,7 +1215,7 @@ public class VillagerTrades { ), new Trade( "Master", - List.of(new ItemStack(Items.EMERALD, 18)), + List.of(Emeraldcount()), List.of( markGlint( new ItemStack( @@ -1136,7 +1243,7 @@ public class VillagerTrades { ), new Trade( "Novice", - List.of(new ItemStack(Items.EMERALD, 7)), + List.of(Emeraldcount()), List.of( markGlint( new ItemStack(Items.IRON_SWORD) @@ -1165,7 +1272,7 @@ public class VillagerTrades { ), new Trade( "Expert", - List.of(new ItemStack(Items.EMERALD, 17)), + List.of(Emeraldcount()), List.of( markGlint( new ItemStack(Items.DIAMOND_AXE) @@ -1174,7 +1281,7 @@ public class VillagerTrades { ), new Trade( "Master", - List.of(new ItemStack(Items.EMERALD, 13)), + List.of(Emeraldcount()), List.of( markGlint( new ItemStack(Items.DIAMOND_SWORD) @@ -1186,7 +1293,7 @@ public class VillagerTrades { ); public static ItemStack markGlint(ItemStack stack) { - stack.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, true); + stack.set(DataComponents.ENCHANTMENT_GLINT_OVERRIDE, true); return stack; } @@ -1196,30 +1303,30 @@ public static List getTradesForVillager(String villagerName) { public static ItemStack markGlint( ItemStack stack, - RegistryWrapper.WrapperLookup registries + HolderLookup.Provider registries ) { - ItemEnchantmentsComponent existing = stack.get(DataComponentTypes.ENCHANTMENTS); - ItemEnchantmentsComponent.Builder builder = - new ItemEnchantmentsComponent.Builder( - existing != null ? existing : ItemEnchantmentsComponent.DEFAULT + ItemEnchantments existing = stack.get(DataComponents.ENCHANTMENTS); + ItemEnchantments.Mutable builder = + new ItemEnchantments.Mutable( + existing != null ? existing : ItemEnchantments.EMPTY ); - RegistryKey key = Enchantments.UNBREAKING; - RegistryEntry unbreakingEntry = - registries.getOrThrow(RegistryKeys.ENCHANTMENT) - .getOptional(key) + ResourceKey key = Enchantments.UNBREAKING; + Holder unbreakingEntry = + registries.lookupOrThrow(Registries.ENCHANTMENT) + .get(key) .orElseThrow(); builder.set(unbreakingEntry, 1); - stack.set(DataComponentTypes.ENCHANTMENTS, builder.build()); + stack.set(DataComponents.ENCHANTMENTS, builder.toImmutable()); - SequencedSet> hidden = new LinkedHashSet<>(); - hidden.add(DataComponentTypes.ENCHANTMENTS); + SequencedSet> hidden = new LinkedHashSet<>(); + hidden.add(DataComponents.ENCHANTMENTS); - TooltipDisplayComponent display = new TooltipDisplayComponent(false, hidden); - stack.set(DataComponentTypes.TOOLTIP_DISPLAY, display); + TooltipDisplay display = new TooltipDisplay(false, hidden); + stack.set(DataComponents.TOOLTIP_DISPLAY, display); return stack; } diff --git a/src/main/java/com/samxel/villagerexplorer/VillagerUtils.java b/src/main/java/com/samxel/villagerexplorer/VillagerUtils.java index 403fc15..26db2f9 100644 --- a/src/main/java/com/samxel/villagerexplorer/VillagerUtils.java +++ b/src/main/java/com/samxel/villagerexplorer/VillagerUtils.java @@ -1,13 +1,13 @@ package com.samxel.villagerexplorer; -import net.minecraft.registry.Registries; -import net.minecraft.util.Identifier; -import net.minecraft.village.VillagerProfession; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.Identifier; +import net.minecraft.world.entity.npc.villager.VillagerProfession; public class VillagerUtils { public static VillagerProfession getProfessionByName(String name) { - Identifier id = Identifier.of("minecraft", name.toLowerCase()); - return Registries.VILLAGER_PROFESSION.get(id); + Identifier id = Identifier.fromNamespaceAndPath("minecraft", name.toLowerCase()); + return BuiltInRegistries.VILLAGER_PROFESSION.getValue(id); } } diff --git a/src/main/java/com/samxel/villagerexplorer/client/VillagerExplorerClient.java b/src/main/java/com/samxel/villagerexplorer/client/VillagerExplorerClient.java index d778442..ee4134b 100644 --- a/src/main/java/com/samxel/villagerexplorer/client/VillagerExplorerClient.java +++ b/src/main/java/com/samxel/villagerexplorer/client/VillagerExplorerClient.java @@ -1,29 +1,29 @@ package com.samxel.villagerexplorer.client; +import com.mojang.blaze3d.platform.InputConstants; import com.samxel.villagerexplorer.VillagerExplorerScreen; import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; -import net.minecraft.client.option.KeyBinding; -import net.minecraft.client.util.InputUtil; -import net.minecraft.util.Identifier; +import net.fabricmc.fabric.api.client.keymapping.v1.KeyMappingHelper; +import net.minecraft.client.KeyMapping; +import net.minecraft.resources.Identifier; import org.lwjgl.glfw.GLFW; public class VillagerExplorerClient implements ClientModInitializer { - public static KeyBinding openGuiKeybind; + public static KeyMapping openGuiKeybind; @Override public void onInitializeClient() { - openGuiKeybind = KeyBindingHelper.registerKeyBinding(new KeyBinding( + openGuiKeybind = KeyMappingHelper.registerKeyMapping(new KeyMapping( "key.villagerexplorer.opengui", - InputUtil.Type.KEYSYM, + InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_V, - KeyBinding.Category.create(Identifier.of("villagerexplorer", "villagerexplorer")) + KeyMapping.Category.register(Identifier.fromNamespaceAndPath("villagerexplorer", "villagerexplorer")) )); net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents.END_CLIENT_TICK.register(client -> { - while (openGuiKeybind.wasPressed()) { - client.setScreen(new VillagerExplorerScreen()); + while (openGuiKeybind.consumeClick()) { + client.gui.setScreen(new VillagerExplorerScreen()); } }); } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 41c3940..9df39db 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -19,7 +19,6 @@ }, "depends": { "fabricloader": ">=${loader_version}", - "fabric": "*", "minecraft": "${minecraft_version}" } }