diff --git a/src/main/java/cc/unilock/legacyfixes/LegacyFixesConfig.java b/src/main/java/cc/unilock/legacyfixes/LegacyFixesConfig.java index 0b368ab..20e8e2e 100644 --- a/src/main/java/cc/unilock/legacyfixes/LegacyFixesConfig.java +++ b/src/main/java/cc/unilock/legacyfixes/LegacyFixesConfig.java @@ -9,6 +9,7 @@ public class LegacyFixesConfig { public static boolean bedSpawnFix = true; public static boolean chatLinebreakFix = false; public static boolean doubleDoors = true; + public static boolean hungerless = false; public static boolean jumpClimbing = true; public static boolean keepXP = false; public static boolean mc5694Fix = true; @@ -25,6 +26,7 @@ public static void synchronizeConfiguration(File configFile) { bedSpawnFix = configuration.getBoolean("bedSpawnFix", Configuration.CATEGORY_GENERAL, bedSpawnFix, "Allows beds to set a player's spawn point during the day (as in 1.15+)"); chatLinebreakFix = configuration.getBoolean("chatLinebreakFix", Configuration.CATEGORY_GENERAL, chatLinebreakFix, "Fixes line breaks in chat not rendering properly, but breaks certain formatting in fixed chat messages"); doubleDoors = configuration.getBoolean("doubleDoors", Configuration.CATEGORY_GENERAL, doubleDoors, "Makes double doors open simultaneously"); + hungerless = configuration.getBoolean("hungerless", Configuration.CATEGORY_GENERAL, hungerless, "Makes the hunger system always act as if the difficulty is set to Peaceful"); jumpClimbing = configuration.getBoolean("jumpClimbing", Configuration.CATEGORY_GENERAL, jumpClimbing, "Allows climbing ladders by jumping (incompat with slideClimbing)"); keepXP = configuration.getBoolean("keepXP", Configuration.CATEGORY_GENERAL, keepXP, "Players keep their experience level / points on death"); mc5694Fix = configuration.getBoolean("mc5694Fix", Configuration.CATEGORY_GENERAL, mc5694Fix, "Try to fix MC-5694 (\"High efficiency tools / fast mining destroys some blocks client-side only\")"); diff --git a/src/main/java/cc/unilock/legacyfixes/mixin/FoodStatsMixin.java b/src/main/java/cc/unilock/legacyfixes/mixin/FoodStatsMixin.java new file mode 100644 index 0000000..9fc66ff --- /dev/null +++ b/src/main/java/cc/unilock/legacyfixes/mixin/FoodStatsMixin.java @@ -0,0 +1,17 @@ +package cc.unilock.legacyfixes.mixin; + +import cc.unilock.legacyfixes.LegacyFixesConfig; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import net.minecraft.util.FoodStats; +import net.minecraft.world.EnumDifficulty; +import org.objectweb.asm.Opcodes; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(FoodStats.class) +public class FoodStatsMixin { + @ModifyExpressionValue(method = "Lnet/minecraft/util/FoodStats;onUpdate(Lnet/minecraft/entity/player/EntityPlayer;)V", at = @At(value = "FIELD", target = "Lnet/minecraft/world/World;difficultySetting:Lnet/minecraft/world/EnumDifficulty;", opcode = Opcodes.GETFIELD)) + private EnumDifficulty legacyfixes$difficultySetting(EnumDifficulty original) { + return LegacyFixesConfig.hungerless ? EnumDifficulty.PEACEFUL : original; + } +} diff --git a/src/main/resources/mixins.legacyfixes.json b/src/main/resources/mixins.legacyfixes.json index 47ae7be..0c3893e 100644 --- a/src/main/resources/mixins.legacyfixes.json +++ b/src/main/resources/mixins.legacyfixes.json @@ -10,6 +10,7 @@ "BlockFarmlandMixin", "EntityLivingBaseMixin", "EntityPlayerMixin", + "FoodStatsMixin", "ItemInWorldManagerMixin", "accessor.EntityPlayerAccessor" ],