Skip to content

Commit

Permalink
Disable nutrition/saturation feature when nostalgic tweaks is present
Browse files Browse the repository at this point in the history
  • Loading branch information
DragonEggBedrockBreaking committed Oct 6, 2024
1 parent fd5e364 commit 7a947f0
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")));
}});
}});
Expand Down Expand Up @@ -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) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public abstract class MixinServerPlayer {
@WrapMethod(method = "awardStat")
private void vanillaDisable$awardStat(Stat<?> stat, int increment, Operation<Void> 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")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@

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;
import java.util.Properties;

public class MixinPluginConfig {
public final Properties properties;
public final Object2ObjectMap<String, String> compatibility = new Object2ObjectOpenHashMap<>() {{
put("mixin.feature.item.food", "nostalgic_tweaks");
}};
private final File configDirectory;
private final File configFile;

Expand Down Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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> T load(Class<T> 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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package uk.debb.vanilla_disable.platform.services;

public interface IPlatformHelper {
boolean isModLoaded(String modId);
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uk.debb.vanilla_disable.platform.FabricPlatformHelper
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uk.debb.vanilla_disable.platform.NeoForgePlatformHelper

0 comments on commit 7a947f0

Please sign in to comment.