From 4150e6cabaad9b1880f186c893a5fe242835eee3 Mon Sep 17 00:00:00 2001 From: Thomas <1688389+Rakambda@users.noreply.github.com> Date: Thu, 15 Aug 2024 12:38:02 +0200 Subject: [PATCH] Reenable CLothConfig for Forge (#740) --- forge/build.gradle | 2 +- .../fallingtree/forge/FallingTree.java | 28 ++++++++------- ...ook.java.disabled => ClothConfigHook.java} | 34 ++++--------------- 3 files changed, 24 insertions(+), 40 deletions(-) rename forge/src/main/java/fr/rakambda/fallingtree/forge/client/cloth/{ClothConfigHook.java.disabled => ClothConfigHook.java} (92%) diff --git a/forge/build.gradle b/forge/build.gradle index d31f0b51..45fdeab0 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -57,7 +57,7 @@ dependencies { minecraft(libs.forge) library(project(":common")) - //implementation(fg.deobf("me.shedaniel.cloth:cloth-config-forge:${libs.versions.clothConfigVersion.get()}")) + implementation("me.shedaniel.cloth:cloth-config-forge:${libs.versions.clothConfigVersion.get()}") // Hack fix for now, force jopt-simple to be exactly 5.0.4 because Mojang ships that version, but some transitive dependencies request 6.0+ implementation('net.sf.jopt-simple:jopt-simple:5.0.4') { version { strictly '5.0.4' } } diff --git a/forge/src/main/java/fr/rakambda/fallingtree/forge/FallingTree.java b/forge/src/main/java/fr/rakambda/fallingtree/forge/FallingTree.java index 4c874a8d..6fbea030 100644 --- a/forge/src/main/java/fr/rakambda/fallingtree/forge/FallingTree.java +++ b/forge/src/main/java/fr/rakambda/fallingtree/forge/FallingTree.java @@ -1,10 +1,14 @@ package fr.rakambda.fallingtree.forge; +import fr.rakambda.fallingtree.common.FallingTreeCommon; +import fr.rakambda.fallingtree.forge.client.cloth.ClothConfigHook; import fr.rakambda.fallingtree.forge.common.FallingTreeCommonsImpl; import lombok.Getter; import lombok.extern.log4j.Log4j2; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.common.Mod; +import java.lang.reflect.InvocationTargetException; @Log4j2 @Mod(FallingTree.MOD_ID) @@ -14,18 +18,18 @@ public class FallingTree{ private static final FallingTreeCommonsImpl mod = new FallingTreeCommonsImpl(); public FallingTree(){ - // if(ModList.get().isLoaded("cloth_config")){ - // try{ - // Class.forName("fr.rakambda.fallingtree.forge.client.cloth.ClothConfigHook") - // .asSubclass(ClothConfigHook.class) - // .getConstructor(FallingTreeCommon.class) - // .newInstance(mod) - // .load(); - // } - // catch(ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e){ - // log.error("Failed to hook into ClothConfig", e); - // } - // } + if(ModList.get().isLoaded("cloth_config")){ + try{ + Class.forName("fr.rakambda.fallingtree.forge.client.cloth.ClothConfigHook") + .asSubclass(ClothConfigHook.class) + .getConstructor(FallingTreeCommon.class) + .newInstance(mod) + .load(); + } + catch(ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e){ + log.error("Failed to hook into ClothConfig", e); + } + } mod.registerForge(MinecraftForge.EVENT_BUS); } diff --git a/forge/src/main/java/fr/rakambda/fallingtree/forge/client/cloth/ClothConfigHook.java.disabled b/forge/src/main/java/fr/rakambda/fallingtree/forge/client/cloth/ClothConfigHook.java similarity index 92% rename from forge/src/main/java/fr/rakambda/fallingtree/forge/client/cloth/ClothConfigHook.java.disabled rename to forge/src/main/java/fr/rakambda/fallingtree/forge/client/cloth/ClothConfigHook.java index 068302a6..9d5f804d 100644 --- a/forge/src/main/java/fr/rakambda/fallingtree/forge/client/cloth/ClothConfigHook.java.disabled +++ b/forge/src/main/java/fr/rakambda/fallingtree/forge/client/cloth/ClothConfigHook.java @@ -7,6 +7,7 @@ import fr.rakambda.fallingtree.common.config.enums.BreakOrder; import fr.rakambda.fallingtree.common.config.enums.DamageRounding; import fr.rakambda.fallingtree.common.config.enums.DetectionMode; +import fr.rakambda.fallingtree.common.config.enums.DurabilityMode; import fr.rakambda.fallingtree.common.config.enums.MaxSizeAction; import fr.rakambda.fallingtree.common.config.enums.NotificationMode; import fr.rakambda.fallingtree.common.config.enums.SneakMode; @@ -317,11 +318,11 @@ private void fillToolsConfigScreen(@NotNull ConfigBuilder builder, @NotNull Tool .setTooltip(getTooltips("tools", "speedMultiplicand")) .setSaveConsumer(config::setSpeedMultiplicand) .build(); - var preserveEntry = builder.entryBuilder() - .startBooleanToggle(translatable(getFieldName("tools", "preserve")), config.isPreserve()) - .setDefaultValue(false) - .setTooltip(getTooltips("tools", "preserve")) - .setSaveConsumer(config::setPreserve) + var durabilityModeEntry = builder.entryBuilder() + .startEnumSelector(translatable(getFieldName("tools", "durabilityMode")), DurabilityMode.class, config.getDurabilityMode()) + .setDefaultValue(DurabilityMode.NORMAL) + .setTooltip(getTooltips("tools", "durabilityMode")) + .setSaveConsumer(config::setDurabilityMode) .build(); var forceToolUsageEntry = builder.entryBuilder() .startBooleanToggle(translatable(getFieldName("tools", "forceToolUsage")), config.isForceToolUsage()) @@ -337,7 +338,7 @@ private void fillToolsConfigScreen(@NotNull ConfigBuilder builder, @NotNull Tool tools.addEntry(damageMultiplicandEntry); tools.addEntry(damageRoundingEntry); tools.addEntry(speedMultiplicandEntry); - tools.addEntry(preserveEntry); + tools.addEntry(durabilityModeEntry); tools.addEntry(forceToolUsageEntry); } @@ -356,24 +357,6 @@ private void fillPlayerConfigScreen(@NotNull ConfigBuilder builder, @NotNull Pla @OnlyIn(Dist.CLIENT) private void fillEnchantmentConfigScreen(@NotNull ConfigBuilder builder, @NotNull EnchantmentConfiguration config){ - var registerEnchantEntry = builder.entryBuilder() - .startBooleanToggle(translatable(getFieldName("enchantment", "registerEnchant")), config.isRegisterEnchant()) - .setDefaultValue(false) - .setTooltip(getTooltips("enchantment", "registerEnchant")) - .setSaveConsumer(config::setRegisterEnchant) - .build(); - var registerSpecificEnchantEntry = builder.entryBuilder() - .startBooleanToggle(translatable(getFieldName("enchantment", "registerSpecificEnchant")), config.isRegisterSpecificEnchant()) - .setDefaultValue(false) - .setTooltip(getTooltips("enchantment", "registerSpecificEnchant")) - .setSaveConsumer(config::setRegisterSpecificEnchant) - .build(); - var hideEnchantEntry = builder.entryBuilder() - .startBooleanToggle(translatable(getFieldName("enchantment", "hideEnchant")), config.isHideEnchant()) - .setDefaultValue(false) - .setTooltip(getTooltips("enchantment", "hideEnchant")) - .setSaveConsumer(config::setHideEnchant) - .build(); var requireEnchantmentEntry = builder.entryBuilder() .startBooleanToggle(translatable(getFieldName("enchantment", "requireEnchantment")), config.isRequireEnchantment()) .setDefaultValue(false) @@ -382,9 +365,6 @@ private void fillEnchantmentConfigScreen(@NotNull ConfigBuilder builder, @NotNul .build(); var enchantment = builder.getOrCreateCategory(translatable("text.autoconfig.fallingtree.category.enchantment")); - enchantment.addEntry(registerEnchantEntry); - enchantment.addEntry(registerSpecificEnchantEntry); - enchantment.addEntry(hideEnchantEntry); enchantment.addEntry(requireEnchantmentEntry); }