diff --git a/build.gradle b/build.gradle index 07e2068..a8c8c08 100644 --- a/build.gradle +++ b/build.gradle @@ -33,7 +33,7 @@ dependencies { modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}+$minecraft_version" + modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" include(implementation("com.electronwill.night-config:toml:3.6.0")) diff --git a/gradle.properties b/gradle.properties index faa33f5..a9b653b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.20.4 +minecraft_version=24w06a parchment_version=2023.09.03 loader_version=0.15.6 @@ -14,4 +14,4 @@ maven_group=com.kirbosoftware archives_base_name=poyolib # Dependencies -fabric_version=0.95.4 \ No newline at end of file +fabric_version=0.96.1+1.20.5 \ No newline at end of file diff --git a/src/main/java/com/kirbosoftware/poyolib/api/item/armor/ArmorBuilder.java b/src/main/java/com/kirbosoftware/poyolib/api/item/armor/ArmorBuilder.java index c009f80..78112b7 100644 --- a/src/main/java/com/kirbosoftware/poyolib/api/item/armor/ArmorBuilder.java +++ b/src/main/java/com/kirbosoftware/poyolib/api/item/armor/ArmorBuilder.java @@ -1,5 +1,6 @@ package com.kirbosoftware.poyolib.api.item.armor; +import net.minecraft.core.Holder; import net.minecraft.world.item.ArmorItem; import net.minecraft.world.item.ArmorMaterial; @@ -8,44 +9,44 @@ public class ArmorBuilder { public static class Helmet extends ArmorItem { /** * Creates a helmet with the chosen materials. - * @param material The armor material. + * @param holder The armor material. * @param properties Item properties. */ - public Helmet(ArmorMaterial material, Properties properties) { - super(material, Type.HELMET, properties.stacksTo(1)); + public Helmet(Holder holder, Properties properties) { + super(holder, Type.HELMET, properties.stacksTo(1)); } } public static class Chestplate extends ArmorItem { /** * Creates a chestplate with the chosen materials. - * @param material The armor material. + * @param holder The armor material. * @param properties Item properties. */ - public Chestplate(ArmorMaterial material, Properties properties) { - super(material, Type.CHESTPLATE, properties.stacksTo(1)); + public Chestplate(Holder holder, Properties properties) { + super(holder, Type.CHESTPLATE, properties.stacksTo(1)); } } public static class Leggings extends ArmorItem { /** * Creates a pair of leggings with the chosen materials. - * @param material The armor material. + * @param holder The armor material. * @param properties Item properties. */ - public Leggings(ArmorMaterial material, Properties properties) { - super(material, Type.LEGGINGS, properties.stacksTo(1)); + public Leggings(Holder holder, Properties properties) { + super(holder, Type.LEGGINGS, properties.stacksTo(1)); } } public static class Boots extends ArmorItem { /** * Creates a pair of boots with the chosen materials. - * @param material The armor material. + * @param holder The armor material. * @param properties Item properties. */ - public Boots(ArmorMaterial material, Properties properties) { - super(material, Type.BOOTS, properties.stacksTo(1)); + public Boots(Holder holder, Properties properties) { + super(holder, Type.BOOTS, properties.stacksTo(1)); } } } \ No newline at end of file diff --git a/src/main/java/com/kirbosoftware/poyolib/api/item/craft/CraftedItemDamage.java b/src/main/java/com/kirbosoftware/poyolib/api/item/craft/CraftedItemDamage.java index 17005dc..228da0f 100644 --- a/src/main/java/com/kirbosoftware/poyolib/api/item/craft/CraftedItemDamage.java +++ b/src/main/java/com/kirbosoftware/poyolib/api/item/craft/CraftedItemDamage.java @@ -1,6 +1,5 @@ package com.kirbosoftware.poyolib.api.item.craft; -import net.minecraft.util.RandomSource; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -38,11 +37,13 @@ public boolean canBeDepleted() { */ @Override public ItemStack getRecipeRemainder(ItemStack stack) { - ItemStack copy = stack.copy(); - if (copy.hurt(1, RandomSource.create(), null)) - return ItemStack.EMPTY; - else + if (stack.getDamageValue() < stack.getMaxDamage() - 1) { + ItemStack copy = stack.copy(); + copy.setDamageValue(stack.getDamageValue() + 1); return copy; + } else { + return ItemStack.EMPTY; + } } /** diff --git a/src/main/java/com/kirbosoftware/poyolib/api/item/craft/CraftedToolDamage.java b/src/main/java/com/kirbosoftware/poyolib/api/item/craft/CraftedToolDamage.java index 5cffc71..3b369bf 100644 --- a/src/main/java/com/kirbosoftware/poyolib/api/item/craft/CraftedToolDamage.java +++ b/src/main/java/com/kirbosoftware/poyolib/api/item/craft/CraftedToolDamage.java @@ -1,6 +1,5 @@ package com.kirbosoftware.poyolib.api.item.craft; -import net.minecraft.util.RandomSource; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Tier; import net.minecraft.world.item.TieredItem; @@ -39,11 +38,13 @@ public boolean canBeDepleted() { */ @Override public ItemStack getRecipeRemainder(ItemStack stack) { - ItemStack copy = stack.copy(); - if (copy.hurt(1, RandomSource.create(), null)) - return ItemStack.EMPTY; - else + if (stack.getDamageValue() < stack.getMaxDamage() - 1) { + ItemStack copy = stack.copy(); + copy.setDamageValue(stack.getDamageValue() + 1); return copy; + } else { + return ItemStack.EMPTY; + } } /** diff --git a/src/main/java/com/kirbosoftware/poyolib/api/world/entity/npc/README.md b/src/main/java/com/kirbosoftware/poyolib/api/world/entity/npc/README.md new file mode 100644 index 0000000..3a9ce6f --- /dev/null +++ b/src/main/java/com/kirbosoftware/poyolib/api/world/entity/npc/README.md @@ -0,0 +1,22 @@ +# Villager Trade Helper + +This is a simple helper method to adjust villager trades upon your need. + +## Example + +This is how you would alter a villager's trade based upon it's ItemListing. Super easy and useful to do! +```java +import com.kirbosoftware.poyolib.api.world.entity.npc.VillagerTradeHelper; +import net.minecraft.world.entity.npc.VillagerProfession; + +public class ModifyTrades { + public static void init() { + VillagerTradeHelper.modifyTrades(villagerProfession, tier, tradeList -> { + tradeList.add("tradeList"); + tradeList.add("tradeList"); + }); + // or + VillagerTradeHelper.modifyTrades(villagerProfession, tier, tradeId, "tradeList"); + } +} +``` \ No newline at end of file diff --git a/src/main/java/com/kirbosoftware/poyolib/api/world/entity/npc/VillagerTradeHelper.java b/src/main/java/com/kirbosoftware/poyolib/api/world/entity/npc/VillagerTradeHelper.java new file mode 100644 index 0000000..9e56555 --- /dev/null +++ b/src/main/java/com/kirbosoftware/poyolib/api/world/entity/npc/VillagerTradeHelper.java @@ -0,0 +1,60 @@ +package com.kirbosoftware.poyolib.api.world.entity.npc; + +import net.minecraft.world.entity.npc.VillagerProfession; +import net.minecraft.world.entity.npc.VillagerTrades; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; + +/** + * The {@code VillagerTradeHelper} class provides utility methods for modifying trades of villagers. + * These methods can be used to customize the trades offered by villagers based on their profession and tier. + * + *

Usage example:

+ *
+ * {@code
+ * // Modify trades using a consumer
+ * VillagerTradeHelper.modifyTrades(VillagerProfession.FARMER, 1, tradeList -> {
+ *     // Add or modify trades in the provided list
+ *     tradeList.add(new VillagerTrades.ItemListing(...));
+ *     // Additional trade modifications...
+        * });
+        *
+        * // Modify a specific trade using an ItemListing factory
+        * VillagerTradeHelper.modifyTrades(VillagerProfession.FISHERMAN, 2, 0, new VillagerTrades.ItemListing(...));
+        * }
+        * 
+ * + *

Note: It is important to handle trades carefully to avoid unintended consequences.

+ */ +@SuppressWarnings("unused") +public class VillagerTradeHelper { + + /** + * Modifies the trades for a specific villager profession and tier using a consumer. + * + * @param profession The villager's profession. + * @param tier The tier of the trades to be modified. + * @param factory A consumer providing a list of {@code ItemListing} to be added or modified. + */ + public static void modifyTrades(VillagerProfession profession, int tier, Consumer> factory) { + List list = new ArrayList<>(); + factory.accept(list); + VillagerTrades.ItemListing[] originalEntries = VillagerTrades.TRADES.get(profession).get(tier); + VillagerTrades.ItemListing[] modifiedEntries = list.toArray(new VillagerTrades.ItemListing[0]); + System.arraycopy(modifiedEntries, 0, originalEntries, 0, modifiedEntries.length); + } + + /** + * Modifies a specific trade for a given villager profession, tier, and trade ID. + * + * @param profession The villager's profession. + * @param tier The tier of the trade to be modified. + * @param tradeId The ID of the trade within the specified tier. + * @param factory The {@code ItemListing} to replace the existing trade. + */ + public static void modifyTrades(VillagerProfession profession, int tier, int tradeId, VillagerTrades.ItemListing factory) { + VillagerTrades.TRADES.get(profession).get(tier)[tradeId] = factory; + } +} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index ad6bfc8..fc4269b 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -23,7 +23,7 @@ "poyolib.mixins.json" ], "depends": { - "fabricloader": ">=0.14.21", + "fabricloader": ">=0.15.6", "minecraft": ">=1.20", "java": ">=17" },