From 29157f2be65a3c8890df561e2e58dcfd2e5d07dc Mon Sep 17 00:00:00 2001 From: ACGaming <4818419+ACGaming@users.noreply.github.com> Date: Mon, 15 Jan 2024 18:27:28 +0100 Subject: [PATCH] Implement villager trade restock tweak --- README.md | 3 ++- .../config/UTConfigTweaks.java | 7 ++++++- .../universaltweaks/core/UTLoadingPlugin.java | 2 +- .../trading/mixin/UTMerchantRecipeMixin.java | 19 +++++++++++++++++++ .../mixins.tweaks.entities.trading.json | 2 +- 5 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 src/main/java/mod/acgaming/universaltweaks/tweaks/entities/trading/mixin/UTMerchantRecipeMixin.java diff --git a/README.md b/README.md index 408aeef9..4367c0f6 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ All changes are toggleable via config files. * **Entity Bounding Boxes:** Saves entity bounding boxes to tags to prevent breakouts and suffocation * **Entity Desync:** Fixes entity motion desyncs most notable with arrows and thrown items * **Entity ID:** Fixes non-functional elytra firework boosting and guardian targeting if the entity ID is 0 -* **Entity Lists:** Fixes entity lists often not getting updated correctly +* **Entity Lists:** Fixes entity lists often not getting updated correctly * **Entity NaN:** Prevents corruption of entities caused by invalid health or damage values * **Entity Suffocation:** Pushes entities out of blocks when growing up to prevent suffocation * **Entity Tracker:** Fixes entity tracker to prevent client-sided desyncs when teleporting or changing dimensions @@ -117,6 +117,7 @@ All changes are toggleable via config files. * **Disable Narrator:** Disables the narrator functionality entirely * **Disable Sleeping:** Disables skipping night by using a bed while making it still able to set spawn * **Disable Villager Trade Leveling:** Disables leveling of villager careers, only allowing base level trades +* **Disable Villager Trade Restock:** Disables restocking of villager trades, only allowing one trade per offer * **Disable Wither Targeting AI:** Disables withers targeting animals * **Easy Breeding:** Enables easy breeding of animals by tossing food on the ground * **End Portal Parallax:** Re-implements parallax rendering of the end portal from 1.11 and older diff --git a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java index 7b6759ff..486e56ee 100644 --- a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java +++ b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java @@ -436,6 +436,11 @@ public static class EntitiesCategory @Config.Comment("Disables leveling of villager careers, only allowing base level trades") public boolean utVillagerTradeLevelingToggle = false; + @Config.RequiresMcRestart + @Config.Name("Disable Villager Trade Restock") + @Config.Comment("Disables restocking of villager trades, only allowing one trade per offer") + public boolean utVillagerTradeRestockToggle = false; + @Config.RequiresMcRestart @Config.Name("Disable Wither Targeting AI") @Config.Comment("Disables withers targeting animals") @@ -1022,7 +1027,7 @@ public static class ItemEntitiesCategory @Config.Name("[17] Slowed Movement") @Config.Comment("Slows how often item entities update their position to improve performance") - public boolean utIEUpdateToggle = true; + public boolean utIEUpdateToggle = true; } public static class MendingCategory diff --git a/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java b/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java index 69944bce..be2d9bcd 100644 --- a/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java +++ b/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java @@ -436,7 +436,7 @@ public boolean shouldMixinConfigQueue(String mixinConfig) case "mixins.tweaks.entities.taming.horse.json": return UTConfigTweaks.ENTITIES.UNDEAD_HORSES.utTamingUndeadHorsesToggle; case "mixins.tweaks.entities.trading.json": - return UTConfigTweaks.ENTITIES.utVillagerTradeLevelingToggle; + return UTConfigTweaks.ENTITIES.utVillagerTradeLevelingToggle || UTConfigTweaks.ENTITIES.utVillagerTradeRestockToggle; case "mixins.tweaks.items.attackcooldown.server.json": return UTConfigTweaks.ITEMS.ATTACK_COOLDOWN.utAttackCooldownToggle; case "mixins.tweaks.items.eating.json": diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/entities/trading/mixin/UTMerchantRecipeMixin.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/entities/trading/mixin/UTMerchantRecipeMixin.java new file mode 100644 index 00000000..355d9cde --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/entities/trading/mixin/UTMerchantRecipeMixin.java @@ -0,0 +1,19 @@ +package mod.acgaming.universaltweaks.tweaks.entities.trading.mixin; + +import net.minecraft.village.MerchantRecipe; + +import mod.acgaming.universaltweaks.config.UTConfigTweaks; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(MerchantRecipe.class) +public class UTMerchantRecipeMixin +{ + @Inject(method = "getMaxTradeUses", at = @At("HEAD"), cancellable = true) + public void utGetMaxTradeUses(CallbackInfoReturnable cir) + { + if (UTConfigTweaks.ENTITIES.utVillagerTradeRestockToggle) cir.setReturnValue(1); + } +} \ No newline at end of file diff --git a/src/main/resources/mixins.tweaks.entities.trading.json b/src/main/resources/mixins.tweaks.entities.trading.json index 626371bb..3cc4a00a 100644 --- a/src/main/resources/mixins.tweaks.entities.trading.json +++ b/src/main/resources/mixins.tweaks.entities.trading.json @@ -3,5 +3,5 @@ "refmap": "universaltweaks.refmap.json", "minVersion": "0.8", "compatibilityLevel": "JAVA_8", - "mixins": ["UTVillagerRegistryMixin"] + "mixins": ["UTMerchantRecipeMixin", "UTVillagerRegistryMixin"] } \ No newline at end of file