From 6e5bd65418054b311cd8472e2af9b0a624ecd08f Mon Sep 17 00:00:00 2001 From: TheBluekr Date: Mon, 26 Jun 2023 23:04:23 +0200 Subject: [PATCH 1/2] Update files to 1.20.1 --- .../amymialee/noenchantcap/EnchantedBookCommand.java | 6 ++++-- .../amymialee/noenchantcap/mixin/AnvilMenuMixin.java | 10 +++++----- .../xyz/amymialee/noenchantcap/mixin/PlayerMixin.java | 2 +- Forge/build.gradle | 3 ++- gradle.properties | 8 ++++---- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Common/src/main/java/xyz/amymialee/noenchantcap/EnchantedBookCommand.java b/Common/src/main/java/xyz/amymialee/noenchantcap/EnchantedBookCommand.java index 7b3a8f1..b6ba826 100644 --- a/Common/src/main/java/xyz/amymialee/noenchantcap/EnchantedBookCommand.java +++ b/Common/src/main/java/xyz/amymialee/noenchantcap/EnchantedBookCommand.java @@ -10,6 +10,7 @@ import net.minecraft.core.Holder; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.EnchantedBookItem; import net.minecraft.world.item.ItemStack; @@ -17,6 +18,7 @@ import net.minecraft.world.item.enchantment.EnchantmentInstance; import java.util.Collection; +import java.util.function.Supplier; public class EnchantedBookCommand { public static void register(CommandDispatcher commandDispatcher, CommandBuildContext commandBuildContext) { @@ -35,9 +37,9 @@ private static int enchant(CommandSourceStack commandSourceStack, Collection) Component.translatable("commands.noenchantcap.enchantedbook.success.single", enchantment.getFullname(level), collection.iterator().next().getDisplayName()), true); } else { - commandSourceStack.sendSuccess(Component.translatable("commands.noenchantcap.enchantedbook.success.multiple", enchantment.getFullname(level), collection.size()), true); + commandSourceStack.sendSuccess((Supplier) Component.translatable("commands.noenchantcap.enchantedbook.success.multiple", enchantment.getFullname(level), collection.size()), true); } return collection.size(); } diff --git a/Common/src/main/java/xyz/amymialee/noenchantcap/mixin/AnvilMenuMixin.java b/Common/src/main/java/xyz/amymialee/noenchantcap/mixin/AnvilMenuMixin.java index e307fb2..c56ed33 100644 --- a/Common/src/main/java/xyz/amymialee/noenchantcap/mixin/AnvilMenuMixin.java +++ b/Common/src/main/java/xyz/amymialee/noenchantcap/mixin/AnvilMenuMixin.java @@ -31,7 +31,7 @@ public AnvilMenuMixin(@Nullable MenuType menuType, int i, Inventory inventory if (max == 1) { return 1; } - if (this.player.level.getGameRules().getBoolean(NoEnchantCap.UNCAPPED_ANVILS)) { + if (this.player.level().getGameRules().getBoolean(NoEnchantCap.UNCAPPED_ANVILS)) { return Integer.MAX_VALUE; } else { ItemStack itemStack1 = this.inputSlots.getItem(0); @@ -44,7 +44,7 @@ public AnvilMenuMixin(@Nullable MenuType menuType, int i, Inventory inventory @WrapOperation(method = "createResult", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/enchantment/Enchantment;isCompatibleWith(Lnet/minecraft/world/item/enchantment/Enchantment;)Z")) private boolean noEnchantCap$moreCombinations(Enchantment enchantment1, Enchantment enchantment2, Operation original) { - if (this.player.level.getGameRules().getBoolean(NoEnchantCap.MIX_ANY_ENCHANTS)) { + if (this.player.level().getGameRules().getBoolean(NoEnchantCap.MIX_ANY_ENCHANTS)) { return true; } return original.call(enchantment1, enchantment2); @@ -52,7 +52,7 @@ public AnvilMenuMixin(@Nullable MenuType menuType, int i, Inventory inventory @WrapOperation(method = "createResult", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;getAbilities()Lnet/minecraft/world/entity/player/Abilities;", ordinal = 0)) private Abilities noEnchantCap$enchantAnyItem(Player player, Operation original) { - if (this.player.level.getGameRules().getBoolean(NoEnchantCap.ENCHANT_ANY_ITEM)) { + if (this.player.level().getGameRules().getBoolean(NoEnchantCap.ENCHANT_ANY_ITEM)) { Abilities abilities = new Abilities(); abilities.instabuild = true; return abilities; @@ -67,13 +67,13 @@ public AnvilMenuMixin(@Nullable MenuType menuType, int i, Inventory inventory @WrapWithCondition(method = "createResult", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;setRepairCost(I)V")) private boolean noEnchantCap$staticRepairCost(ItemStack instance, int repairCost) { - return !this.player.level.getGameRules().getBoolean(NoEnchantCap.STATIC_REPAIR_COST); + return !this.player.level().getGameRules().getBoolean(NoEnchantCap.STATIC_REPAIR_COST); } @WrapWithCondition(method = "onTake", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;giveExperienceLevels(I)V")) private boolean noEnchantCap$fairAnvilCost(Player instance, int levels) { - if (this.player.level.getGameRules().getBoolean(NoEnchantCap.FAIR_EXPERIENCE_COST)) { + if (this.player.level().getGameRules().getBoolean(NoEnchantCap.FAIR_EXPERIENCE_COST)) { this.player.giveExperiencePoints(-noEnchantCap$getExperienceTotal(-levels)); return false; } diff --git a/Common/src/main/java/xyz/amymialee/noenchantcap/mixin/PlayerMixin.java b/Common/src/main/java/xyz/amymialee/noenchantcap/mixin/PlayerMixin.java index 7b46834..39af6fe 100644 --- a/Common/src/main/java/xyz/amymialee/noenchantcap/mixin/PlayerMixin.java +++ b/Common/src/main/java/xyz/amymialee/noenchantcap/mixin/PlayerMixin.java @@ -26,7 +26,7 @@ protected PlayerMixin(EntityType $$0, Level $$1) { @Inject(method = "onEnchantmentPerformed", at = @At(value = "HEAD"), cancellable = true) private void noEnchantCap$fairishEnchantCost(ItemStack stack, int levels, CallbackInfo ci) { - if (this.level.getGameRules().getBoolean(NoEnchantCap.FAIR_EXPERIENCE_COST)) { + if (this.level().getGameRules().getBoolean(NoEnchantCap.FAIR_EXPERIENCE_COST)) { int min = Math.min(30, this.experienceLevel); this.giveExperiencePoints(-noEnchantCap$getExperienceTotal(min - levels, min)); if (this.experienceLevel < 0) { diff --git a/Forge/build.gradle b/Forge/build.gradle index 6f48afb..e6ba24e 100644 --- a/Forge/build.gradle +++ b/Forge/build.gradle @@ -88,7 +88,8 @@ dependencies { minecraftLibrary("com.github.LlamaLad7:MixinExtras:0.1.1") annotationProcessor("com.github.LlamaLad7:MixinExtras:0.1.1") annotationProcessor('org.spongepowered:mixin:0.8.5:processor') - jarJar("com.github.LlamaLad7:MixinExtras:0.1.1") + implementation("com.github.LlamaLad7:MixinExtras:0.1.1") + //jarJar("com.github.LlamaLad7:MixinExtras:0.1.1") } shadowJar { diff --git a/gradle.properties b/gradle.properties index d4a4b64..953b666 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,18 +3,18 @@ version=2.2.6 group=xyz.amymialee.noenchantcap # Common -minecraft_version=1.19.3 +minecraft_version=1.20.1 common_runs_enabled=false common_client_run_name=Common Client common_server_run_name=Common Server # Forge -forge_version=44.0.23 +forge_version=47.0.19 forge_ats_enabled=true # Fabric https://fabricmc.net/develop/ -fabric_version=0.69.1+1.19.3 -fabric_loader_version=0.14.11 +fabric_version=0.84.0+1.20.1 +fabric_loader_version=0.14.21 # Mod options mod_name=No Enchant Cap From cd26b6f2d85b97767ed351adae867d1af2ae2c90 Mon Sep 17 00:00:00 2001 From: TheBluekr Date: Mon, 26 Jun 2023 23:06:23 +0200 Subject: [PATCH 2/2] Migrate mappings --- .../noenchantcap/NoEnchantCapFabric.java | 22 ++++++++++ .../noenchantcap/NoEnchantCapPreLaunch.java | 14 ++++++ .../platform/FabricPlatformHelper.java | 43 +++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 Fabric/remappedSrc/xyz/amymialee/noenchantcap/NoEnchantCapFabric.java create mode 100644 Fabric/remappedSrc/xyz/amymialee/noenchantcap/NoEnchantCapPreLaunch.java create mode 100644 Fabric/remappedSrc/xyz/amymialee/noenchantcap/platform/FabricPlatformHelper.java diff --git a/Fabric/remappedSrc/xyz/amymialee/noenchantcap/NoEnchantCapFabric.java b/Fabric/remappedSrc/xyz/amymialee/noenchantcap/NoEnchantCapFabric.java new file mode 100644 index 0000000..0b4e34c --- /dev/null +++ b/Fabric/remappedSrc/xyz/amymialee/noenchantcap/NoEnchantCapFabric.java @@ -0,0 +1,22 @@ +package xyz.amymialee.noenchantcap; + +import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import net.fabricmc.fabric.api.gamerule.v1.CustomGameRuleCategory; +import net.minecraft.text.Text; + +/** + * Initializes the custom gamerule category and the common initializer. + */ +public class NoEnchantCapFabric implements ModInitializer { + /** + * Custom Gamerules category for the mod on fabric. Uses players category on forge due to lack of custom gamerule categories. + */ + public static final CustomGameRuleCategory ENCHANT_CAP_GAMERULES = new CustomGameRuleCategory(NoEnchantCap.id("no_enchant_cap"), Text.translatable("gamerule.category."+ NoEnchantCap.MOD_ID)); + + @Override + public void onInitialize() { + NoEnchantCap.init(); + CommandRegistrationCallback.EVENT.register((commandDispatcher, commandBuildContext, commandSelection) -> EnchantedBookCommand.register(commandDispatcher, commandBuildContext)); + } +} \ No newline at end of file diff --git a/Fabric/remappedSrc/xyz/amymialee/noenchantcap/NoEnchantCapPreLaunch.java b/Fabric/remappedSrc/xyz/amymialee/noenchantcap/NoEnchantCapPreLaunch.java new file mode 100644 index 0000000..ef36558 --- /dev/null +++ b/Fabric/remappedSrc/xyz/amymialee/noenchantcap/NoEnchantCapPreLaunch.java @@ -0,0 +1,14 @@ +package xyz.amymialee.noenchantcap; + +import com.llamalad7.mixinextras.MixinExtrasBootstrap; +import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; + +/** + * PreLaunch to Initialize Mixin Extras which is used heavily in the mod. + */ +public class NoEnchantCapPreLaunch implements PreLaunchEntrypoint { + @Override + public void onPreLaunch() { + MixinExtrasBootstrap.init(); + } +} \ No newline at end of file diff --git a/Fabric/remappedSrc/xyz/amymialee/noenchantcap/platform/FabricPlatformHelper.java b/Fabric/remappedSrc/xyz/amymialee/noenchantcap/platform/FabricPlatformHelper.java new file mode 100644 index 0000000..12f435f --- /dev/null +++ b/Fabric/remappedSrc/xyz/amymialee/noenchantcap/platform/FabricPlatformHelper.java @@ -0,0 +1,43 @@ +package xyz.amymialee.noenchantcap.platform; + +import net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory; +import net.fabricmc.fabric.api.gamerule.v1.GameRuleRegistry; +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.world.GameRules; +import xyz.amymialee.noenchantcap.NoEnchantCapFabric; +import xyz.amymialee.noenchantcap.platform.services.IPlatformHelper; + +/** + * Handles Fabric exclusive code. + */ +public class FabricPlatformHelper implements IPlatformHelper { + @Override + public String getPlatformName() { + return "Fabric"; + } + + @Override + public boolean isModLoaded(String modId) { + return FabricLoader.getInstance().isModLoaded(modId); + } + + @Override + public boolean isDevelopmentEnvironment() { + return FabricLoader.getInstance().isDevelopmentEnvironment(); + } + + @Override + public > GameRules.Key registerGamerule(String name, GameRules.Type type) { + return GameRuleRegistry.register(name, NoEnchantCapFabric.ENCHANT_CAP_GAMERULES, type); + } + + @Override + public GameRules.Type createBooleanValue(boolean defaultValue) { + return GameRuleFactory.createBooleanRule(defaultValue); + } + + @Override + public GameRules.Type createIntegerValue(int defaultValue) { + return GameRuleFactory.createIntRule(defaultValue); + } +} \ No newline at end of file