From 4752d7e737ca425dc80f257f4235763b2c883ec4 Mon Sep 17 00:00:00 2001 From: rugmj Date: Tue, 2 Jan 2024 16:48:29 +0000 Subject: [PATCH] fixes various errors --- .../features/commands/ColorCodeFeature.java | 7 ++++--- .../features/toggleable/AirPlaceFeature.java | 3 ++- .../macros/gui/screen/CommandEditScreen.java | 21 +++++++++---------- .../macros/gui/screen/MacroSelectScreen.java | 10 ++++----- .../macros/gui/widget/IconButtonWidget.java | 7 ++++--- .../gui/widget/macrolist/MacroEntry.java | 19 +++++++++-------- .../gui/widget/macrolist/MacroListWidget.java | 7 ++++--- .../redstonetools/utils/ColoredBlockType.java | 4 ++-- 8 files changed, 41 insertions(+), 37 deletions(-) diff --git a/src/main/java/tools/redstone/redstonetools/features/commands/ColorCodeFeature.java b/src/main/java/tools/redstone/redstonetools/features/commands/ColorCodeFeature.java index cbef6849..497775d8 100644 --- a/src/main/java/tools/redstone/redstonetools/features/commands/ColorCodeFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/commands/ColorCodeFeature.java @@ -1,6 +1,7 @@ package tools.redstone.redstonetools.features.commands; import com.google.auto.service.AutoService; +import com.sk89q.worldedit.function.pattern.Pattern; import tools.redstone.redstonetools.features.AbstractFeature; import tools.redstone.redstonetools.features.Feature; import tools.redstone.redstonetools.features.arguments.Argument; @@ -81,8 +82,8 @@ protected Feedback execute(ServerCommandSource source) throws CommandSyntaxExcep var playerSession = worldEdit.getSessionManager().get(wePlayer); // for each block in the selection - final World world = FabricAdapter.adapt(player.method_48926()); - try (EditSession session = worldEdit.newEditSession(FabricAdapter.adapt(player.method_48926()))) { + final World world = FabricAdapter.adapt(player.getWorld()); + try (EditSession session = worldEdit.newEditSession(FabricAdapter.adapt(player.getWorld()))) { // create mask and pattern and execute block set int blocksColored = session.replaceBlocks(selection, new Mask() { @@ -97,7 +98,7 @@ public Mask2D toMask2D() { return null; } }, - new com.sk89q.worldedit.function.pattern.Pattern() { + new Pattern() { @Override public BaseBlock applyBlock(BlockVector3 position) { return getColoredBlock(world, position, color.getValue()); diff --git a/src/main/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java b/src/main/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java index db0eba6a..94d7ef16 100644 --- a/src/main/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java +++ b/src/main/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java @@ -91,7 +91,8 @@ public static BlockHitResult findAirPlaceBlockHit(PlayerEntity playerEntity) { HitResult hitResult = findAirPlacePosition(client); if (hitResult == null) return true; - BlockPos blockPos = new BlockPos(hitResult.getPos()); + Vec3d pos = hitResult.getPos(); + BlockPos blockPos = new BlockPos((int) pos.x, (int) pos.y, (int) pos.z); BlockState blockState = ItemUtils.getUseState(client.player, ItemUtils.getMainItem(client.player), diff --git a/src/main/java/tools/redstone/redstonetools/macros/gui/screen/CommandEditScreen.java b/src/main/java/tools/redstone/redstonetools/macros/gui/screen/CommandEditScreen.java index d7eee994..90125762 100644 --- a/src/main/java/tools/redstone/redstonetools/macros/gui/screen/CommandEditScreen.java +++ b/src/main/java/tools/redstone/redstonetools/macros/gui/screen/CommandEditScreen.java @@ -1,5 +1,6 @@ package tools.redstone.redstonetools.macros.gui.screen; +import net.minecraft.client.gui.DrawContext; import tools.redstone.redstonetools.macros.gui.MacroCommandSuggestor; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; @@ -21,28 +22,27 @@ public CommandEditScreen(Screen parent, GameOptions gameOptions, TextFieldWidget super(parent, gameOptions, Text.of("")); this.commandField = commandField; client = MinecraftClient.getInstance(); - this.commandMacroCommandSuggestor = new MacroCommandSuggestor(client, parent, commandField,client.textRenderer,true,false, commandField.y -20,5,-805306368); + this.commandMacroCommandSuggestor = new MacroCommandSuggestor(client, parent, commandField,client.textRenderer,true,false, commandField.getY() -20,5,-805306368); commandField.setChangedListener((s) -> changed = true); commandMacroCommandSuggestor.setWindowActive(true); commandMacroCommandSuggestor.refresh(); } - @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { - parent.render(matrices, mouseX, mouseY, delta); + public void render(DrawContext context, int mouseX, int mouseY, float delta) { + parent.render(context, mouseX, mouseY, delta); - this.fillGradient(matrices, 0, 0, this.width, this.height, -1072689136, -804253680); + this.fillGradient(context, 0, 0, this.width, this.height, -1072689136, -804253680); - commandField.render(matrices, mouseX, mouseY, delta); + commandField.render(context, mouseX, mouseY, delta); - commandMacroCommandSuggestor.render(matrices, mouseX, mouseY); + commandMacroCommandSuggestor.render(context, mouseX, mouseY); if (changed) { commandMacroCommandSuggestor.refresh(); changed = false; } - super.render(matrices, mouseX, mouseY, delta); + super.render(context, mouseX, mouseY, delta); } @@ -60,7 +60,7 @@ public void resize(MinecraftClient client, int width, int height) { @Override public void close() { super.close(); - commandField.setTextFieldFocused(false); + commandField.setFocused(false); commandField.setChangedListener(null); commandMacroCommandSuggestor.setWindowActive(false); commandMacroCommandSuggestor.refresh(); @@ -73,14 +73,13 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) { if (!commandMacroCommandSuggestor.mouseClicked(mouseX, mouseY, button)) { close(); } else { - commandField.setTextFieldFocused(true); + commandField.setFocused(true); } return false; } return super.mouseClicked(mouseX, mouseY, button); } - @Override public boolean mouseScrolled(double mouseX, double mouseY, double amount) { return commandMacroCommandSuggestor.mouseScrolled(amount); } diff --git a/src/main/java/tools/redstone/redstonetools/macros/gui/screen/MacroSelectScreen.java b/src/main/java/tools/redstone/redstonetools/macros/gui/screen/MacroSelectScreen.java index a67687d8..ce7e9382 100644 --- a/src/main/java/tools/redstone/redstonetools/macros/gui/screen/MacroSelectScreen.java +++ b/src/main/java/tools/redstone/redstonetools/macros/gui/screen/MacroSelectScreen.java @@ -1,5 +1,6 @@ package tools.redstone.redstonetools.macros.gui.screen; +import net.minecraft.client.gui.DrawContext; import tools.redstone.redstonetools.macros.gui.widget.macrolist.MacroEntry; import tools.redstone.redstonetools.macros.gui.widget.macrolist.MacroListWidget; import net.minecraft.client.gui.screen.Screen; @@ -35,13 +36,12 @@ public void init() { })); } - @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void render(DrawContext context, int mouseX, int mouseY, float delta) { this.renderBackgroundTexture(0); - macroList.render(matrices, mouseX, mouseY, delta); + macroList.render(context, mouseX, mouseY, delta); - drawCenteredTextWithShadow(matrices, this.textRenderer, this.title, this.width / 2, 8, 16777215); - super.render(matrices, mouseX, mouseY, delta); + drawCenteredTextWithShadow(context, this.textRenderer, this.title, this.width / 2, 8, 16777215); + super.render(context, mouseX, mouseY, delta); } diff --git a/src/main/java/tools/redstone/redstonetools/macros/gui/widget/IconButtonWidget.java b/src/main/java/tools/redstone/redstonetools/macros/gui/widget/IconButtonWidget.java index e6e08235..af56ea36 100644 --- a/src/main/java/tools/redstone/redstonetools/macros/gui/widget/IconButtonWidget.java +++ b/src/main/java/tools/redstone/redstonetools/macros/gui/widget/IconButtonWidget.java @@ -2,6 +2,7 @@ import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; @@ -18,8 +19,8 @@ public IconButtonWidget(Identifier texture ,int x, int y, int width, int height, this.texture = texture; } - public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) { - super.renderButton(matrices, mouseX, mouseY, delta); + public void renderButton(DrawContext context, int mouseX, int mouseY, float delta) { + super.renderButton(context, mouseX, mouseY, delta); RenderSystem.setShaderTexture(0, texture); @@ -29,7 +30,7 @@ public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float del RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA); - drawTexture(matrices, this.x, this.y, 0,0, 20, this.height, 20, 20); + drawTexture(context, this.getX(), this.getY(), 0,0, 20, this.height, 20, 20); } } diff --git a/src/main/java/tools/redstone/redstonetools/macros/gui/widget/macrolist/MacroEntry.java b/src/main/java/tools/redstone/redstonetools/macros/gui/widget/macrolist/MacroEntry.java index 523e4810..8426057e 100644 --- a/src/main/java/tools/redstone/redstonetools/macros/gui/widget/macrolist/MacroEntry.java +++ b/src/main/java/tools/redstone/redstonetools/macros/gui/widget/macrolist/MacroEntry.java @@ -1,5 +1,6 @@ package tools.redstone.redstonetools.macros.gui.widget.macrolist; +import net.minecraft.client.gui.DrawContext; import tools.redstone.redstonetools.macros.Macro; import tools.redstone.redstonetools.macros.gui.widget.IconButtonWidget; import net.minecraft.client.gui.screen.ConfirmScreen; @@ -34,10 +35,10 @@ public MacroEntry(Macro macro, MacroListWidget owner) { } - public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { - renderWidget(buttonWidget,matrices,mouseX,mouseY,tickDelta,x-30,y-2); - renderWidget(editButton,matrices,mouseX,mouseY,tickDelta,x+entryWidth,y-2); - renderWidget(deleteButton,matrices,mouseX,mouseY,tickDelta,x+entryWidth+22,y-2); + public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { + renderWidget(buttonWidget,context,mouseX,mouseY,tickDelta,x-30,y-2); + renderWidget(editButton,context,mouseX,mouseY,tickDelta,x+entryWidth,y-2); + renderWidget(deleteButton,context,mouseX,mouseY,tickDelta,x+entryWidth+22,y-2); String text = macro.name; @@ -50,13 +51,13 @@ public void render(MatrixStack matrices, int index, int y, int x, int entryWidth } - owner.client.textRenderer.drawWithShadow(matrices, text, x, y+3,macro.enabled?16777215:8355711, true); + owner.client.textRenderer.drawWithShadow(context, text, x, y+3,macro.enabled?16777215:8355711, true); } - private void renderWidget(PressableWidget widget, MatrixStack matrices, int mouseX, int mouseY, float tickDelta, int x, int y) { - widget.x = x; - widget.y = y; - widget.render(matrices,mouseX,mouseY,tickDelta); + private void renderWidget(PressableWidget widget, DrawContext context, int mouseX, int mouseY, float tickDelta, int x, int y) { + widget.setX(x); + widget.setY(y); + widget.render(context,mouseX,mouseY,tickDelta); } public boolean mouseClicked(double mouseX, double mouseY, int button) { diff --git a/src/main/java/tools/redstone/redstonetools/macros/gui/widget/macrolist/MacroListWidget.java b/src/main/java/tools/redstone/redstonetools/macros/gui/widget/macrolist/MacroListWidget.java index 333f2bf4..73743d7a 100644 --- a/src/main/java/tools/redstone/redstonetools/macros/gui/widget/macrolist/MacroListWidget.java +++ b/src/main/java/tools/redstone/redstonetools/macros/gui/widget/macrolist/MacroListWidget.java @@ -1,5 +1,6 @@ package tools.redstone.redstonetools.macros.gui.widget.macrolist; +import net.minecraft.client.gui.DrawContext; import tools.redstone.redstonetools.macros.Macro; import tools.redstone.redstonetools.macros.MacroManager; import tools.redstone.redstonetools.macros.gui.screen.MacroSelectScreen; @@ -48,11 +49,11 @@ protected int getScrollbarPositionX() { } - protected void renderBackground(MatrixStack matrices) { - parent.renderBackground(matrices); + protected void renderBackground(DrawContext context, int mouseX, int mouseY, float delta) { + parent.renderBackground(context, mouseX, mouseY, delta); } - protected boolean isFocused() { + public boolean isFocused() { return parent.getFocused() == this; } diff --git a/src/main/java/tools/redstone/redstonetools/utils/ColoredBlockType.java b/src/main/java/tools/redstone/redstonetools/utils/ColoredBlockType.java index c8b14d90..0279defb 100644 --- a/src/main/java/tools/redstone/redstonetools/utils/ColoredBlockType.java +++ b/src/main/java/tools/redstone/redstonetools/utils/ColoredBlockType.java @@ -1,7 +1,7 @@ package tools.redstone.redstonetools.utils; import net.minecraft.block.Block; -import net.minecraft.registry.Registry; +import net.minecraft.registry.Registries; import net.minecraft.util.Identifier; public enum ColoredBlockType { @@ -34,6 +34,6 @@ public String toBlockId() { } public Block toBlock() { - return Registry.BLOCK.get(Identifier.tryParse(toBlockId())); + return Registries.BLOCK.get(Identifier.tryParse(toBlockId())); } }