From c7d9727bf08310ead31e8fb699b3c165a5827b00 Mon Sep 17 00:00:00 2001 From: GameduJS Date: Wed, 8 May 2024 21:18:27 +0200 Subject: [PATCH] Update 1.20.2-1.20.4; Gradle update --- build.gradle | 4 +- gradle.properties | 10 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- .../easyvillagertrade/EasyVillagerTrade.java | 1 + .../commands/EasyVillagerTradeCommand.java | 23 +++-- .../core/SelectionInterface.java | 4 +- .../core/TradeRequestInputHandler.java | 5 +- .../mixin/NetworkPacketMixin.java | 6 +- .../screen/TradeSelectScreen.java | 45 +++++----- .../screen/widget/EnchantmentInputWidget.java | 19 +++-- .../screen/widget/TradeRequestListWidget.java | 84 +++++++++---------- src/main/resources/fabric.mod.json | 6 +- 12 files changed, 116 insertions(+), 93 deletions(-) diff --git a/build.gradle b/build.gradle index de11c58..1e9f14e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.1-SNAPSHOT' + id 'fabric-loom' version '1.6-SNAPSHOT' id 'maven-publish' } @@ -79,3 +79,5 @@ publishing { // retrieving dependencies. } } + + diff --git a/gradle.properties b/gradle.properties index 0dcec42..dba79fd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,13 +2,13 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://modmuss50.me/fabric.html -minecraft_version=1.19.2 -yarn_mappings=1.19.2+build.28 -loader_version=0.14.17 +minecraft_version=1.20.4 +yarn_mappings=1.20.4+build.3 +loader_version=0.15.11 # Mod Properties -mod_version=1.2-1.19.2 +mod_version=1.2-1.20.4 maven_group=de.gamedude archives_base_name=EasyVillagerTrade # Dependencies # check this on https://modmuss50.me/fabric.html -fabric_version=0.75.1+1.19.2 +fabric_version=0.97.0+1.20.4 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index aa991fc..48c0a02 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/de/gamedude/easyvillagertrade/EasyVillagerTrade.java b/src/main/java/de/gamedude/easyvillagertrade/EasyVillagerTrade.java index 0708f1a..f8c92c6 100644 --- a/src/main/java/de/gamedude/easyvillagertrade/EasyVillagerTrade.java +++ b/src/main/java/de/gamedude/easyvillagertrade/EasyVillagerTrade.java @@ -37,6 +37,7 @@ public void onInitialize() { KeyBindingHelper.registerKeyBinding(keyBinding); } + public void registerCallbacks() { UseEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> { if (hand == Hand.OFF_HAND || hitResult == null || !world.isClient()) diff --git a/src/main/java/de/gamedude/easyvillagertrade/commands/EasyVillagerTradeCommand.java b/src/main/java/de/gamedude/easyvillagertrade/commands/EasyVillagerTradeCommand.java index 6eefe7d..9ae3abe 100644 --- a/src/main/java/de/gamedude/easyvillagertrade/commands/EasyVillagerTradeCommand.java +++ b/src/main/java/de/gamedude/easyvillagertrade/commands/EasyVillagerTradeCommand.java @@ -11,8 +11,10 @@ import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.command.argument.EnchantmentArgumentType; +import net.minecraft.command.argument.RegistryEntryArgumentType; import net.minecraft.enchantment.Enchantment; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.text.Text; import org.apache.commons.lang3.StringUtils; @@ -34,9 +36,12 @@ public void register(CommandDispatcher dispatcher, Co dispatcher.register(literal(command_base) .then(literal("select").then(literal("close").executes(this::executeSelectionClosest)).executes(this::executeSelection)) .then(literal("search") - .then(literal("add").then(argument("maxPrice", IntegerArgumentType.integer()).then(argument("enchantment", EnchantmentArgumentType.enchantment()).executes(this::executeAddTradeRequest).then(argument("level", IntegerArgumentType.integer()).executes(this::executeAddTradeRequest))))) + .then(literal("add").then(argument("maxPrice", IntegerArgumentType.integer()).then(argument("enchantment", RegistryEntryArgumentType.registryEntry(registryAccess, RegistryKeys.ENCHANTMENT)) + .executes(this::executeAddTradeRequest).then(argument("level", IntegerArgumentType.integer()).executes(this::executeAddTradeRequest))))) + + .then(literal("remove").then(argument("enchantment", RegistryEntryArgumentType.registryEntry(registryAccess, RegistryKeys.ENCHANTMENT)) + .executes(this::executeRemoveTradeRequest))) - .then(literal("remove").then(argument("enchantment", EnchantmentArgumentType.enchantment()).executes(this::executeRemoveTradeRequest))) .then(literal("list").executes(this::executeListTradeRequest))) .then(literal("execute").executes(this::executeVillagerTrade)) .then(literal("stop").executes(ctx -> { @@ -51,7 +56,10 @@ public void register(CommandDispatcher dispatcher, Co public int executeAddTradeRequest(CommandContext context) { - Enchantment enchantment = context.getArgument("enchantment", Enchantment.class); + RegistryEntry.Reference reference = context.getArgument("enchantment", RegistryEntry.Reference.class); + if(!(reference.value() instanceof Enchantment enchantment)) + return 0; + int maxPrice = context.getArgument("maxPrice", Integer.class); int level = getArgumentOrElse(context, "level", Integer.class, enchantment.getMaxLevel()); @@ -63,7 +71,10 @@ public int executeAddTradeRequest(CommandContext cont } public int executeRemoveTradeRequest(CommandContext context) { - Enchantment enchantment = context.getArgument("enchantment", Enchantment.class); + RegistryEntry.Reference reference = context.getArgument("enchantment", RegistryEntry.Reference.class); + if(!(reference.value() instanceof Enchantment enchantment)) + return 0; + modBase.getTradeRequestContainer().removeTradeRequestByEnchantment(enchantment); boolean multipleLevels = enchantment.getMaxLevel() == 1; @@ -109,7 +120,7 @@ private T getArgumentOrElse(CommandContext contex T t; try { t = context.getArgument(argument, argumentClass); - } catch ( IllegalArgumentException e ) { + } catch (IllegalArgumentException e) { return orElse; } return t; diff --git a/src/main/java/de/gamedude/easyvillagertrade/core/SelectionInterface.java b/src/main/java/de/gamedude/easyvillagertrade/core/SelectionInterface.java index 049f62a..106e062 100644 --- a/src/main/java/de/gamedude/easyvillagertrade/core/SelectionInterface.java +++ b/src/main/java/de/gamedude/easyvillagertrade/core/SelectionInterface.java @@ -29,14 +29,14 @@ public SelectionInterface(EasyVillagerTradeBase modBase) { public void setLecternPos(BlockPos blockPos) { this.lecternPos = blockPos; } public int selectClosestToPlayer(ClientPlayerEntity player) { - Optional closestBlockOptional = BlockPos.findClosest(player.getBlockPos(), 3, 0, blockPos -> player.world.getBlockState(blockPos).getBlock() instanceof LecternBlock); + Optional closestBlockOptional = BlockPos.findClosest(player.getBlockPos(), 3, 0, blockPos -> player.getWorld().getBlockState(blockPos).getBlock() instanceof LecternBlock); if(closestBlockOptional.isEmpty()) { modBase.setState(TradingState.INACTIVE); return 1; } this.lecternPos = closestBlockOptional.get(); - this.villager = getClosestEntity(player.world, this.lecternPos); + this.villager = getClosestEntity(player.getWorld(), this.lecternPos); if(this.villager == null) { modBase.setState(TradingState.INACTIVE); return 2; diff --git a/src/main/java/de/gamedude/easyvillagertrade/core/TradeRequestInputHandler.java b/src/main/java/de/gamedude/easyvillagertrade/core/TradeRequestInputHandler.java index 2667de8..a2cf63e 100644 --- a/src/main/java/de/gamedude/easyvillagertrade/core/TradeRequestInputHandler.java +++ b/src/main/java/de/gamedude/easyvillagertrade/core/TradeRequestInputHandler.java @@ -2,13 +2,14 @@ import de.gamedude.easyvillagertrade.utils.TradeRequest; import net.minecraft.enchantment.Enchantment; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; import net.minecraft.text.Text; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.registry.Registry; public class TradeRequestInputHandler { - private static final Registry ENCHANTMENT_REGISTRY = Registry.ENCHANTMENT; + private static final Registry ENCHANTMENT_REGISTRY = Registries.ENCHANTMENT; public TradeRequest handleCommandInput(Enchantment enchantment, int inputLevel, int maxPrice) { int level = mapLevel(enchantment, inputLevel); diff --git a/src/main/java/de/gamedude/easyvillagertrade/mixin/NetworkPacketMixin.java b/src/main/java/de/gamedude/easyvillagertrade/mixin/NetworkPacketMixin.java index edc922a..1b6e527 100644 --- a/src/main/java/de/gamedude/easyvillagertrade/mixin/NetworkPacketMixin.java +++ b/src/main/java/de/gamedude/easyvillagertrade/mixin/NetworkPacketMixin.java @@ -9,7 +9,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.entity.passive.VillagerEntity; import net.minecraft.network.ClientConnection; -import net.minecraft.network.Packet; +import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket; import net.minecraft.network.packet.s2c.play.EntityStatusS2CPacket; import net.minecraft.network.packet.s2c.play.OpenScreenS2CPacket; @@ -17,6 +17,7 @@ import net.minecraft.screen.ScreenHandlerType; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -25,9 +26,10 @@ @Mixin(ClientConnection.class) public abstract class NetworkPacketMixin { + @Unique private final EasyVillagerTradeBase modBase = EasyVillagerTrade.getModBase(); - @Inject(method = "channelRead0(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/Packet;)V", at = @At("HEAD"), cancellable = true) + @Inject(method = "channelRead0(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/packet/Packet;)V", at = @At("HEAD"), cancellable = true) private void channelRead(ChannelHandlerContext context, Packet packet, CallbackInfo ci) { if(packet instanceof EntityStatusS2CPacket statusPacket) { World world = MinecraftClient.getInstance().world; diff --git a/src/main/java/de/gamedude/easyvillagertrade/screen/TradeSelectScreen.java b/src/main/java/de/gamedude/easyvillagertrade/screen/TradeSelectScreen.java index 9506384..61712b9 100644 --- a/src/main/java/de/gamedude/easyvillagertrade/screen/TradeSelectScreen.java +++ b/src/main/java/de/gamedude/easyvillagertrade/screen/TradeSelectScreen.java @@ -6,11 +6,10 @@ import de.gamedude.easyvillagertrade.screen.widget.TradeRequestListWidget; import de.gamedude.easyvillagertrade.utils.TradeRequest; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.DrawableHelper; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.TextFieldWidget; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.enchantment.Enchantment; import net.minecraft.text.Text; import net.minecraft.util.math.ColorHelper; @@ -49,25 +48,26 @@ protected void init() { TextFieldWidget priceTextFieldWidget = new TextFieldWidget(textRenderer, x + 30 + enchantmentWidth + levelWidth, px + 15, priceWidth, 20, Text.of("Price")); TradeRequestListWidget tradeRequestListWidget = new TradeRequestListWidget(x + 10, px + 80, width - x - px - 20, this.height - px - 50); - modBase.getTradeRequestContainer().getTradeRequests().forEach(tradeRequest -> tradeRequestListWidget.addEntry(new TradeRequestListWidget.TradeRequestEntry(tradeRequest))); + modBase.getTradeRequestContainer().getTradeRequests().forEach(tradeRequestListWidget::addEntry); this.addDrawableChild(enchantmentInputWidget); this.addDrawableChild(levelTextFieldWidget); this.addDrawableChild(priceTextFieldWidget); - this.addDrawableChild(new ButtonWidget(x + 9, px + 15 + 20 + 5, 50, 20, Text.of("Add"), button -> { + + ButtonWidget addButton = ButtonWidget.builder(Text.of("Add"), button -> { TradeRequest request = modBase.getTradeRequestInputHandler().handleGUIInput(enchantmentInputWidget.getText(), levelTextFieldWidget.getText(), priceTextFieldWidget.getText()); if (request != null) { if (!modBase.getTradeRequestContainer().getTradeRequests().contains(request)) { - tradeRequestListWidget.addEntry(new TradeRequestListWidget.TradeRequestEntry(request)); + tradeRequestListWidget.addEntry(request); modBase.getTradeRequestContainer().addTradeRequest(request); clearTextFieldWidgets(enchantmentInputWidget, levelTextFieldWidget, priceTextFieldWidget); } } else { enchantmentInputWidget.setEditableColor(ColorHelper.Argb.getArgb(255, 255, 0, 0)); } - })); + }).position(x + 9, px + 15 + 20 + 5).size(50, 20).build(); - this.addDrawableChild(new ButtonWidget(x + 70, px + 40, 50, 20, Text.of("Remove"), button -> { + ButtonWidget removeButton = ButtonWidget.builder(Text.of("Remove"), button -> { Enchantment enchantment = modBase.getTradeRequestInputHandler().getEnchantment(enchantmentInputWidget.getText()); if (enchantment == null) { enchantmentInputWidget.setEditableColor(ColorHelper.Argb.getArgb(255, 255, 0, 0)); @@ -75,34 +75,37 @@ protected void init() { } for (Iterator it = tradeRequestListWidget.children().iterator(); it.hasNext(); ) { TradeRequestListWidget.TradeRequestEntry entry = it.next(); - if (entry.tradeRequest.enchantment().getTranslationKey().equals(enchantment.getTranslationKey())) { - modBase.getTradeRequestContainer().removeTradeRequest(entry.tradeRequest); - it.remove(); - clearTextFieldWidgets(enchantmentInputWidget, levelTextFieldWidget, priceTextFieldWidget); - } + if (entry.tradeRequest.enchantment().getTranslationKey().equals(enchantment.getTranslationKey())) { + modBase.getTradeRequestContainer().removeTradeRequest(entry.tradeRequest); + it.remove(); + clearTextFieldWidgets(enchantmentInputWidget, levelTextFieldWidget, priceTextFieldWidget); + } } - })); + }).position(x + 70, px + 40).size(50, 20).build(); + + this.addDrawableChild(addButton); + this.addDrawableChild(removeButton); this.addDrawableChild(tradeRequestListWidget); } @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { - this.renderBackground(matrices); - super.render(matrices, mouseX, mouseY, delta); + public void render(DrawContext context, int mouseX, int mouseY, float delta) { + this.renderBackground(context, mouseX, mouseY, delta); + super.render(context, mouseX, mouseY, delta); int px = (int) (this.width / 50f); int x = this.width - px - widgetWidth; - this.textRenderer.draw(matrices, Text.of("Enchantment"), x + 10, px + 6, 0xE0E0E0); - this.textRenderer.draw(matrices, Text.of("Level"), x + 20 + enchantmentWidth, px + 6, 0xE0E0E0); - this.textRenderer.draw(matrices, Text.of("Price"), x + 30 + enchantmentWidth + levelWidth, px + 6, 0xE0E0E0); + context.drawText(textRenderer, "Enchantment", x + 10, px + 6, 0xE0E0E0, false); + context.drawText(textRenderer, "Level", x + 20 + enchantmentWidth, px + 6, 0xE0E0E0, false); + context.drawText(textRenderer, "Price", x + 30 + enchantmentWidth + priceWidth, px + 6, 0xE0E0E0, false); } @Override - public void renderBackground(MatrixStack matrices) { + public void renderBackground(DrawContext context, int mouseX, int mouseY, float delta) { int px = (int) (this.width / 50f); int x = this.width - px - widgetWidth; - DrawableHelper.fill(matrices, x, px, this.width - px, this.height - px, ColorHelper.Argb.getArgb(150, 7, 7, 7)); + context.fill(x, px, this.width - px, this.height - px, ColorHelper.Argb.getArgb(150, 7, 7, 7)); } public void clearTextFieldWidgets(TextFieldWidget... textFieldWidgets){ diff --git a/src/main/java/de/gamedude/easyvillagertrade/screen/widget/EnchantmentInputWidget.java b/src/main/java/de/gamedude/easyvillagertrade/screen/widget/EnchantmentInputWidget.java index 573d82e..a6dbcb9 100644 --- a/src/main/java/de/gamedude/easyvillagertrade/screen/widget/EnchantmentInputWidget.java +++ b/src/main/java/de/gamedude/easyvillagertrade/screen/widget/EnchantmentInputWidget.java @@ -2,12 +2,17 @@ import joptsimple.internal.Strings; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.navigation.GuiNavigation; +import net.minecraft.client.gui.navigation.GuiNavigationPath; +import net.minecraft.client.gui.navigation.NavigationDirection; import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.enchantment.Enchantment; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; import net.minecraft.text.Text; import net.minecraft.util.math.ColorHelper; -import net.minecraft.util.registry.Registry; import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; import java.util.Arrays; @@ -15,7 +20,7 @@ public class EnchantmentInputWidget extends TextFieldWidget { - private static final Registry ENCHANTMENT_REGISTRY = Registry.ENCHANTMENT; + private static final Registry ENCHANTMENT_REGISTRY = Registries.ENCHANTMENT; private String suggestion; public EnchantmentInputWidget(int x, int y, int width, int height) { @@ -32,7 +37,7 @@ private Consumer getChangeListener() { else this.setEditableColor(0xE0E0E0); - suggestion = getPossibleEnchantmentNameOrElse(text).toLowerCase().replaceFirst("" + text.toLowerCase().replace("+", ""), ""); + suggestion = getPossibleEnchantmentNameOrElse(text).toLowerCase().replaceFirst(text.toLowerCase().replace("+", ""), ""); setSuggestion(suggestion); }; } @@ -63,12 +68,12 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) { return super.keyPressed(keyCode, scanCode, modifiers); } + @Nullable @Override - public boolean changeFocus(boolean lookForwards) { - if(lookForwards) { + public GuiNavigationPath getNavigationPath(GuiNavigation navigation) { + if (navigation.getDirection() == NavigationDirection.DOWN) setEnchantmentText(); - } - return super.changeFocus(lookForwards); + return super.getNavigationPath(navigation); } private void setEnchantmentText() { diff --git a/src/main/java/de/gamedude/easyvillagertrade/screen/widget/TradeRequestListWidget.java b/src/main/java/de/gamedude/easyvillagertrade/screen/widget/TradeRequestListWidget.java index 0ffbc22..97e0399 100644 --- a/src/main/java/de/gamedude/easyvillagertrade/screen/widget/TradeRequestListWidget.java +++ b/src/main/java/de/gamedude/easyvillagertrade/screen/widget/TradeRequestListWidget.java @@ -8,7 +8,6 @@ import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.*; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import net.minecraft.util.math.ColorHelper; @@ -16,7 +15,7 @@ import java.util.ArrayList; import java.util.List; -import java.util.function.Consumer; +import java.util.Optional; public class TradeRequestListWidget extends AbstractParentElement implements Drawable, Selectable { @@ -51,15 +50,15 @@ public TradeRequestEntry getEntry(int index) { } @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + public void render(DrawContext context, int mouseX, int mouseY, float delta) { ENTRIES_PER_PAGE = (int) Math.ceil((height - y + 5) / (ENTRY_HEIGHT + 5f) - 1); if (ENTRIES_PER_PAGE == 0) return; - this.renderBackground(matrices); + this.renderBackground(context); for (int index = 0; index < Math.min(getEntryCount(), ENTRIES_PER_PAGE); ++index) { - getEntry(index + getOffset()).render(matrices, index, x, y + 1, width); + getEntry(index + getOffset()).render(context, index, x, y + 1, width); } } @@ -83,33 +82,40 @@ public List children() { } @Override - public boolean mouseScrolled(double mouseX, double mouseY, double amount) { - this.setScrollAmount(scrollAmount - (amount * (ENTRY_HEIGHT + 5))); + public boolean mouseScrolled(double mouseX, double mouseY, double horizontal, double vertical) { + this.scrollAmount = MathHelper.clamp( + scrollAmount - (vertical * (ENTRY_HEIGHT + 5)), + 0.0, + this.getMaxScroll()); return true; } - public void setScrollAmount(double amount) { - this.scrollAmount = MathHelper.clamp(amount, 0.0, this.getMaxScroll()); - } - @Override public boolean isMouseOver(double mouseX, double mouseY) { return x <= mouseX && mouseX <= (x + width) && y <= mouseY && mouseY <= height; } - private void renderBackground(MatrixStack matrices) { - fill(matrices, x - 1, y, x + width + 1, y + 1, -1); // horizontal - fill(matrices, x - 2, height, x + width + 2, height + 1, -1); - fill(matrices, x - 2, y, x - 1, height, -1); // vertical - fill(matrices, x + width + 1, y, x + width + 2, height, -1); + private void renderBackground(DrawContext context) { + context.fill(x - 1, y, x + width + 1, y + 1, -1); // horizontal + context.fill(x - 2, height, x + width + 2, height + 1, -1); + context.fill(x - 2, y, x - 1, height, -1); // vertical + context.fill(x + width + 1, y, x + width + 2, height, -1); + } + + public void addEntry(TradeRequest entry) { + children.add(new TradeRequestEntry(entry)); } - public void addEntry(TradeRequestEntry entry) { - entry.setRemoveConsumer(tradeRequestEntry -> { - modBase.getTradeRequestContainer().removeTradeRequest(tradeRequestEntry.tradeRequest); - children.remove(tradeRequestEntry); - }); - children.add(entry); + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + boolean bl = super.mouseClicked(mouseX, mouseY, button); + Optional element = this.hoveredElement(mouseX, mouseY); + if(element.isEmpty()) + return bl; + TradeRequestEntry tradeRequestEntry = (TradeRequestEntry) element.get(); + children.remove(tradeRequestEntry); + modBase.getTradeRequestContainer().removeTradeRequest(tradeRequestEntry.tradeRequest); + return bl; } @Override @@ -128,46 +134,38 @@ public static class TradeRequestEntry implements Element { public final TradeRequest tradeRequest; private int x,y1,x2,y2; - private Consumer removeConsumer; - public TradeRequestEntry(TradeRequest request) { this.tradeRequest = request; } - public void setRemoveConsumer(Consumer removeConsumer) { - this.removeConsumer = removeConsumer; - } - - private void render(MatrixStack matrices, int index, int x, int y, int entryWidth) { + private void render(DrawContext context, int index, int x, int y, int entryWidth) { this.x = x; this.y1 = y + (index * ENTRY_HEIGHT) + (5 * index); this.x2 = x + entryWidth; this.y2 = y + ENTRY_HEIGHT * (index + 1) + (5 * index); - DrawableHelper.fill(matrices, x, y1, x2, y2, ColorHelper.Argb.getArgb(240, 7, 7, 7)); + context.fill(x, y1, x2, y2, ColorHelper.Argb.getArgb(240, 7, 7, 7)); - RenderSystem.setShaderTexture(0, ENCHANTED_BOOK_TEXTURE); - DrawableHelper.drawTexture(matrices, x, y1, 0.0f, 0.0f, 16, 16, 16, 16); + context.drawTexture(ENCHANTED_BOOK_TEXTURE, x, y1, 0, 0, 16, 16, 16, 16); RenderSystem.setShaderTexture(0, EMERALD_TEXTURE); - DrawableHelper.drawTexture(matrices, x, y1 + 16, 24, 0f, 0f, 16, 16, 16, 16); + context.drawTexture(EMERALD_TEXTURE, x, y1 + 16,0, 0, 16, 16, 16, 16); - textRenderer.draw(matrices, tradeRequest.enchantment().getName(tradeRequest.level()), x + 20, y1 + 4, 0); - textRenderer.draw(matrices, Text.of("§e" + tradeRequest.maxPrice()), x + 20, y1 + 20, 0); + context.drawText(textRenderer, tradeRequest.enchantment().getName(tradeRequest.level()), x + 20, y1 + 4, 0, false); + context.drawText(textRenderer, Text.of("§e" + tradeRequest.maxPrice()), x + 20, y1 + 20, 0, false); } @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - boolean clicked = isMouseOver(mouseX, mouseY); - - if(clicked) - removeConsumer.accept(this); - return clicked; + public boolean isMouseOver(double mouseX, double mouseY) { + return x <= mouseX && mouseX <= x2 && y1 <= mouseY && mouseY <= y2; } @Override - public boolean isMouseOver(double mouseX, double mouseY) { - return x <= mouseX && mouseX <= x2 && y1 <= mouseY && mouseY <= y2; + public void setFocused(boolean focused) { } + + @Override + public boolean isFocused() { + return false; } } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index e46604e..0ba2b73 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -18,8 +18,8 @@ "EasyVillagerTrade.mixins.json" ], "depends": { - "fabricloader": ">=0.14.17", - "fabric": "*", - "minecraft": "1.19.2" + "fabricloader": ">=0.14.21", + "fabric-api": "*", + "minecraft": ">=1.20.2" } }