diff --git a/build.gradle.kts b/build.gradle.kts index c997608..a484da2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,3 @@ plugins { - id("roundalib") version "0.1.3" + id("roundalib") version "0.3.6" } diff --git a/gradle.properties b/gradle.properties index 65881f8..22c56c8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,9 +5,9 @@ org.gradle.parallel=true # RoundaLib Properties group_id=me.roundaround mod_id=armorstands -mod_version=1.0.2 -minecraft_version=1.19.4 -yarn_mappings=build.1 -loader_version=0.14.19 -fabric_version=0.76.0 -mod_menu_version=6.1.0-rc.4 +mod_version=1.1.0 +minecraft_version=1.20-pre6 +yarn_mappings=build.2 +loader_version=0.14.21 +fabric_version=0.82.1+1.20 +mod_menu_version=7.0.0-beta.2 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7454180..c1962a7 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 84d1f85..37aef8d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c787..aeb74cb 100755 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +80,10 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# 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"' +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -143,12 +140,16 @@ fi 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=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=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,6 +194,10 @@ if "$cygwin" || "$msys" ; then 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 $GRADLE_OPTS can contain fragments of # shell script including quotes and variable substitutions, so put them in @@ -205,6 +210,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# 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. diff --git a/gradlew.bat b/gradlew.bat index ac1b06f..6689b85 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/src/main/java/me/roundaround/armorstands/client/gui/MessageRenderer.java b/src/main/java/me/roundaround/armorstands/client/gui/MessageRenderer.java index 1ff6d55..adc8ce2 100644 --- a/src/main/java/me/roundaround/armorstands/client/gui/MessageRenderer.java +++ b/src/main/java/me/roundaround/armorstands/client/gui/MessageRenderer.java @@ -4,7 +4,7 @@ import me.roundaround.armorstands.client.gui.widget.NavigationButtonWidget; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.DrawableHelper; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; @@ -44,13 +44,13 @@ public void tick() { } } - public void render(MatrixStack matrixStack) { + public void render(DrawContext drawContext) { shownMessage.ifPresent((message) -> { - message.render(screen, matrixStack); + message.render(screen, drawContext); }); } - private static class Message extends DrawableHelper { + private static class Message { private static final int SHOW_DURATION = 40; private final Text text; @@ -72,7 +72,7 @@ public void tick() { timeRemaining--; } - public void render(Screen screen, MatrixStack matrixStack) { + public void render(Screen screen, DrawContext context) { MinecraftClient client = MinecraftClient.getInstance(); TextRenderer textRenderer = client.textRenderer; int width = textRenderer.getWidth(text); @@ -87,8 +87,8 @@ public void render(Screen screen, MatrixStack matrixStack) { RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); - fill(matrixStack, x - 2, y - 2, x + width + 2, y + textRenderer.fontHeight + 2, backgroundColor); - textRenderer.drawWithShadow(matrixStack, text, x, y, textColor); + context.fill(x - 2, y - 2, x + width + 2, y + textRenderer.fontHeight + 2, backgroundColor); + context.drawTextWithShadow(textRenderer, text, x, y, textColor); RenderSystem.disableBlend(); } diff --git a/src/main/java/me/roundaround/armorstands/client/gui/screen/AbstractArmorStandScreen.java b/src/main/java/me/roundaround/armorstands/client/gui/screen/AbstractArmorStandScreen.java index 20d1d81..f9f98f8 100644 --- a/src/main/java/me/roundaround/armorstands/client/gui/screen/AbstractArmorStandScreen.java +++ b/src/main/java/me/roundaround/armorstands/client/gui/screen/AbstractArmorStandScreen.java @@ -20,11 +20,10 @@ import me.roundaround.armorstands.network.packet.c2s.UtilityActionPacket; import me.roundaround.armorstands.screen.ArmorStandScreenHandler; import me.roundaround.armorstands.util.HasArmorStand; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.Element; -import net.minecraft.client.gui.navigation.GuiNavigation; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.ingame.HandledScreen; -import net.minecraft.client.render.GameRenderer; import net.minecraft.client.sound.PositionedSoundInstance; import net.minecraft.client.util.InputUtil; import net.minecraft.client.util.math.MatrixStack; @@ -67,6 +66,7 @@ protected AbstractArmorStandScreen(ArmorStandScreenHandler handler, Text title) this.messageRenderer = new MessageRenderer(this); + // TODO: Find an alternative to this this.passEvents = true; } @@ -119,32 +119,32 @@ protected void handledScreenTick() { } @Override - public void render(MatrixStack matrixStack, int mouseX, int mouseY, float delta) { + public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { int adjustedMouseX = cursorLocked ? -1 : mouseX; int adjustedMouseY = cursorLocked ? -1 : mouseY; RenderSystem.enableBlend(); - ((InGameHudAccessor) this.client.inGameHud).invokeRenderVignetteOverlay(matrixStack, + ((InGameHudAccessor) this.client.inGameHud).invokeRenderVignetteOverlay(drawContext, this.client.getCameraEntity()); // Render labels before all other widgets so they are rendered on bottom for (LabelWidget label : this.labels) { - label.render(matrixStack, adjustedMouseX, adjustedMouseY, delta); + label.render(drawContext, adjustedMouseX, adjustedMouseY, delta); } - super.render(matrixStack, adjustedMouseX, adjustedMouseY, delta); + super.render(drawContext, adjustedMouseX, adjustedMouseY, delta); - renderActivePageButtonHighlight(matrixStack); + renderActivePageButtonHighlight(drawContext); - this.messageRenderer.render(matrixStack); + this.messageRenderer.render(drawContext); } @Override - protected void drawBackground(MatrixStack matrixStack, float delta, int mouseX, int mouseY) { + protected void drawBackground(DrawContext drawContext, float delta, int mouseX, int mouseY) { } @Override - protected void drawForeground(MatrixStack matrices, int mouseX, int mouseY) { + protected void drawForeground(DrawContext drawContext, int mouseX, int mouseY) { } @Override @@ -442,20 +442,19 @@ protected void initRight() { protected void initEnd() { } - protected void renderActivePageButtonHighlight(MatrixStack matrixStack) { + protected void renderActivePageButtonHighlight(DrawContext drawContext) { if (this.activeButton == null) { return; } RenderSystem.setShaderColor(1f, 1f, 1f, 1f); - RenderSystem.setShader(GameRenderer::getPositionTexProgram); - RenderSystem.setShaderTexture(0, WIDGETS_TEXTURE); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); + MatrixStack matrixStack = drawContext.getMatrices(); matrixStack.push(); matrixStack.translate(0, 0, 100); - drawNineSlicedTexture(matrixStack, + drawContext.drawNineSlicedTexture(WIDGETS_TEXTURE, this.activeButton.getX() - 2, this.activeButton.getY() - 2, 25, diff --git a/src/main/java/me/roundaround/armorstands/client/gui/screen/ArmorStandInventoryScreen.java b/src/main/java/me/roundaround/armorstands/client/gui/screen/ArmorStandInventoryScreen.java index a427789..fb180e2 100644 --- a/src/main/java/me/roundaround/armorstands/client/gui/screen/ArmorStandInventoryScreen.java +++ b/src/main/java/me/roundaround/armorstands/client/gui/screen/ArmorStandInventoryScreen.java @@ -3,15 +3,13 @@ import com.google.common.collect.ImmutableList; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.datafixers.util.Pair; - import me.roundaround.armorstands.ArmorStandsMod; import me.roundaround.armorstands.client.gui.widget.FlagToggleWidget; import me.roundaround.armorstands.network.ArmorStandFlag; import me.roundaround.armorstands.network.ScreenType; import me.roundaround.armorstands.screen.ArmorStandScreenHandler; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.InventoryScreen; -import net.minecraft.client.render.GameRenderer; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.EquipmentSlot; import net.minecraft.screen.slot.Slot; import net.minecraft.util.Identifier; @@ -19,9 +17,8 @@ public class ArmorStandInventoryScreen extends AbstractArmorStandScreen { private static final int BACKGROUND_WIDTH = 176; private static final int BACKGROUND_HEIGHT = 166; - private static final Identifier CUSTOM_TEXTURE = new Identifier( - ArmorStandsMod.MOD_ID, - "textures/gui/container/inventory.png"); + private static final Identifier CUSTOM_TEXTURE = + new Identifier(ArmorStandsMod.MOD_ID, "textures/gui/container/inventory.png"); private float mouseX; private float mouseY; @@ -42,20 +39,16 @@ public ScreenType getScreenType() { @Override protected void initRight() { - this.showArmsToggle = addDrawableChild( - new FlagToggleWidget( - this.textRenderer, - ArmorStandFlag.SHOW_ARMS, - ArmorStandFlag.SHOW_ARMS.getValue(this.armorStand), - this.width - SCREEN_EDGE_PAD, - this.height - SCREEN_EDGE_PAD - 2 * FlagToggleWidget.WIDGET_HEIGHT - BETWEEN_PAD)); - this.lockInventoryToggle = addDrawableChild( - new FlagToggleWidget( - this.textRenderer, - ArmorStandFlag.LOCK_INVENTORY, - ArmorStandFlag.LOCK_INVENTORY.getValue(this.armorStand), - this.width - SCREEN_EDGE_PAD, - this.height - SCREEN_EDGE_PAD - FlagToggleWidget.WIDGET_HEIGHT)); + this.showArmsToggle = addDrawableChild(new FlagToggleWidget(this.textRenderer, + ArmorStandFlag.SHOW_ARMS, + ArmorStandFlag.SHOW_ARMS.getValue(this.armorStand), + this.width - SCREEN_EDGE_PAD, + this.height - SCREEN_EDGE_PAD - 2 * FlagToggleWidget.WIDGET_HEIGHT - BETWEEN_PAD)); + this.lockInventoryToggle = addDrawableChild(new FlagToggleWidget(this.textRenderer, + ArmorStandFlag.LOCK_INVENTORY, + ArmorStandFlag.LOCK_INVENTORY.getValue(this.armorStand), + this.width - SCREEN_EDGE_PAD, + this.height - SCREEN_EDGE_PAD - FlagToggleWidget.WIDGET_HEIGHT)); } @Override @@ -67,45 +60,35 @@ public void handledScreenTick() { } @Override - public void render(MatrixStack matrixStack, int mouseX, int mouseY, float delta) { - renderBackground(matrixStack); + public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { + renderBackground(drawContext); this.mouseX = mouseX; this.mouseY = mouseY; - super.render(matrixStack, mouseX, mouseY, delta); + super.render(drawContext, mouseX, mouseY, delta); - drawMouseoverTooltip(matrixStack, mouseX, mouseY); + drawMouseoverTooltip(drawContext, mouseX, mouseY); } @Override - protected void drawBackground(MatrixStack matrixStack, float delta, int mouseX, int mouseY) { - RenderSystem.setShader(GameRenderer::getPositionTexProgram); + protected void drawBackground(DrawContext drawContext, float delta, int mouseX, int mouseY) { RenderSystem.setShaderColor(1f, 1f, 1f, 1f); int x = (this.width - BACKGROUND_WIDTH) / 2; int y = (this.height - BACKGROUND_HEIGHT) / 2; - RenderSystem.setShaderTexture(0, CUSTOM_TEXTURE); - drawTexture( - matrixStack, - x, - y, - 0, - 0, - BACKGROUND_WIDTH, - BACKGROUND_HEIGHT); + drawContext.drawTexture(CUSTOM_TEXTURE, x, y, 0, 0, BACKGROUND_WIDTH, BACKGROUND_HEIGHT); ImmutableList> armorSlots = this.handler.getArmorSlots(); for (int index = 0; index < armorSlots.size(); index++) { Slot slot = armorSlots.get(index).getFirst(); EquipmentSlot equipmentSlot = armorSlots.get(index).getSecond(); if (ArmorStandScreenHandler.isSlotDisabled(armorStand, equipmentSlot)) { - fill(matrixStack, x + slot.x, y + slot.y, x + slot.x + 16, y + slot.y + 16, 0x80000000); + drawContext.fill(x + slot.x, y + slot.y, x + slot.x + 16, y + slot.y + 16, 0x80000000); } } - InventoryScreen.drawEntity( - matrixStack, + InventoryScreen.drawEntity(drawContext, x + 88, y + 75, 30, diff --git a/src/main/java/me/roundaround/armorstands/client/gui/screen/ArmorStandPoseScreen.java b/src/main/java/me/roundaround/armorstands/client/gui/screen/ArmorStandPoseScreen.java index b56c736..3347526 100644 --- a/src/main/java/me/roundaround/armorstands/client/gui/screen/ArmorStandPoseScreen.java +++ b/src/main/java/me/roundaround/armorstands/client/gui/screen/ArmorStandPoseScreen.java @@ -4,17 +4,16 @@ import me.roundaround.armorstands.client.gui.widget.AdjustPoseSliderWidget; import me.roundaround.armorstands.client.gui.widget.IconButtonWidget; import me.roundaround.armorstands.client.gui.widget.LabelWidget; -import me.roundaround.armorstands.client.gui.widget.NavigationButtonWidget; import me.roundaround.armorstands.network.EulerAngleParameter; import me.roundaround.armorstands.network.PosePart; import me.roundaround.armorstands.network.ScreenType; import me.roundaround.armorstands.network.packet.c2s.SetPosePacket; import me.roundaround.armorstands.screen.ArmorStandScreenHandler; import me.roundaround.armorstands.util.Pose; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.tooltip.Tooltip; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.CyclingButtonWidget; -import net.minecraft.client.render.GameRenderer; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.decoration.ArmorStandEntity; import net.minecraft.text.Text; @@ -261,22 +260,21 @@ protected void handledScreenTick() { } @Override - protected void renderActivePageButtonHighlight(MatrixStack matrixStack) { - super.renderActivePageButtonHighlight(matrixStack); + protected void renderActivePageButtonHighlight(DrawContext drawContext) { + super.renderActivePageButtonHighlight(drawContext); if (this.activePosePartButton == null) { return; } RenderSystem.setShaderColor(1f, 1f, 1f, 1f); - RenderSystem.setShader(GameRenderer::getPositionTexProgram); - RenderSystem.setShaderTexture(0, WIDGETS_TEXTURE); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); + MatrixStack matrixStack = drawContext.getMatrices(); matrixStack.push(); matrixStack.translate(0, 0, 100); - drawNineSlicedTexture(matrixStack, + drawContext.drawNineSlicedTexture(WIDGETS_TEXTURE, this.activePosePartButton.getX() - 2, this.activePosePartButton.getY() - 2, 25, diff --git a/src/main/java/me/roundaround/armorstands/client/gui/widget/FlagToggleWidget.java b/src/main/java/me/roundaround/armorstands/client/gui/widget/FlagToggleWidget.java index dfcbe6c..0052aad 100644 --- a/src/main/java/me/roundaround/armorstands/client/gui/widget/FlagToggleWidget.java +++ b/src/main/java/me/roundaround/armorstands/client/gui/widget/FlagToggleWidget.java @@ -1,14 +1,12 @@ package me.roundaround.armorstands.client.gui.widget; import com.mojang.blaze3d.systems.RenderSystem; - import me.roundaround.armorstands.network.ArmorStandFlag; import me.roundaround.armorstands.network.packet.c2s.SetFlagPacket; import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; import net.minecraft.client.gui.widget.PressableWidget; -import net.minecraft.client.render.GameRenderer; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; public class FlagToggleWidget extends PressableWidget { @@ -71,12 +69,12 @@ protected boolean clicked(double mouseX, double mouseY) { } @Override - public void renderButton(MatrixStack matrixStack, int mouseX, int mouseY, float delta) { + public void renderButton(DrawContext drawContext, int mouseX, int mouseY, float delta) { hovered = isWithinBounds(mouseX, mouseY); - renderWidget(matrixStack, mouseX, mouseY, delta); - flagLabel.render(matrixStack, mouseX, mouseY, delta); - valueLabel.render(matrixStack, mouseX, mouseY, delta); + renderWidget(drawContext, mouseX, mouseY, delta); + flagLabel.render(drawContext, mouseX, mouseY, delta); + valueLabel.render(drawContext, mouseX, mouseY, delta); } public void setValue(boolean newValue) { @@ -85,15 +83,13 @@ public void setValue(boolean newValue) { "armorstands.flagToggle." + (newValue ^ inverted ? "on" : "off"))); } - private void renderWidget(MatrixStack matrixStack, int mouseX, int mouseY, float delta) { - RenderSystem.setShader(GameRenderer::getPositionTexProgram); - RenderSystem.setShaderTexture(0, WIDGETS_TEXTURE); + private void renderWidget(DrawContext drawContext, int mouseX, int mouseY, float delta) { RenderSystem.setShaderColor(1f, 1f, 1f, 1f); RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.enableDepthTest(); - drawNineSlicedTexture(matrixStack, + drawContext.drawNineSlicedTexture(WIDGETS_TEXTURE, widgetX, widgetY, WIDGET_WIDTH, @@ -104,7 +100,7 @@ private void renderWidget(MatrixStack matrixStack, int mouseX, int mouseY, float 0, 46); - renderBar(matrixStack, mouseX, mouseY, delta); + renderBar(drawContext, mouseX, mouseY, delta); } private int getTextureY() { @@ -118,13 +114,12 @@ private int getTextureY() { return 46 + i * 20; } - private void renderBar(MatrixStack matrixStack, int mouseX, int mouseY, float delta) { - RenderSystem.setShaderTexture(0, WIDGETS_TEXTURE); + private void renderBar(DrawContext drawContext, int mouseX, int mouseY, float delta) { RenderSystem.setShaderColor(1f, 1f, 1f, 1f); int offset = (currentValue ^ inverted) ? WIDGET_WIDTH - BAR_WIDTH : 0; - drawNineSlicedTexture(matrixStack, + drawContext.drawNineSlicedTexture(WIDGETS_TEXTURE, widgetX + offset, widgetY, BAR_WIDTH, diff --git a/src/main/java/me/roundaround/armorstands/client/gui/widget/IconButtonWidget.java b/src/main/java/me/roundaround/armorstands/client/gui/widget/IconButtonWidget.java index 2d3eecf..335b6dd 100644 --- a/src/main/java/me/roundaround/armorstands/client/gui/widget/IconButtonWidget.java +++ b/src/main/java/me/roundaround/armorstands/client/gui/widget/IconButtonWidget.java @@ -1,10 +1,9 @@ package me.roundaround.armorstands.client.gui.widget; -import com.mojang.blaze3d.systems.RenderSystem; import me.roundaround.armorstands.ArmorStandsMod; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.tooltip.Tooltip; import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; import net.minecraft.util.Identifier; @@ -19,11 +18,7 @@ public class IconButtonWidget extends ButtonWidget { protected final int textureIndex; public IconButtonWidget( - int x, - int y, - int textureIndex, - Text tooltip, - ButtonWidget.PressAction onPress) { + int x, int y, int textureIndex, Text tooltip, ButtonWidget.PressAction onPress) { super(x, y, WIDTH, HEIGHT, Text.empty(), onPress, ButtonWidget.DEFAULT_NARRATION_SUPPLIER); this.textureIndex = textureIndex; @@ -31,16 +26,14 @@ public IconButtonWidget( } @Override - public void renderButton(MatrixStack matrixStack, int mouseX, int mouseY, float delta) { - super.renderButton(matrixStack, mouseX, mouseY, delta); - - RenderSystem.setShaderTexture(0, TEXTURE); + public void renderButton(DrawContext drawContext, int mouseX, int mouseY, float delta) { + super.renderButton(drawContext, mouseX, mouseY, delta); int uIndex = this.textureIndex % ICONS_PER_ROW; int vIndex = this.textureIndex / ICONS_PER_ROW; int u = uIndex * WIDTH; int v = vIndex * HEIGHT; - drawTexture(matrixStack, getX(), getY(), u, v, WIDTH, HEIGHT); + drawContext.drawTexture(TEXTURE, getX(), getY(), u, v, WIDTH, HEIGHT); } } diff --git a/src/main/java/me/roundaround/armorstands/client/gui/widget/LabelWidget.java b/src/main/java/me/roundaround/armorstands/client/gui/widget/LabelWidget.java index 9676ac8..6d48764 100644 --- a/src/main/java/me/roundaround/armorstands/client/gui/widget/LabelWidget.java +++ b/src/main/java/me/roundaround/armorstands/client/gui/widget/LabelWidget.java @@ -2,13 +2,12 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.Drawable; -import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; import net.minecraft.util.math.MathHelper; -public class LabelWidget extends DrawableHelper implements Drawable { +public class LabelWidget implements Drawable { public static final int HEIGHT_WITH_PADDING = 13; public static final int PADDING = 2; @@ -53,11 +52,9 @@ private LabelWidget( } @Override - public void render(MatrixStack matrixStack, int mouseX, int mouseY, float delta) { + public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) { if (showBackground) { - fill( - matrixStack, - MathHelper.floor(left) - 2, + drawContext.fill(MathHelper.floor(left) - 2, MathHelper.floor(top) - 1, MathHelper.ceil(right) + 2, MathHelper.ceil(bottom) + 1, @@ -65,19 +62,18 @@ public void render(MatrixStack matrixStack, int mouseX, int mouseY, float delta) } if (showTextShadow) { - textRenderer.drawWithShadow( - matrixStack, + drawContext.drawTextWithShadow(textRenderer, text, - left + 0.5f, - top + 1, + Math.round(left + 0.5f), + Math.round(top + 1), 0xFFFFFFFF); } else { - textRenderer.draw( - matrixStack, + drawContext.drawText(textRenderer, text, - left + 0.5f, - top + 1, - 0xFFFFFFFF); + Math.round(left + 0.5f), + Math.round(top + 1), + 0xFFFFFFFF, + false); } } @@ -86,10 +82,7 @@ public boolean isMouseOver(double mouseX, double mouseY) { int pixelRight = MathHelper.ceil(right) + (showBackground ? 2 : 0); int pixelTop = MathHelper.floor(top) - (showBackground ? 1 : 0); int pixelBottom = MathHelper.ceil(bottom) + (showBackground ? 1 : 0); - return mouseX >= pixelLeft - && mouseY >= pixelTop - && mouseX < pixelRight - && mouseY < pixelBottom; + return mouseX >= pixelLeft && mouseY >= pixelTop && mouseX < pixelRight && mouseY < pixelBottom; } public void setText(Text text) { @@ -223,7 +216,14 @@ public Builder shiftForPadding() { @Override public LabelWidget build() { - return new LabelWidget(text, posX, posY, alignmentH, alignmentV, showBackground, showTextShadow, shiftForPadding); + return new LabelWidget(text, + posX, + posY, + alignmentH, + alignmentV, + showBackground, + showTextShadow, + shiftForPadding); } } diff --git a/src/main/java/me/roundaround/armorstands/mixin/InGameHudAccessor.java b/src/main/java/me/roundaround/armorstands/mixin/InGameHudAccessor.java index 7fd2f7d..8e6dc0a 100644 --- a/src/main/java/me/roundaround/armorstands/mixin/InGameHudAccessor.java +++ b/src/main/java/me/roundaround/armorstands/mixin/InGameHudAccessor.java @@ -1,7 +1,7 @@ package me.roundaround.armorstands.mixin; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.hud.InGameHud; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.Entity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Invoker; @@ -12,5 +12,5 @@ public interface InGameHudAccessor { public void invokeUpdateVignetteDarkness(Entity entity); @Invoker("renderVignetteOverlay") - public void invokeRenderVignetteOverlay(MatrixStack matrixStack, Entity entity); + public void invokeRenderVignetteOverlay(DrawContext context, Entity entity); } diff --git a/src/main/java/me/roundaround/armorstands/network/packet/c2s/RequestScreenPacket.java b/src/main/java/me/roundaround/armorstands/network/packet/c2s/RequestScreenPacket.java index 3a1f2f0..67231be 100644 --- a/src/main/java/me/roundaround/armorstands/network/packet/c2s/RequestScreenPacket.java +++ b/src/main/java/me/roundaround/armorstands/network/packet/c2s/RequestScreenPacket.java @@ -40,7 +40,7 @@ private void handleOnServer( ServerPlayerEntity player, ServerPlayNetworkHandler handler, PacketSender responseSender) { - ArmorStandEntity armorStand = (ArmorStandEntity) player.world.getEntityById(this.armorStandId); + ArmorStandEntity armorStand = (ArmorStandEntity) player.getWorld().getEntityById(this.armorStandId); if (armorStand == null) { return; diff --git a/src/main/java/me/roundaround/armorstands/screen/ArmorStandScreenHandler.java b/src/main/java/me/roundaround/armorstands/screen/ArmorStandScreenHandler.java index 6b31eea..f6e6c69 100644 --- a/src/main/java/me/roundaround/armorstands/screen/ArmorStandScreenHandler.java +++ b/src/main/java/me/roundaround/armorstands/screen/ArmorStandScreenHandler.java @@ -1,10 +1,7 @@ package me.roundaround.armorstands.screen; -import java.util.ArrayList; - import com.google.common.collect.ImmutableList; import com.mojang.datafixers.util.Pair; - import me.roundaround.armorstands.ArmorStandsMod; import me.roundaround.armorstands.entity.ArmorStandInventory; import me.roundaround.armorstands.mixin.ArmorStandEntityAccessor; @@ -27,29 +24,28 @@ import net.minecraft.text.Text; import net.minecraft.util.Identifier; -public class ArmorStandScreenHandler - extends ScreenHandler +import java.util.ArrayList; + +public class ArmorStandScreenHandler extends ScreenHandler implements HasArmorStand, HasArmorStandEditor { - public static final Identifier EMPTY_MAINHAND_ARMOR_SLOT = new Identifier( - ArmorStandsMod.MOD_ID, - "item/empty_armor_slot_sword"); + public static final Identifier EMPTY_MAINHAND_ARMOR_SLOT = + new Identifier(ArmorStandsMod.MOD_ID, "item/empty_armor_slot_sword"); private static final Identifier[] EMPTY_ARMOR_SLOT_TEXTURES = new Identifier[] { PlayerScreenHandler.EMPTY_BOOTS_SLOT_TEXTURE, PlayerScreenHandler.EMPTY_LEGGINGS_SLOT_TEXTURE, PlayerScreenHandler.EMPTY_CHESTPLATE_SLOT_TEXTURE, - PlayerScreenHandler.EMPTY_HELMET_SLOT_TEXTURE }; + PlayerScreenHandler.EMPTY_HELMET_SLOT_TEXTURE + }; private static final Identifier[] EMPTY_HAND_SLOT_TEXTURES = new Identifier[] { - EMPTY_MAINHAND_ARMOR_SLOT, - PlayerScreenHandler.EMPTY_OFFHAND_ARMOR_SLOT }; + EMPTY_MAINHAND_ARMOR_SLOT, PlayerScreenHandler.EMPTY_OFFHAND_ARMOR_SLOT + }; private static final EquipmentSlot[] EQUIPMENT_SLOT_ORDER = new EquipmentSlot[] { - EquipmentSlot.HEAD, - EquipmentSlot.CHEST, - EquipmentSlot.LEGS, - EquipmentSlot.FEET }; + EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET + }; private static final EquipmentSlot[] HAND_SLOT_ORDER = new EquipmentSlot[] { - EquipmentSlot.MAINHAND, - EquipmentSlot.OFFHAND }; + EquipmentSlot.MAINHAND, EquipmentSlot.OFFHAND + }; private final PlayerInventory playerInventory; private final ArmorStandEntity armorStand; @@ -85,13 +81,10 @@ public ArmorStandScreenHandler( } public ArmorStandScreenHandler( - int syncId, - PlayerInventory playerInventory, - PacketByteBuf buf) { - this( - syncId, + int syncId, PlayerInventory playerInventory, PacketByteBuf buf) { + this(syncId, playerInventory, - (ArmorStandEntity) playerInventory.player.world.getEntityById(buf.readInt()), + (ArmorStandEntity) playerInventory.player.getWorld().getEntityById(buf.readInt()), ScreenType.fromId(buf.readString())); } @@ -118,15 +111,13 @@ public void setStack(ItemStack stack) { @Override public Pair getBackgroundSprite() { - return Pair.of( - PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, - EMPTY_HAND_SLOT_TEXTURES[index]); + return Pair.of(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, EMPTY_HAND_SLOT_TEXTURES[index]); } @Override public boolean canTakeItems(PlayerEntity player) { - if (!ArmorStandScreenHandler.this.playerInventory.player.isCreative() - && isSlotDisabled(armorStand, equipmentSlot)) { + if (!ArmorStandScreenHandler.this.playerInventory.player.isCreative() && + isSlotDisabled(armorStand, equipmentSlot)) { return false; } return super.canTakeItems(player); @@ -134,8 +125,8 @@ && isSlotDisabled(armorStand, equipmentSlot)) { @Override public boolean canInsert(ItemStack stack) { - if (!ArmorStandScreenHandler.this.playerInventory.player.isCreative() - && isSlotDisabled(armorStand, equipmentSlot)) { + if (!ArmorStandScreenHandler.this.playerInventory.player.isCreative() && + isSlotDisabled(armorStand, equipmentSlot)) { return false; } return super.canInsert(stack); @@ -162,8 +153,8 @@ public int getMaxItemCount() { @Override public boolean canTakeItems(PlayerEntity player) { - if (!ArmorStandScreenHandler.this.playerInventory.player.isCreative() - && isSlotDisabled(armorStand, equipmentSlot)) { + if (!ArmorStandScreenHandler.this.playerInventory.player.isCreative() && + isSlotDisabled(armorStand, equipmentSlot)) { return false; } return super.canTakeItems(player); @@ -171,8 +162,8 @@ && isSlotDisabled(armorStand, equipmentSlot)) { @Override public boolean canInsert(ItemStack stack) { - if (!ArmorStandScreenHandler.this.playerInventory.player.isCreative() - && isSlotDisabled(armorStand, equipmentSlot)) { + if (!ArmorStandScreenHandler.this.playerInventory.player.isCreative() && + isSlotDisabled(armorStand, equipmentSlot)) { return false; } return equipmentSlot == ArmorStandEntity.getPreferredEquipmentSlot(stack); @@ -180,8 +171,7 @@ && isSlotDisabled(armorStand, equipmentSlot)) { @Override public Pair getBackgroundSprite() { - return Pair.of( - PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, + return Pair.of(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE, EMPTY_ARMOR_SLOT_TEXTURES[equipmentSlot.getEntitySlotId()]); } }); @@ -215,7 +205,8 @@ public PlayerInventory getPlayerInventory() { @Override public void sendContentUpdates() { if (this.playerInventory.player instanceof ServerPlayerEntity) { - ClientUpdatePacket.sendToClient((ServerPlayerEntity) this.playerInventory.player, this.armorStand); + ClientUpdatePacket.sendToClient((ServerPlayerEntity) this.playerInventory.player, + this.armorStand); } super.sendContentUpdates(); @@ -250,9 +241,8 @@ public ItemStack quickMove(PlayerEntity player, int index) { ItemStack originalStack = stack.copy(); if (index < PlayerInventory.MAIN_SIZE) { - if (!tryTransferArmor(stack) - && !tryTransferToMainHand(stack) - && !tryTransferToOffHand(stack)) { + if (!tryTransferArmor(stack) && !tryTransferToMainHand(stack) && + !tryTransferToOffHand(stack)) { return ItemStack.EMPTY; } } else { @@ -299,7 +289,8 @@ private boolean tryTransferToOffHand(ItemStack stack) { } public static boolean isSlotDisabled(ArmorStandEntity armorStand, EquipmentSlot slot) { - return (((ArmorStandEntityAccessor) armorStand).getDisabledSlots() & 1 << slot.getArmorStandSlotId()) != 0; + return (((ArmorStandEntityAccessor) armorStand).getDisabledSlots() & + 1 << slot.getArmorStandSlotId()) != 0; } public static class Factory implements ExtendedScreenHandlerFactory { @@ -321,12 +312,9 @@ public Text getDisplayName() { } @Override - public ScreenHandler createMenu(int syncId, PlayerInventory playerInventory, PlayerEntity player) { - return new ArmorStandScreenHandler( - syncId, - playerInventory, - this.armorStand, - this.screenType); + public ScreenHandler createMenu( + int syncId, PlayerInventory playerInventory, PlayerEntity player) { + return new ArmorStandScreenHandler(syncId, playerInventory, this.armorStand, this.screenType); } @Override diff --git a/src/main/java/me/roundaround/armorstands/server/command/ArmorStandsCommand.java b/src/main/java/me/roundaround/armorstands/server/command/ArmorStandsCommand.java index 8a070c7..36f3a49 100644 --- a/src/main/java/me/roundaround/armorstands/server/command/ArmorStandsCommand.java +++ b/src/main/java/me/roundaround/armorstands/server/command/ArmorStandsCommand.java @@ -1,14 +1,10 @@ package me.roundaround.armorstands.server.command; -import java.util.Collection; -import java.util.stream.Stream; - import com.mojang.authlib.GameProfile; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; - import me.roundaround.armorstands.ArmorStandsMod; import me.roundaround.armorstands.server.ArmorStandUsers; import net.minecraft.command.CommandSource; @@ -21,21 +17,24 @@ import net.minecraft.text.Text; import net.minecraft.text.Texts; +import java.util.Collection; +import java.util.stream.Stream; + public class ArmorStandsCommand { - private static final SimpleCommandExceptionType ADD_FAILED_EXCEPTION = new SimpleCommandExceptionType( - Text.translatable("armorstands.commands.add.failed")); - private static final SimpleCommandExceptionType REMOVE_FAILED_EXCEPTION = new SimpleCommandExceptionType( - Text.translatable("armorstands.commands.remove.failed")); - private static final SimpleCommandExceptionType RELOAD_FAILED_EXCEPTION = new SimpleCommandExceptionType( - Text.translatable("armorstands.commands.reload.failed")); + private static final SimpleCommandExceptionType ADD_FAILED_EXCEPTION = + new SimpleCommandExceptionType(Text.translatable("armorstands.commands.add.failed")); + private static final SimpleCommandExceptionType REMOVE_FAILED_EXCEPTION = + new SimpleCommandExceptionType(Text.translatable("armorstands.commands.remove.failed")); + private static final SimpleCommandExceptionType RELOAD_FAILED_EXCEPTION = + new SimpleCommandExceptionType(Text.translatable("armorstands.commands.reload.failed")); public static void register(CommandDispatcher dispatcher) { - LiteralArgumentBuilder baseCommand = CommandManager.literal(ArmorStandsMod.MOD_ID) - .requires(source -> source.isExecutedByPlayer() - && (source.hasPermissionLevel(2) || source.getServer().isSingleplayer())); + LiteralArgumentBuilder baseCommand = + CommandManager.literal(ArmorStandsMod.MOD_ID) + .requires(source -> source.isExecutedByPlayer() && + (source.hasPermissionLevel(2) || source.getServer().isSingleplayer())); - LiteralArgumentBuilder addSub = CommandManager - .literal("add") + LiteralArgumentBuilder addSub = CommandManager.literal("add") .then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()) .suggests((context, builder) -> { PlayerManager playerManager = context.getSource().getServer().getPlayerManager(); @@ -48,8 +47,7 @@ public static void register(CommandDispatcher dispatcher) { .executes((context) -> executeAdd(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")))); - LiteralArgumentBuilder removeSub = CommandManager - .literal("remove") + LiteralArgumentBuilder removeSub = CommandManager.literal("remove") .then(CommandManager.argument("targets", GameProfileArgumentType.gameProfile()) .suggests((context, builder) -> { return CommandSource.suggestMatching(ArmorStandUsers.getNames(), builder); @@ -57,14 +55,11 @@ public static void register(CommandDispatcher dispatcher) { .executes((context) -> executeRemove(context.getSource(), GameProfileArgumentType.getProfileArgument(context, "targets")))); - LiteralArgumentBuilder reloadSub = CommandManager - .literal("reload") - .executes((context) -> executeReload(context.getSource())); + LiteralArgumentBuilder reloadSub = + CommandManager.literal("reload").executes((context) -> executeReload(context.getSource())); - LiteralArgumentBuilder finalCommand = baseCommand - .then(addSub) - .then(removeSub) - .then(reloadSub); + LiteralArgumentBuilder finalCommand = + baseCommand.then(addSub).then(removeSub).then(reloadSub); dispatcher.register(finalCommand); } @@ -81,7 +76,8 @@ private static int executeAdd(ServerCommandSource source, Collection Text.translatable("armorstands.commands.add.success", + Texts.toText(profile)), true); added++; } @@ -104,7 +100,8 @@ private static int executeRemove(ServerCommandSource source, Collection Text.translatable("armorstands.commands.remove.success", + Texts.toText(profile)), true); removed++; } @@ -123,7 +120,7 @@ private static int executeReload(ServerCommandSource source) throws CommandSynta throw RELOAD_FAILED_EXCEPTION.create(); } - source.sendFeedback(Text.translatable("armorstands.commands.reload.success"), true); + source.sendFeedback(() -> Text.translatable("armorstands.commands.reload.success"), true); return 1; } } diff --git a/src/main/java/me/roundaround/armorstands/util/actions/ToolRackAction.java b/src/main/java/me/roundaround/armorstands/util/actions/ToolRackAction.java index 8206ec9..20876aa 100644 --- a/src/main/java/me/roundaround/armorstands/util/actions/ToolRackAction.java +++ b/src/main/java/me/roundaround/armorstands/util/actions/ToolRackAction.java @@ -32,7 +32,7 @@ public static ToolRackAction create(ArmorStandEntity armorStand) { actions.add(FlagAction.set(ArmorStandFlag.NO_GRAVITY, true)); actions.add(FlagAction.set(ArmorStandFlag.NAME, false)); actions.add(FlagAction.set(ArmorStandFlag.SMALL, false)); - actions.add(RotateAction.absolute(armorStand.world + actions.add(RotateAction.absolute(armorStand.getWorld() .getBlockState(hookPos) .get(TripwireHookBlock.FACING).asRotation())); actions.add(MoveAction.absolute( @@ -57,7 +57,7 @@ private static BlockPos findTripwireHook(ArmorStandEntity armorStand) { for (int i = 1; i <= 3; i++) { mutable.set(pos.getX(), pos.getY() + i, pos.getZ()); - BlockState state = armorStand.world.getBlockState(mutable); + BlockState state = armorStand.getWorld().getBlockState(mutable); if (state.isOf(Blocks.TRIPWIRE_HOOK)) { return mutable.toImmutable(); }