From 7a947f0a945fc5fdd029f0ee81f20ca595b77b57 Mon Sep 17 00:00:00 2001 From: DragonEggBedrockBreaking <68545280+DragonEggBedrockBreaking@users.noreply.github.com> Date: Sun, 6 Oct 2024 01:09:35 +0100 Subject: [PATCH] Disable nutrition/saturation feature when nostalgic tweaks is present --- .../config/data/DataDefinitions.java | 23 +++++++++++-------- .../other/MixinDragonStrafePlayerPhase.java | 2 +- .../entity/other/MixinServerPlayer.java | 2 +- .../mixin/plugin/MixinPluginConfig.java | 11 ++++++++- .../plugin/VanillaDisableMixinPlugin.java | 6 +++++ .../vanilla_disable/platform/Services.java | 18 +++++++++++++++ .../platform/services/IPlatformHelper.java | 5 ++++ .../platform/FabricPlatformHelper.java | 11 +++++++++ ..._disable.platform.services.IPlatformHelper | 1 + .../platform/NeoForgePlatformHelper.java | 13 +++++++++++ ..._disable.platform.services.IPlatformHelper | 1 + 11 files changed, 81 insertions(+), 12 deletions(-) create mode 100644 common/src/main/java/uk/debb/vanilla_disable/platform/Services.java create mode 100644 common/src/main/java/uk/debb/vanilla_disable/platform/services/IPlatformHelper.java create mode 100644 fabric/src/main/java/uk/debb/vanilla_disable/platform/FabricPlatformHelper.java create mode 100644 fabric/src/main/resources/META-INF/services/uk.debb.vanilla_disable.platform.services.IPlatformHelper create mode 100644 neoforge/src/main/java/uk/debb/vanilla_disable/platform/NeoForgePlatformHelper.java create mode 100644 neoforge/src/main/resources/META-INF/services/uk.debb.vanilla_disable.platform.services.IPlatformHelper diff --git a/common/src/main/java/uk/debb/vanilla_disable/config/data/DataDefinitions.java b/common/src/main/java/uk/debb/vanilla_disable/config/data/DataDefinitions.java index f719c42f..06037f52 100644 --- a/common/src/main/java/uk/debb/vanilla_disable/config/data/DataDefinitions.java +++ b/common/src/main/java/uk/debb/vanilla_disable/config/data/DataDefinitions.java @@ -48,6 +48,7 @@ import net.minecraft.world.level.levelgen.placement.PlacedFeature; import net.minecraft.world.level.levelgen.structure.Structure; import net.minecraft.world.level.material.PushReaction; +import uk.debb.vanilla_disable.platform.Services; import java.util.Arrays; import java.util.List; @@ -239,8 +240,10 @@ public static void populateCols() { put("dispenser_interaction", new ObjectObjectImmutablePair<>(BOOLEAN, Component.translatable("vd.commandRule.items.dispenserInteraction"))); put("durability", new ObjectObjectImmutablePair<>(INTEGER, Component.translatable("vd.commandRule.items.durability"))); put("fuel_duration", new ObjectObjectImmutablePair<>(INTEGER, Component.translatable("vd.commandRule.items.fuelDuration"))); - put("nutrition", new ObjectObjectImmutablePair<>(INTEGER, Component.translatable("vd.commandRule.items.nutrition"))); - put("saturation", new ObjectObjectImmutablePair<>(REAL, Component.translatable("vd.commandRule.items.saturation"))); + if (!Services.PLATFORM.isModLoaded("nostalgic_tweaks")) { + put("nutrition", new ObjectObjectImmutablePair<>(INTEGER, Component.translatable("vd.commandRule.items.nutrition"))); + put("saturation", new ObjectObjectImmutablePair<>(REAL, Component.translatable("vd.commandRule.items.saturation"))); + } put("works", new ObjectObjectImmutablePair<>(BOOLEAN, Component.translatable("vd.commandRule.items.works"))); }}); }}); @@ -574,13 +577,15 @@ private static void populateRows() { } FoodProperties foodProperties = itemStack.get(DataComponents.FOOD); - if (foodProperties != null) { - put("nutrition", String.valueOf(foodProperties.nutrition())); - put("saturation", String.valueOf(foodProperties.saturation())); - } - if (item.equals(Items.CAKE)) { - put("nutrition", "2"); - put("saturation", "0.1"); + if (!Services.PLATFORM.isModLoaded("nostalgic_tweaks")) { + if (foodProperties != null) { + put("nutrition", String.valueOf(foodProperties.nutrition())); + put("saturation", String.valueOf(foodProperties.saturation())); + } + if (item.equals(Items.CAKE)) { + put("nutrition", "2"); + put("saturation", "0.1"); + } } if (item.equals(Items.POTION) || item.equals(Items.SPLASH_POTION) || diff --git a/common/src/main/java/uk/debb/vanilla_disable/mixin/feature/entity/other/MixinDragonStrafePlayerPhase.java b/common/src/main/java/uk/debb/vanilla_disable/mixin/feature/entity/other/MixinDragonStrafePlayerPhase.java index 2aeea364..d469a8a6 100644 --- a/common/src/main/java/uk/debb/vanilla_disable/mixin/feature/entity/other/MixinDragonStrafePlayerPhase.java +++ b/common/src/main/java/uk/debb/vanilla_disable/mixin/feature/entity/other/MixinDragonStrafePlayerPhase.java @@ -6,7 +6,7 @@ package uk.debb.vanilla_disable.mixin.feature.entity.other; - import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.boss.enderdragon.phases.DragonStrafePlayerPhase; import net.minecraft.world.level.Level; diff --git a/common/src/main/java/uk/debb/vanilla_disable/mixin/feature/entity/other/MixinServerPlayer.java b/common/src/main/java/uk/debb/vanilla_disable/mixin/feature/entity/other/MixinServerPlayer.java index aa7d77ee..dbeac01d 100644 --- a/common/src/main/java/uk/debb/vanilla_disable/mixin/feature/entity/other/MixinServerPlayer.java +++ b/common/src/main/java/uk/debb/vanilla_disable/mixin/feature/entity/other/MixinServerPlayer.java @@ -25,7 +25,7 @@ public abstract class MixinServerPlayer { @WrapMethod(method = "awardStat") private void vanillaDisable$awardStat(Stat stat, int increment, Operation original) { if (stat.getType().equals(Stats.CUSTOM) && !SqlManager.getBoolean("entities", "minecraft:player", - DataUtils.lightCleanup(stat.getName().split(":")[1].replace(".", ":")) + "_custom_stat")) { + DataUtils.lightCleanup(stat.getName().split(":")[1].replace(".", ":")) + "_custom_stat")) { return; } else if (!SqlManager.getBoolean("entities", "minecraft:player", DataUtils.lightCleanup(Objects.requireNonNull(DataDefinitions.statTypeRegistry.getKey(stat.getType()))) + "_stat_type")) { diff --git a/common/src/main/java/uk/debb/vanilla_disable/mixin/plugin/MixinPluginConfig.java b/common/src/main/java/uk/debb/vanilla_disable/mixin/plugin/MixinPluginConfig.java index 36271d1b..b1c6de58 100644 --- a/common/src/main/java/uk/debb/vanilla_disable/mixin/plugin/MixinPluginConfig.java +++ b/common/src/main/java/uk/debb/vanilla_disable/mixin/plugin/MixinPluginConfig.java @@ -6,7 +6,10 @@ package uk.debb.vanilla_disable.mixin.plugin; +import it.unimi.dsi.fastutil.objects.Object2ObjectMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import uk.debb.vanilla_disable.Constants; +import uk.debb.vanilla_disable.platform.Services; import java.io.*; import java.nio.file.Paths; @@ -14,6 +17,9 @@ public class MixinPluginConfig { public final Properties properties; + public final Object2ObjectMap compatibility = new Object2ObjectOpenHashMap<>() {{ + put("mixin.feature.item.food", "nostalgic_tweaks"); + }}; private final File configDirectory; private final File configFile; @@ -51,10 +57,13 @@ private void loadConfigFile() { } public boolean isMixinConfigured(String mixinName) { - return properties.containsKey(mixinName); + return properties.containsKey(mixinName) || compatibility.containsKey(mixinName); } public boolean isMixinEnabled(String mixinName) { + if (compatibility.containsKey(mixinName) && Services.PLATFORM.isModLoaded(compatibility.get(mixinName))) { + return false; + } return !properties.getProperty(mixinName, "true").equals("false"); } } \ No newline at end of file diff --git a/common/src/main/java/uk/debb/vanilla_disable/mixin/plugin/VanillaDisableMixinPlugin.java b/common/src/main/java/uk/debb/vanilla_disable/mixin/plugin/VanillaDisableMixinPlugin.java index cdc13ca5..befb8ec1 100644 --- a/common/src/main/java/uk/debb/vanilla_disable/mixin/plugin/VanillaDisableMixinPlugin.java +++ b/common/src/main/java/uk/debb/vanilla_disable/mixin/plugin/VanillaDisableMixinPlugin.java @@ -10,6 +10,7 @@ import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; import uk.debb.vanilla_disable.Constants; +import uk.debb.vanilla_disable.platform.Services; import java.util.List; import java.util.Set; @@ -22,6 +23,11 @@ public void onLoad(String s) { if (config == null) { config = new MixinPluginConfig(); Constants.LOG.info("Loaded VanillaDisable mixin config file with {} override(s).", config.properties.size()); + config.compatibility.forEach((mixin, mod) -> { + if (Services.PLATFORM.isModLoaded(mod)) { + Constants.LOG.warn("Disabled {} due to compatibility with {}.", mixin, mod); + } + }); } } diff --git a/common/src/main/java/uk/debb/vanilla_disable/platform/Services.java b/common/src/main/java/uk/debb/vanilla_disable/platform/Services.java new file mode 100644 index 00000000..bf92da01 --- /dev/null +++ b/common/src/main/java/uk/debb/vanilla_disable/platform/Services.java @@ -0,0 +1,18 @@ +package uk.debb.vanilla_disable.platform; + +import uk.debb.vanilla_disable.Constants; +import uk.debb.vanilla_disable.platform.services.IPlatformHelper; + +import java.util.ServiceLoader; + +public class Services { + public static final IPlatformHelper PLATFORM = load(IPlatformHelper.class); + + public static T load(Class clazz) { + final T loadedService = ServiceLoader.load(clazz) + .findFirst() + .orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName())); + Constants.LOG.debug("Loaded {} for service {}", loadedService, clazz); + return loadedService; + } +} diff --git a/common/src/main/java/uk/debb/vanilla_disable/platform/services/IPlatformHelper.java b/common/src/main/java/uk/debb/vanilla_disable/platform/services/IPlatformHelper.java new file mode 100644 index 00000000..ec005ef4 --- /dev/null +++ b/common/src/main/java/uk/debb/vanilla_disable/platform/services/IPlatformHelper.java @@ -0,0 +1,5 @@ +package uk.debb.vanilla_disable.platform.services; + +public interface IPlatformHelper { + boolean isModLoaded(String modId); +} diff --git a/fabric/src/main/java/uk/debb/vanilla_disable/platform/FabricPlatformHelper.java b/fabric/src/main/java/uk/debb/vanilla_disable/platform/FabricPlatformHelper.java new file mode 100644 index 00000000..86073faf --- /dev/null +++ b/fabric/src/main/java/uk/debb/vanilla_disable/platform/FabricPlatformHelper.java @@ -0,0 +1,11 @@ +package uk.debb.vanilla_disable.platform; + +import net.fabricmc.loader.api.FabricLoader; +import uk.debb.vanilla_disable.platform.services.IPlatformHelper; + +public class FabricPlatformHelper implements IPlatformHelper { + @Override + public boolean isModLoaded(String modId) { + return FabricLoader.getInstance().isModLoaded(modId); + } +} diff --git a/fabric/src/main/resources/META-INF/services/uk.debb.vanilla_disable.platform.services.IPlatformHelper b/fabric/src/main/resources/META-INF/services/uk.debb.vanilla_disable.platform.services.IPlatformHelper new file mode 100644 index 00000000..5a9f5e6e --- /dev/null +++ b/fabric/src/main/resources/META-INF/services/uk.debb.vanilla_disable.platform.services.IPlatformHelper @@ -0,0 +1 @@ +uk.debb.vanilla_disable.platform.FabricPlatformHelper \ No newline at end of file diff --git a/neoforge/src/main/java/uk/debb/vanilla_disable/platform/NeoForgePlatformHelper.java b/neoforge/src/main/java/uk/debb/vanilla_disable/platform/NeoForgePlatformHelper.java new file mode 100644 index 00000000..9547bd53 --- /dev/null +++ b/neoforge/src/main/java/uk/debb/vanilla_disable/platform/NeoForgePlatformHelper.java @@ -0,0 +1,13 @@ +package uk.debb.vanilla_disable.platform; + +import net.neoforged.fml.loading.LoadingModList; +import uk.debb.vanilla_disable.platform.services.IPlatformHelper; + +import java.util.Optional; + +public class NeoForgePlatformHelper implements IPlatformHelper { + @Override + public boolean isModLoaded(String modId) { + return Optional.ofNullable(LoadingModList.get()).map(ml -> ml.getModFileById(modId)).isPresent(); + } +} diff --git a/neoforge/src/main/resources/META-INF/services/uk.debb.vanilla_disable.platform.services.IPlatformHelper b/neoforge/src/main/resources/META-INF/services/uk.debb.vanilla_disable.platform.services.IPlatformHelper new file mode 100644 index 00000000..7b913e0d --- /dev/null +++ b/neoforge/src/main/resources/META-INF/services/uk.debb.vanilla_disable.platform.services.IPlatformHelper @@ -0,0 +1 @@ +uk.debb.vanilla_disable.platform.NeoForgePlatformHelper \ No newline at end of file