diff --git a/dependencies.gradle b/dependencies.gradle index 4b127ab..8eb8884 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -34,5 +34,5 @@ * For more details, see https://docs.gradle.org/8.0.1/userguide/java_library_plugin.html#sec:java_library_configurations_graph */ dependencies { - + implementation("com.github.GTNewHorizons:GTNHLib:0.5.18:dev") } diff --git a/gradle.properties b/gradle.properties index a9ebeb6..99395f7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -93,7 +93,7 @@ mixinsPackage = mixin # Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin! # This parameter is for legacy compatibility only # Example value: (coreModClass = asm.FMLPlugin) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.asm.FMLPlugin -coreModClass = +coreModClass = EarlyMixinLoader # If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class # that is annotated with @Mod) you want this to be true. When in doubt: leave it on false! diff --git a/src/main/java/cc/unilock/legacyfixes/EarlyMixinLoader.java b/src/main/java/cc/unilock/legacyfixes/EarlyMixinLoader.java new file mode 100644 index 0000000..e958e62 --- /dev/null +++ b/src/main/java/cc/unilock/legacyfixes/EarlyMixinLoader.java @@ -0,0 +1,118 @@ +package cc.unilock.legacyfixes; + +import com.gtnewhorizon.gtnhlib.config.ConfigException; +import com.gtnewhorizon.gtnhlib.config.ConfigurationManager; +import com.gtnewhorizon.gtnhmixins.IEarlyMixinLoader; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.relauncher.FMLLaunchHandler; +import cpw.mods.fml.relauncher.IFMLLoadingPlugin; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +@IFMLLoadingPlugin.MCVersion("1.7.10") +public class EarlyMixinLoader implements IFMLLoadingPlugin, IEarlyMixinLoader { + static { + try { + ConfigurationManager.registerConfig(LegacyFixesConfig.class); + } catch (ConfigException e) { + throw new RuntimeException(e); + } + } + + @Override + public String getMixinConfig() { + return "mixins.legacyfixes.early.json"; + } + + @Override + public List getMixins(Set loadedCoreMods) { + List mixins = new ArrayList<>(); + + if (LegacyFixesConfig.apatheticMobs) { + mixins.add("apatheticMobs.EntityAITargetMixin"); + mixins.add("apatheticMobs.EntityCreatureMixin"); + } + if (LegacyFixesConfig.bedSpawnFix) { + mixins.add("bedSpawnFix.BlockBedMixin"); + mixins.add("bedSpawnFix.EntityPlayerAccessor"); + } + if (LegacyFixesConfig.hungerless) { + if (Loader.isModLoaded("AppleCore")) { + LegacyFixes.LOGGER.error("LegacyFixes failed to enable hungerless with AppleCore installed!"); + } else { + mixins.add("hungerless.FoodStatsMixin"); + } + } + if (LegacyFixesConfig.jumpClimbing) { + if (LegacyFixesConfig.slideClimbing) { + LegacyFixes.LOGGER.error("LegacyFixes failed to enable jumpClimbing with slideClimbing enabled!"); + } else { + mixins.add("jumpClimbing.EntityLivingBaseMixin"); + } + } + if (LegacyFixesConfig.keepXP) { + mixins.add("keepXP.EntityLivingBaseMixin"); + mixins.add("keepXP.EntityPlayerMixin"); + } + if (LegacyFixesConfig.mc5694Fix) { + mixins.add("mc5694Fix.ItemInWorldManagerMixin"); + } + if (LegacyFixesConfig.noTrample) { + mixins.add("noTrample.BlockFarmlandMixin"); + } + if (LegacyFixesConfig.slideClimbing) { + if (LegacyFixesConfig.jumpClimbing) { + LegacyFixes.LOGGER.error("LegacyFixes failed to enable slideClimbing with jumpClimbing enabled!"); + } else { + mixins.add("slideClimbing.EntityLivingBaseMixin"); + } + } + + if (FMLLaunchHandler.side().isClient()) { + if (LegacyFixesConfig.chatLinebreakFix) { + mixins.add("client.chatLinebreakFix.GuiNewChatMixin"); + } + if (LegacyFixesConfig.nnbspFix) { + mixins.add("client.nnbspFix.FontRendererMixin"); + } + if (LegacyFixesConfig.rmbClear) { + mixins.add("client.rmbClear.GuiTextFieldMixin"); + } + if (LegacyFixesConfig.sortedEnchantments) { + mixins.add("client.sortedEnchantments.ItemEnchantedBookMixin"); + mixins.add("client.sortedEnchantments.ItemStackMixin"); + mixins.add("client.sortedEnchantments.NBTTagListAccessor"); + } + } + + return mixins; + } + + @Override + public String[] getASMTransformerClass() { + return null; + } + + @Override + public String getModContainerClass() { + return null; + } + + @Override + public String getSetupClass() { + return null; + } + + @Override + public void injectData(Map data) { + // NO-OP + } + + @Override + public String getAccessTransformerClass() { + return null; + } +} diff --git a/src/main/java/cc/unilock/legacyfixes/LegacyFixes.java b/src/main/java/cc/unilock/legacyfixes/LegacyFixes.java index caf2821..17bc3e6 100644 --- a/src/main/java/cc/unilock/legacyfixes/LegacyFixes.java +++ b/src/main/java/cc/unilock/legacyfixes/LegacyFixes.java @@ -7,7 +7,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -@Mod(modid = "legacyfixes", version = Tags.VERSION, name = "LegacyFixes", acceptedMinecraftVersions = "[1.7.10]") +@Mod(modid = "legacyfixes", version = Tags.VERSION, name = "LegacyFixes", dependencies = "required-after:gtnhlib@[0.2.0,);") public class LegacyFixes { public static final Logger LOGGER = LogManager.getLogger("LegacyFixes"); diff --git a/src/main/java/cc/unilock/legacyfixes/LegacyFixesConfig.java b/src/main/java/cc/unilock/legacyfixes/LegacyFixesConfig.java index 970399f..21f0687 100644 --- a/src/main/java/cc/unilock/legacyfixes/LegacyFixesConfig.java +++ b/src/main/java/cc/unilock/legacyfixes/LegacyFixesConfig.java @@ -1,43 +1,59 @@ package cc.unilock.legacyfixes; -import net.minecraftforge.common.config.Configuration; - -import java.io.File; +import com.gtnewhorizon.gtnhlib.config.Config; +@Config(modid = "legacyfixes") +@Config.RequiresMcRestart public class LegacyFixesConfig { - public static boolean apatheticMobs = false; - 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; - public static boolean nnbspFix = true; - public static boolean noTrample = false; - public static boolean rmbClear = true; - public static boolean slideClimbing = false; - public static boolean sortedEnchantments = true; - - public static void synchronizeConfiguration(File configFile) { - Configuration configuration = new Configuration(configFile); - - apatheticMobs = configuration.getBoolean("apatheticMobs", Configuration.CATEGORY_GENERAL, apatheticMobs, "Prevents mobs from attacking / targeting players"); - 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 (incompat with AppleCore)"); - 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\")"); - noTrample = configuration.getBoolean("noTrample", Configuration.CATEGORY_GENERAL, noTrample, "Prevents trampling farmland (completely)"); - nnbspFix = configuration.getBoolean("nnbspFix", Configuration.CATEGORY_GENERAL, nnbspFix, "Fixes the \"NNBSP\" character in DateFormat outputs in Java 20+, as in the singleplayer world selection menu"); - rmbClear = configuration.getBoolean("rmbClear", Configuration.CATEGORY_GENERAL, rmbClear, "Allows clearing text fields by right-clicking them"); - slideClimbing = configuration.getBoolean("slideClimbing", Configuration.CATEGORY_GENERAL, slideClimbing, "Allows traversing ladders by looking up or down (incompat with jumpClimbing)"); - sortedEnchantments = configuration.getBoolean("sortedEnchantments", Configuration.CATEGORY_GENERAL, sortedEnchantments, "Sorts enchantments in item tooltips (alphabetically)"); - - if (configuration.hasChanged()) { - configuration.save(); - } - } + @Config.Comment("Prevents mobs from attacking / targeting players") + @Config.DefaultBoolean(false) + public static boolean apatheticMobs; + + @Config.Comment("Allows beds to set a player's spawn point during the day (as in 1.15+)") + @Config.DefaultBoolean(true) + public static boolean bedSpawnFix; + + @Config.Comment("Fixes line breaks in chat not rendering properly, but breaks certain formatting in fixed chat messages") + @Config.DefaultBoolean(false) + public static boolean chatLinebreakFix; + + @Config.Comment("Makes double doors open simultaneously") + @Config.DefaultBoolean(true) + public static boolean doubleDoors; + + @Config.Comment("Makes the hunger system always act as if the difficulty is set to Peaceful (incompat with AppleCore)") + @Config.DefaultBoolean(false) + public static boolean hungerless; + + @Config.Comment("Allows climbing ladders by jumping (incompat with slideClimbing)") + @Config.DefaultBoolean(true) + public static boolean jumpClimbing; + + @Config.Comment("Players keep their experience level / points on death") + @Config.DefaultBoolean(false) + public static boolean keepXP; + + @Config.Comment("Try to fix MC-5694 (\"High efficiency tools / fast mining destroys some blocks client-side only\")") + @Config.DefaultBoolean(true) + public static boolean mc5694Fix; + + @Config.Comment("Fixes the \"NNBSP\" character in DateFormat outputs in Java 20+, as in the singleplayer world selection menu") + @Config.DefaultBoolean(true) + public static boolean nnbspFix; + + @Config.Comment("Prevents trampling farmland (completely)") + @Config.DefaultBoolean(false) + public static boolean noTrample; + + @Config.Comment("Allows clearing text fields by right-clicking them") + @Config.DefaultBoolean(true) + public static boolean rmbClear; + + @Config.Comment("Allows traversing ladders by looking up or down (incompat with jumpClimbing)") + @Config.DefaultBoolean(false) + public static boolean slideClimbing; + + @Config.Comment("Sorts enchantments in item tooltips (alphabetically)") + @Config.DefaultBoolean(true) + public static boolean sortedEnchantments; } diff --git a/src/main/java/cc/unilock/legacyfixes/mixin/EntityLivingBaseMixin.java b/src/main/java/cc/unilock/legacyfixes/mixin/EntityLivingBaseMixin.java deleted file mode 100644 index b53d6cd..0000000 --- a/src/main/java/cc/unilock/legacyfixes/mixin/EntityLivingBaseMixin.java +++ /dev/null @@ -1,87 +0,0 @@ -package cc.unilock.legacyfixes.mixin; - -import cc.unilock.legacyfixes.LegacyFixesConfig; -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import org.objectweb.asm.Opcodes; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(EntityLivingBase.class) -public abstract class EntityLivingBaseMixin { - @Shadow - protected boolean isJumping; - - @Shadow - protected abstract boolean isPlayer(); - - @Unique - private final EntityLivingBase INSTANCE = (EntityLivingBase) (Object) this; - - @Inject(method = "Lnet/minecraft/entity/EntityLivingBase;moveEntityWithHeading(FF)V", at = @At("TAIL")) - private void legacyFixes$moveEntityWithHeading(float moveStrafing, float moveForward, CallbackInfo ci) { - if (LegacyFixesConfig.slideClimbing && !INSTANCE.isInWater() && !INSTANCE.handleLavaMovement() && INSTANCE.isOnLadder() && !INSTANCE.isSneaking() && this.isPlayer()) { - if (INSTANCE.moveForward == 0) { // Not moving? - if (INSTANCE.rotationPitch < 0) { // Looking up? - INSTANCE.motionY = this.legacyfixes$calculateSpeed(INSTANCE.rotationPitch); - } else if (INSTANCE.rotationPitch > 0) { // Looking down? - INSTANCE.motionY = this.legacyfixes$calculateSpeed(INSTANCE.rotationPitch) * -1.0; - } - } - } - } - - @WrapOperation(method = "Lnet/minecraft/entity/EntityLivingBase;moveEntityWithHeading(FF)V", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/EntityLivingBase;isCollidedHorizontally:Z", opcode = Opcodes.GETFIELD, ordinal = 2)) - private boolean legacyfixes$isCollidedHorizontally(EntityLivingBase instance, Operation original) { - return original.call(instance) || (LegacyFixesConfig.jumpClimbing && this.isJumping); - } - - @WrapOperation(method = "Lnet/minecraft/entity/EntityLivingBase;moveEntityWithHeading(FF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityLivingBase;isOnLadder()Z")) - private boolean legacyfixes$isOnLadder(EntityLivingBase instance, Operation original) { - if (original.call(instance)) { - if (!LegacyFixesConfig.slideClimbing) return true; - - if (instance.motionX < -0.15) { - instance.motionX = -0.15; - } - - if (instance.motionX > 0.15) { - instance.motionX = 0.15; - } - - if (instance.motionZ < -0.15) { - instance.motionZ = -0.15; - } - - if (instance.motionZ > 0.15) { - instance.motionZ = 0.15; - } - - instance.fallDistance = 0.0F; - - if (instance.isSneaking() && this.isPlayer() && instance.motionY < 0.0D) { - instance.motionY = 0.0; - } - - return instance.moveForward != 0; - } - - return false; - } - - @WrapOperation(method = "Lnet/minecraft/entity/EntityLivingBase;onDeathUpdate()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityLivingBase;getExperiencePoints(Lnet/minecraft/entity/player/EntityPlayer;)I")) - private int legacyfixes$getExperiencePoints(EntityLivingBase instance, EntityPlayer p_70693_1_, Operation original) { - return (LegacyFixesConfig.keepXP && this.isPlayer()) ? 0 : original.call(instance, p_70693_1_); - } - - @Unique - private double legacyfixes$calculateSpeed(float pitch) { - return Math.abs(pitch / 90.0) * 0.4; - } -} diff --git a/src/main/java/cc/unilock/legacyfixes/mixin/EntityAITargetMixin.java b/src/main/java/cc/unilock/legacyfixes/mixin/early/apatheticMobs/EntityAITargetMixin.java similarity index 91% rename from src/main/java/cc/unilock/legacyfixes/mixin/EntityAITargetMixin.java rename to src/main/java/cc/unilock/legacyfixes/mixin/early/apatheticMobs/EntityAITargetMixin.java index 86e189e..bcd61d6 100644 --- a/src/main/java/cc/unilock/legacyfixes/mixin/EntityAITargetMixin.java +++ b/src/main/java/cc/unilock/legacyfixes/mixin/early/apatheticMobs/EntityAITargetMixin.java @@ -1,4 +1,4 @@ -package cc.unilock.legacyfixes.mixin; +package cc.unilock.legacyfixes.mixin.early.apatheticMobs; import cc.unilock.legacyfixes.LegacyFixesConfig; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; diff --git a/src/main/java/cc/unilock/legacyfixes/mixin/EntityCreatureMixin.java b/src/main/java/cc/unilock/legacyfixes/mixin/early/apatheticMobs/EntityCreatureMixin.java similarity index 91% rename from src/main/java/cc/unilock/legacyfixes/mixin/EntityCreatureMixin.java rename to src/main/java/cc/unilock/legacyfixes/mixin/early/apatheticMobs/EntityCreatureMixin.java index a089691..32e7017 100644 --- a/src/main/java/cc/unilock/legacyfixes/mixin/EntityCreatureMixin.java +++ b/src/main/java/cc/unilock/legacyfixes/mixin/early/apatheticMobs/EntityCreatureMixin.java @@ -1,4 +1,4 @@ -package cc.unilock.legacyfixes.mixin; +package cc.unilock.legacyfixes.mixin.early.apatheticMobs; import cc.unilock.legacyfixes.LegacyFixesConfig; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; diff --git a/src/main/java/cc/unilock/legacyfixes/mixin/BlockBedMixin.java b/src/main/java/cc/unilock/legacyfixes/mixin/early/bedSpawnFix/BlockBedMixin.java similarity index 93% rename from src/main/java/cc/unilock/legacyfixes/mixin/BlockBedMixin.java rename to src/main/java/cc/unilock/legacyfixes/mixin/early/bedSpawnFix/BlockBedMixin.java index 8c67040..c55e195 100644 --- a/src/main/java/cc/unilock/legacyfixes/mixin/BlockBedMixin.java +++ b/src/main/java/cc/unilock/legacyfixes/mixin/early/bedSpawnFix/BlockBedMixin.java @@ -1,7 +1,6 @@ -package cc.unilock.legacyfixes.mixin; +package cc.unilock.legacyfixes.mixin.early.bedSpawnFix; import cc.unilock.legacyfixes.LegacyFixesConfig; -import cc.unilock.legacyfixes.mixin.accessor.EntityPlayerAccessor; import net.minecraft.block.BlockBed; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ChatComponentTranslation; diff --git a/src/main/java/cc/unilock/legacyfixes/mixin/accessor/EntityPlayerAccessor.java b/src/main/java/cc/unilock/legacyfixes/mixin/early/bedSpawnFix/EntityPlayerAccessor.java similarity index 84% rename from src/main/java/cc/unilock/legacyfixes/mixin/accessor/EntityPlayerAccessor.java rename to src/main/java/cc/unilock/legacyfixes/mixin/early/bedSpawnFix/EntityPlayerAccessor.java index 4f4f3c0..909c16c 100644 --- a/src/main/java/cc/unilock/legacyfixes/mixin/accessor/EntityPlayerAccessor.java +++ b/src/main/java/cc/unilock/legacyfixes/mixin/early/bedSpawnFix/EntityPlayerAccessor.java @@ -1,4 +1,4 @@ -package cc.unilock.legacyfixes.mixin.accessor; +package cc.unilock.legacyfixes.mixin.early.bedSpawnFix; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ChunkCoordinates; diff --git a/src/main/java/cc/unilock/legacyfixes/mixin/client/GuiNewChatMixin.java b/src/main/java/cc/unilock/legacyfixes/mixin/early/client/chatLinebreakFix/GuiNewChatMixin.java similarity index 94% rename from src/main/java/cc/unilock/legacyfixes/mixin/client/GuiNewChatMixin.java rename to src/main/java/cc/unilock/legacyfixes/mixin/early/client/chatLinebreakFix/GuiNewChatMixin.java index 26019ea..9783d8e 100644 --- a/src/main/java/cc/unilock/legacyfixes/mixin/client/GuiNewChatMixin.java +++ b/src/main/java/cc/unilock/legacyfixes/mixin/early/client/chatLinebreakFix/GuiNewChatMixin.java @@ -1,4 +1,4 @@ -package cc.unilock.legacyfixes.mixin.client; +package cc.unilock.legacyfixes.mixin.early.client.chatLinebreakFix; import cc.unilock.legacyfixes.LegacyFixesConfig; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; diff --git a/src/main/java/cc/unilock/legacyfixes/mixin/client/FontRendererMixin.java b/src/main/java/cc/unilock/legacyfixes/mixin/early/client/nnbspFix/FontRendererMixin.java similarity index 92% rename from src/main/java/cc/unilock/legacyfixes/mixin/client/FontRendererMixin.java rename to src/main/java/cc/unilock/legacyfixes/mixin/early/client/nnbspFix/FontRendererMixin.java index 8933625..a197c3f 100644 --- a/src/main/java/cc/unilock/legacyfixes/mixin/client/FontRendererMixin.java +++ b/src/main/java/cc/unilock/legacyfixes/mixin/early/client/nnbspFix/FontRendererMixin.java @@ -1,4 +1,4 @@ -package cc.unilock.legacyfixes.mixin.client; +package cc.unilock.legacyfixes.mixin.early.client.nnbspFix; import cc.unilock.legacyfixes.LegacyFixesConfig; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; diff --git a/src/main/java/cc/unilock/legacyfixes/mixin/client/GuiTextFieldMixin.java b/src/main/java/cc/unilock/legacyfixes/mixin/early/client/rmbClear/GuiTextFieldMixin.java similarity index 95% rename from src/main/java/cc/unilock/legacyfixes/mixin/client/GuiTextFieldMixin.java rename to src/main/java/cc/unilock/legacyfixes/mixin/early/client/rmbClear/GuiTextFieldMixin.java index 99b18a7..6858e3f 100644 --- a/src/main/java/cc/unilock/legacyfixes/mixin/client/GuiTextFieldMixin.java +++ b/src/main/java/cc/unilock/legacyfixes/mixin/early/client/rmbClear/GuiTextFieldMixin.java @@ -1,4 +1,4 @@ -package cc.unilock.legacyfixes.mixin.client; +package cc.unilock.legacyfixes.mixin.early.client.rmbClear; import cc.unilock.legacyfixes.LegacyFixesConfig; import net.minecraft.client.gui.GuiTextField; diff --git a/src/main/java/cc/unilock/legacyfixes/mixin/client/ItemEnchantedBookMixin.java b/src/main/java/cc/unilock/legacyfixes/mixin/early/client/sortedEnchantments/ItemEnchantedBookMixin.java similarity index 93% rename from src/main/java/cc/unilock/legacyfixes/mixin/client/ItemEnchantedBookMixin.java rename to src/main/java/cc/unilock/legacyfixes/mixin/early/client/sortedEnchantments/ItemEnchantedBookMixin.java index f228520..3cf4b13 100644 --- a/src/main/java/cc/unilock/legacyfixes/mixin/client/ItemEnchantedBookMixin.java +++ b/src/main/java/cc/unilock/legacyfixes/mixin/early/client/sortedEnchantments/ItemEnchantedBookMixin.java @@ -1,4 +1,4 @@ -package cc.unilock.legacyfixes.mixin.client; +package cc.unilock.legacyfixes.mixin.early.client.sortedEnchantments; import cc.unilock.legacyfixes.LegacyFixesConfig; import cc.unilock.legacyfixes.util.NBTUtils; diff --git a/src/main/java/cc/unilock/legacyfixes/mixin/client/ItemStackMixin.java b/src/main/java/cc/unilock/legacyfixes/mixin/early/client/sortedEnchantments/ItemStackMixin.java similarity index 92% rename from src/main/java/cc/unilock/legacyfixes/mixin/client/ItemStackMixin.java rename to src/main/java/cc/unilock/legacyfixes/mixin/early/client/sortedEnchantments/ItemStackMixin.java index 642a797..a28e168 100644 --- a/src/main/java/cc/unilock/legacyfixes/mixin/client/ItemStackMixin.java +++ b/src/main/java/cc/unilock/legacyfixes/mixin/early/client/sortedEnchantments/ItemStackMixin.java @@ -1,4 +1,4 @@ -package cc.unilock.legacyfixes.mixin.client; +package cc.unilock.legacyfixes.mixin.early.client.sortedEnchantments; import cc.unilock.legacyfixes.LegacyFixesConfig; import cc.unilock.legacyfixes.util.NBTUtils; diff --git a/src/main/java/cc/unilock/legacyfixes/mixin/client/accessor/NBTTagListAccessor.java b/src/main/java/cc/unilock/legacyfixes/mixin/early/client/sortedEnchantments/NBTTagListAccessor.java similarity index 81% rename from src/main/java/cc/unilock/legacyfixes/mixin/client/accessor/NBTTagListAccessor.java rename to src/main/java/cc/unilock/legacyfixes/mixin/early/client/sortedEnchantments/NBTTagListAccessor.java index 9349a47..f0d5b94 100644 --- a/src/main/java/cc/unilock/legacyfixes/mixin/client/accessor/NBTTagListAccessor.java +++ b/src/main/java/cc/unilock/legacyfixes/mixin/early/client/sortedEnchantments/NBTTagListAccessor.java @@ -1,4 +1,4 @@ -package cc.unilock.legacyfixes.mixin.client.accessor; +package cc.unilock.legacyfixes.mixin.early.client.sortedEnchantments; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagList; diff --git a/src/main/java/cc/unilock/legacyfixes/mixin/FoodStatsMixin.java b/src/main/java/cc/unilock/legacyfixes/mixin/early/hungerless/FoodStatsMixin.java similarity index 93% rename from src/main/java/cc/unilock/legacyfixes/mixin/FoodStatsMixin.java rename to src/main/java/cc/unilock/legacyfixes/mixin/early/hungerless/FoodStatsMixin.java index 3a0d342..99a7c31 100644 --- a/src/main/java/cc/unilock/legacyfixes/mixin/FoodStatsMixin.java +++ b/src/main/java/cc/unilock/legacyfixes/mixin/early/hungerless/FoodStatsMixin.java @@ -1,4 +1,4 @@ -package cc.unilock.legacyfixes.mixin; +package cc.unilock.legacyfixes.mixin.early.hungerless; import cc.unilock.legacyfixes.LegacyFixesConfig; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; diff --git a/src/main/java/cc/unilock/legacyfixes/mixin/early/jumpClimbing/EntityLivingBaseMixin.java b/src/main/java/cc/unilock/legacyfixes/mixin/early/jumpClimbing/EntityLivingBaseMixin.java new file mode 100644 index 0000000..0449b32 --- /dev/null +++ b/src/main/java/cc/unilock/legacyfixes/mixin/early/jumpClimbing/EntityLivingBaseMixin.java @@ -0,0 +1,20 @@ +package cc.unilock.legacyfixes.mixin.early.jumpClimbing; + +import cc.unilock.legacyfixes.LegacyFixesConfig; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import net.minecraft.entity.EntityLivingBase; +import org.objectweb.asm.Opcodes; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(EntityLivingBase.class) +public abstract class EntityLivingBaseMixin { + @Shadow + protected boolean isJumping; + + @ModifyExpressionValue(method = "Lnet/minecraft/entity/EntityLivingBase;moveEntityWithHeading(FF)V", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/EntityLivingBase;isCollidedHorizontally:Z", opcode = Opcodes.GETFIELD, ordinal = 2)) + private boolean legacyfixes$isCollidedHorizontally(boolean original) { + return original || (LegacyFixesConfig.jumpClimbing && this.isJumping); + } +} diff --git a/src/main/java/cc/unilock/legacyfixes/mixin/early/keepXP/EntityLivingBaseMixin.java b/src/main/java/cc/unilock/legacyfixes/mixin/early/keepXP/EntityLivingBaseMixin.java new file mode 100644 index 0000000..03761eb --- /dev/null +++ b/src/main/java/cc/unilock/legacyfixes/mixin/early/keepXP/EntityLivingBaseMixin.java @@ -0,0 +1,19 @@ +package cc.unilock.legacyfixes.mixin.early.keepXP; + +import cc.unilock.legacyfixes.LegacyFixesConfig; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import net.minecraft.entity.EntityLivingBase; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(EntityLivingBase.class) +public abstract class EntityLivingBaseMixin { + @Shadow + protected abstract boolean isPlayer(); + + @ModifyExpressionValue(method = "Lnet/minecraft/entity/EntityLivingBase;onDeathUpdate()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityLivingBase;getExperiencePoints(Lnet/minecraft/entity/player/EntityPlayer;)I")) + private int legacyfixes$getExperiencePoints(int original) { + return (LegacyFixesConfig.keepXP && this.isPlayer()) ? 0 : original; + } +} diff --git a/src/main/java/cc/unilock/legacyfixes/mixin/EntityPlayerMixin.java b/src/main/java/cc/unilock/legacyfixes/mixin/early/keepXP/EntityPlayerMixin.java similarity index 95% rename from src/main/java/cc/unilock/legacyfixes/mixin/EntityPlayerMixin.java rename to src/main/java/cc/unilock/legacyfixes/mixin/early/keepXP/EntityPlayerMixin.java index 5a32685..3d23338 100644 --- a/src/main/java/cc/unilock/legacyfixes/mixin/EntityPlayerMixin.java +++ b/src/main/java/cc/unilock/legacyfixes/mixin/early/keepXP/EntityPlayerMixin.java @@ -1,4 +1,4 @@ -package cc.unilock.legacyfixes.mixin; +package cc.unilock.legacyfixes.mixin.early.keepXP; import cc.unilock.legacyfixes.LegacyFixesConfig; import net.minecraft.entity.player.EntityPlayer; diff --git a/src/main/java/cc/unilock/legacyfixes/mixin/ItemInWorldManagerMixin.java b/src/main/java/cc/unilock/legacyfixes/mixin/early/mc5694Fix/ItemInWorldManagerMixin.java similarity index 94% rename from src/main/java/cc/unilock/legacyfixes/mixin/ItemInWorldManagerMixin.java rename to src/main/java/cc/unilock/legacyfixes/mixin/early/mc5694Fix/ItemInWorldManagerMixin.java index 5e21747..6bcd72f 100644 --- a/src/main/java/cc/unilock/legacyfixes/mixin/ItemInWorldManagerMixin.java +++ b/src/main/java/cc/unilock/legacyfixes/mixin/early/mc5694Fix/ItemInWorldManagerMixin.java @@ -1,4 +1,4 @@ -package cc.unilock.legacyfixes.mixin; +package cc.unilock.legacyfixes.mixin.early.mc5694Fix; import cc.unilock.legacyfixes.LegacyFixesConfig; import net.minecraft.network.play.server.S23PacketBlockChange; diff --git a/src/main/java/cc/unilock/legacyfixes/mixin/BlockFarmlandMixin.java b/src/main/java/cc/unilock/legacyfixes/mixin/early/noTrample/BlockFarmlandMixin.java similarity index 93% rename from src/main/java/cc/unilock/legacyfixes/mixin/BlockFarmlandMixin.java rename to src/main/java/cc/unilock/legacyfixes/mixin/early/noTrample/BlockFarmlandMixin.java index 06fe225..a3032e1 100644 --- a/src/main/java/cc/unilock/legacyfixes/mixin/BlockFarmlandMixin.java +++ b/src/main/java/cc/unilock/legacyfixes/mixin/early/noTrample/BlockFarmlandMixin.java @@ -1,4 +1,4 @@ -package cc.unilock.legacyfixes.mixin; +package cc.unilock.legacyfixes.mixin.early.noTrample; import cc.unilock.legacyfixes.LegacyFixesConfig; import net.minecraft.block.BlockFarmland; diff --git a/src/main/java/cc/unilock/legacyfixes/mixin/early/slideClimbing/EntityLivingBaseMixin.java b/src/main/java/cc/unilock/legacyfixes/mixin/early/slideClimbing/EntityLivingBaseMixin.java new file mode 100644 index 0000000..ec6b4e8 --- /dev/null +++ b/src/main/java/cc/unilock/legacyfixes/mixin/early/slideClimbing/EntityLivingBaseMixin.java @@ -0,0 +1,74 @@ +package cc.unilock.legacyfixes.mixin.early.slideClimbing; + +import cc.unilock.legacyfixes.LegacyFixesConfig; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import net.minecraft.entity.EntityLivingBase; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(EntityLivingBase.class) +public abstract class EntityLivingBaseMixin { + @Shadow + protected abstract boolean isPlayer(); + + @Inject(method = "Lnet/minecraft/entity/EntityLivingBase;moveEntityWithHeading(FF)V", at = @At("TAIL")) + private void legacyFixes$moveEntityWithHeading(float moveStrafing, float moveForward, CallbackInfo ci) { + if (LegacyFixesConfig.slideClimbing) { + EntityLivingBase instance = (EntityLivingBase) (Object) this; + + if (!instance.isInWater() && !instance.handleLavaMovement() && instance.isOnLadder() && !instance.isSneaking() && this.isPlayer()) { + if (instance.moveForward == 0) { // Not moving? + if (instance.rotationPitch < 0) { // Looking up? + instance.motionY = this.legacyfixes$calculateSpeed(instance.rotationPitch); + } else if (instance.rotationPitch > 0) { // Looking down? + instance.motionY = this.legacyfixes$calculateSpeed(instance.rotationPitch) * -1.0; + } + } + } + } + } + + @ModifyExpressionValue(method = "Lnet/minecraft/entity/EntityLivingBase;moveEntityWithHeading(FF)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityLivingBase;isOnLadder()Z")) + private boolean legacyfixes$isOnLadder(boolean original) { + if (original) { + if (!LegacyFixesConfig.slideClimbing) return true; + + EntityLivingBase instance = (EntityLivingBase) (Object) this; + + if (instance.motionX < -0.15) { + instance.motionX = -0.15; + } + + if (instance.motionX > 0.15) { + instance.motionX = 0.15; + } + + if (instance.motionZ < -0.15) { + instance.motionZ = -0.15; + } + + if (instance.motionZ > 0.15) { + instance.motionZ = 0.15; + } + + instance.fallDistance = 0.0F; + + if (instance.isSneaking() && this.isPlayer() && instance.motionY < 0.0D) { + instance.motionY = 0.0; + } + + return instance.moveForward != 0; + } + + return false; + } + + @Unique + private double legacyfixes$calculateSpeed(float pitch) { + return Math.abs(pitch / 90.0) * 0.4; + } +} diff --git a/src/main/java/cc/unilock/legacyfixes/proxy/CommonProxy.java b/src/main/java/cc/unilock/legacyfixes/proxy/CommonProxy.java index 11b4d2c..c16c4b9 100644 --- a/src/main/java/cc/unilock/legacyfixes/proxy/CommonProxy.java +++ b/src/main/java/cc/unilock/legacyfixes/proxy/CommonProxy.java @@ -8,8 +8,6 @@ public class CommonProxy { public void preInit(FMLPreInitializationEvent event) { - LegacyFixesConfig.synchronizeConfiguration(event.getSuggestedConfigurationFile()); - if (LegacyFixesConfig.doubleDoors) { MinecraftForge.EVENT_BUS.register(new DoubleDoorsModule()); } diff --git a/src/main/java/cc/unilock/legacyfixes/util/NBTUtils.java b/src/main/java/cc/unilock/legacyfixes/util/NBTUtils.java index 1b30352..18e14c2 100644 --- a/src/main/java/cc/unilock/legacyfixes/util/NBTUtils.java +++ b/src/main/java/cc/unilock/legacyfixes/util/NBTUtils.java @@ -1,6 +1,6 @@ package cc.unilock.legacyfixes.util; -import cc.unilock.legacyfixes.mixin.client.accessor.NBTTagListAccessor; +import cc.unilock.legacyfixes.mixin.early.client.sortedEnchantments.NBTTagListAccessor; import net.minecraft.enchantment.Enchantment; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; diff --git a/src/main/resources/mixins.legacyfixes.early.json b/src/main/resources/mixins.legacyfixes.early.json new file mode 100644 index 0000000..6b5bcd0 --- /dev/null +++ b/src/main/resources/mixins.legacyfixes.early.json @@ -0,0 +1,8 @@ +{ + "required": true, + "minVersion": "0.8.5-GTNH", + "package": "cc.unilock.legacyfixes.mixin.early", + "refmap": "mixins.legacyfixes.refmap.json", + "target": "@env(DEFAULT)", + "compatibilityLevel": "JAVA_8" +} diff --git a/src/main/resources/mixins.legacyfixes.json b/src/main/resources/mixins.legacyfixes.json index eb47f14..66fc146 100644 --- a/src/main/resources/mixins.legacyfixes.json +++ b/src/main/resources/mixins.legacyfixes.json @@ -4,25 +4,5 @@ "package": "cc.unilock.legacyfixes.mixin", "refmap": "mixins.legacyfixes.refmap.json", "target": "@env(DEFAULT)", - "compatibilityLevel": "JAVA_8", - "mixins": [ - "BlockBedMixin", - "BlockFarmlandMixin", - "EntityAITargetMixin", - "EntityCreatureMixin", - "EntityLivingBaseMixin", - "EntityPlayerMixin", - "FoodStatsMixin", - "ItemInWorldManagerMixin", - "accessor.EntityPlayerAccessor" - ], - "client": [ - "client.FontRendererMixin", - "client.GuiNewChatMixin", - "client.GuiTextFieldMixin", - "client.ItemEnchantedBookMixin", - "client.ItemStackMixin", - "client.accessor.NBTTagListAccessor" - ], - "server": [] + "compatibilityLevel": "JAVA_8" }