diff --git a/build.gradle b/build.gradle index 1e9f14e..186bd86 100644 --- a/build.gradle +++ b/build.gradle @@ -33,7 +33,7 @@ processResources { } } -def targetJavaVersion = 17 +def targetJavaVersion = 21 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 dba79fd..a539264 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,8 +2,8 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://modmuss50.me/fabric.html -minecraft_version=1.20.4 -yarn_mappings=1.20.4+build.3 +minecraft_version=1.20.6 +yarn_mappings=1.20.6+build.1 loader_version=0.15.11 # Mod Properties mod_version=1.2-1.20.4 @@ -11,4 +11,4 @@ maven_group=de.gamedude archives_base_name=EasyVillagerTrade # Dependencies # check this on https://modmuss50.me/fabric.html -fabric_version=0.97.0+1.20.4 +fabric_version=0.98.0+1.20.6 diff --git a/src/main/java/de/gamedude/easyvillagertrade/commands/EasyVillagerTradeCommand.java b/src/main/java/de/gamedude/easyvillagertrade/commands/EasyVillagerTradeCommand.java index 9ae3abe..024d2e7 100644 --- a/src/main/java/de/gamedude/easyvillagertrade/commands/EasyVillagerTradeCommand.java +++ b/src/main/java/de/gamedude/easyvillagertrade/commands/EasyVillagerTradeCommand.java @@ -11,7 +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.ArgumentTypes; import net.minecraft.command.argument.RegistryEntryArgumentType; +import net.minecraft.command.argument.RegistryEntryReferenceArgumentType; +import net.minecraft.command.argument.serialize.ArgumentSerializer; import net.minecraft.enchantment.Enchantment; import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.entry.RegistryEntry; @@ -36,10 +39,10 @@ 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", RegistryEntryArgumentType.registryEntry(registryAccess, RegistryKeys.ENCHANTMENT)) + .then(literal("add").then(argument("maxPrice", IntegerArgumentType.integer()).then(argument("enchantment", RegistryEntryReferenceArgumentType.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)) + .then(literal("remove").then(argument("enchantment", RegistryEntryReferenceArgumentType.registryEntry(registryAccess, RegistryKeys.ENCHANTMENT)) .executes(this::executeRemoveTradeRequest))) .then(literal("list").executes(this::executeListTradeRequest))) diff --git a/src/main/java/de/gamedude/easyvillagertrade/core/EasyVillagerTradeBase.java b/src/main/java/de/gamedude/easyvillagertrade/core/EasyVillagerTradeBase.java index b7b5dca..cd314f1 100644 --- a/src/main/java/de/gamedude/easyvillagertrade/core/EasyVillagerTradeBase.java +++ b/src/main/java/de/gamedude/easyvillagertrade/core/EasyVillagerTradeBase.java @@ -6,12 +6,13 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.ItemEnchantmentsComponent; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.network.packet.c2s.play.HandSwingC2SPacket; -import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; import net.minecraft.util.Hand; @@ -19,14 +20,11 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3d; -import net.minecraft.util.math.random.LocalRandom; import net.minecraft.village.TradeOffer; import net.minecraft.village.TradeOfferList; import net.minecraft.village.VillagerProfession; import net.minecraft.world.World; -import java.util.Map; - public class EasyVillagerTradeBase { private TradingState state; @@ -77,7 +75,7 @@ public void handle() { case APPLY_TRADE -> tradeInterface.applyTrade(); case PICKUP_TRADE -> tradeInterface.pickupBook(); case WAIT_JOB_LOSS -> { - if(selectionInterface.getVillager().getVillagerData().getProfession() == VillagerProfession.NONE) + if (selectionInterface.getVillager().getVillagerData().getProfession() == VillagerProfession.NONE) setState(TradingState.PLACE_WORKSTATION); } } @@ -87,7 +85,7 @@ private void handlePlacement() { ClientPlayerEntity player = minecraftClient.player; BlockPos lecternPos = selectionInterface.getLecternPos(); - if(player.getOffHandStack().equals(ItemStack.EMPTY)) { + if (player.getOffHandStack().equals(ItemStack.EMPTY)) { player.sendMessage(Text.translatable("evt.logic.lectern_non")); setState(TradingState.INACTIVE); return; @@ -109,13 +107,13 @@ private void handleBreak() { if (world == null || player == null) return; ItemStack axe = player.getMainHandStack(); - if(axe.getMaxDamage() - axe.getDamage() < 20) { + if (axe.getMaxDamage() - axe.getDamage() < 20) { player.sendMessage(Text.translatable("evt.logic.axe_durability")); setState(TradingState.INACTIVE); return; } - if(blockPos == null) { + if (blockPos == null) { player.sendMessage(Text.translatable("evt.logic.pos_not_set")); setState(TradingState.INACTIVE); return; @@ -137,19 +135,22 @@ public void checkVillagerOffers(TradeOfferList tradeOffers) { bookOffer = offers; break; } + if (bookOffer == null) { setState(TradingState.BREAK_WORKSTATION); return; } - Map enchantmentMap = EnchantmentHelper.get(bookOffer.getSellItem()); - Enchantment bookEnchantment = enchantmentMap.keySet().iterator().next(); - int level = enchantmentMap.values().iterator().next(); - TradeRequest offer = new TradeRequest(bookEnchantment, level, bookOffer.getAdjustedFirstBuyItem().getCount()); + + ItemEnchantmentsComponent enchantments = EnchantmentHelper.getEnchantments(bookOffer.getSellItem()); + Enchantment bookEnchantment = enchantments.getEnchantments().iterator().next().value(); + int level = enchantments.getLevel(bookEnchantment); + + TradeRequest offer = new TradeRequest(bookEnchantment, level, bookOffer.getDisplayedFirstBuyItem().getCount()); if (tradeRequestContainer.matchesAny(offer)) { minecraftClient.player.sendMessage(Text.translatable("evt.logic.trade_found", "§e" + bookEnchantment.getName(level).getString(), "§a" + offer.maxPrice())); - minecraftClient.getSoundManager().play(new PositionedSoundInstance(SoundEvents.BLOCK_AMETHYST_CLUSTER_BREAK, SoundCategory.MASTER, 2f, 1f, new LocalRandom(0), MinecraftClient.getInstance().player.getBlockPos())); + minecraftClient.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.BLOCK_AMETHYST_CLUSTER_BREAK, 1f)); tradeRequestContainer.removeTradeRequestByEnchantment(bookEnchantment); tradeInterface.setTradeSlotID(tradeOffers.indexOf(bookOffer)); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 0ba2b73..40a2fad 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.21", + "fabricloader": ">=0.15.11", "fabric-api": "*", - "minecraft": ">=1.20.2" + "minecraft": ">=1.20.5" } }