Skip to content

Commit

Permalink
Keep the inventory centered when the player has potion effects (#100)
Browse files Browse the repository at this point in the history
* Prevents the inventory from shifting when the player has active potion effects - works in dev but not in full pack

* case on method names

* remove faulty mixins that causes crash in full pack

* use a hook for the transformer to make debugging easier if someone looks at class dump

* add todo where code needs to be changed to solved mixin loading wrong jars

* does that fix merge conflict
  • Loading branch information
Alexdoru authored Sep 5, 2022
1 parent f68c01f commit eb6c039
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 4 deletions.
4 changes: 3 additions & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ dependencies {
compile("curse.maven:biomes-o-plenty-220318:2499612")
compileOnly("curse.maven:projecte-226410:2340786")
compileOnly(deobf("https://mediafiles.forgecdn.net/files/2241/397/Pam%27s+Harvest+the+Nether+1.7.10a.jar"))

compileOnly("com.github.GTNewHorizons:Galacticraft:3.0.44-GTNH:dev")
compileOnly("com.github.GTNewHorizons:Baubles:1.0.1.14:dev")
compileOnly fileTree(dir: 'dependencies', includes: ['TravellersGear-1.7.10-1.16.8-GTNH.jar'])

// Thermos Compat, compile only not run in dev by default
compileOnly files("dependencies/Thermos-1.7.10-1614-stripped.jar")
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
@IFMLLoadingPlugin.TransformerExclusions({"com.mitchej123.hodgepodge.asm", "optifine"})
@IFMLLoadingPlugin.SortingIndex(1002)
@IFMLLoadingPlugin.DependsOn("cofh.asm.LoadingPlugin")
public class HodgePodgeASMLoader implements IFMLLoadingPlugin {
public class HodgePodgeASMLoader
implements IFMLLoadingPlugin { // TODO move the Transformers to the asm.transformers package
private static final Logger log = LogManager.getLogger("Hodgepodge");
public static final SortingIndex index =
HodgePodgeASMLoader.class.getAnnotation(IFMLLoadingPlugin.SortingIndex.class);
Expand All @@ -41,6 +42,11 @@ public enum AsmTransformers {
"Fix vanilla potion effects rendering above the NEI tooltips in the inventory",
() -> Hodgepodge.config.fixPotionEffectRender,
Collections.singletonList("com.mitchej123.hodgepodge.asm.InventoryEffectRendererTransformer")),
FIX_TINKER_POTION_EFFECT_OFFSET(
"Prevents the inventory from shifting when the player has active potion effects",
() -> Hodgepodge.config.fixPotionRenderOffset,
Collections.singletonList(
"com.mitchej123.hodgepodge.asm.transformers.tconstruct.TabRegistryTransformer")),
THERMOS_SLEDGEHAMMER_FURNACE_FIX(
"Take a sledgehammer to CraftServer.resetRecipes() to prevent it from breaking our Furnace Fix",
() -> Hodgepodge.thermosTainted && Hodgepodge.config.speedupVanillaFurnace,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mitchej123.hodgepodge.asm.hooks.tconstruct;

@SuppressWarnings("unused")
public class TabRegistryHook {
public static int fixPotionOffset() {
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.mitchej123.hodgepodge.asm.transformers.tconstruct;

import static org.objectweb.asm.Opcodes.ASM5;

import com.mitchej123.hodgepodge.Hodgepodge;
import net.minecraft.launchwrapper.IClassTransformer;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;

@SuppressWarnings("unused")
public class TabRegistryTransformer implements IClassTransformer {
@Override
public byte[] transform(String name, String transformedName, byte[] basicClass) {
if ("tconstruct.client.tabs.TabRegistry".equals(transformedName)) {
Hodgepodge.log.info("Patching TConstruct {}", transformedName);
final ClassReader cr = new ClassReader(basicClass);
final ClassWriter cw = new ClassWriter(0);
final ClassNode cn = new ClassNode(ASM5);
cr.accept(cn, 0);
for (MethodNode m : cn.methods) {
if ("guiPostInit".equals(m.name)) {
for (AbstractInsnNode insnNode : m.instructions.toArray()) {
if (insnNode instanceof MethodInsnNode
&& insnNode.getOpcode() == Opcodes.INVOKESTATIC
&& ((MethodInsnNode) insnNode).name.equals("getPotionOffset")
&& ((MethodInsnNode) insnNode).desc.equals("()I")) {
m.instructions.insert(
insnNode,
new MethodInsnNode(
Opcodes.INVOKESTATIC,
"com/mitchej123/hodgepodge/asm/hooks/tconstruct/TabRegistryHook",
"fixPotionOffset",
"()I",
false));
m.instructions.remove(insnNode);
}
}
}
}
cn.accept(cw);
return cw.toByteArray();
} else {
return basicClass;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ private boolean loadModJar(final TargetedMod mod) {
Hodgepodge.log.info("Jar not found for " + mod);
return false;
}

// TODO it loads the wrong .jar for certain mods that contains the same same
// for instance with TargetedMod = TINKERSCONSTRUCT("TConstruct", "TConstruct", "TinkersConstruct")
// it loads IguanaTweaksTConstruct-1.7.10-2.2.2.jar instead
Hodgepodge.log.info("Attempting to add " + jar + " to the URL Class Path");
if (!jar.exists()) {
throw new FileNotFoundException(jar.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class LoadingConfig {
public boolean fixIc2UnprotectedGetBlock;
public boolean fixNorthWestBias;
public boolean fixPotionEffectRender;
public boolean fixPotionRenderOffset;
public boolean fixPotionLimit;
public boolean fixPerspectiveCamera;
public boolean fixHopperVoidingItems;
Expand Down Expand Up @@ -254,6 +255,12 @@ public LoadingConfig(File file) {
true,
"Fix vanilla potion effects rendering above the NEI tooltips in the inventory")
.getBoolean();
fixPotionRenderOffset = config.get(
"tweaks",
"fixPotionRenderOffset",
true,
"Prevents the inventory from shifting when the player has active potion effects")
.getBoolean();
installAnchorAlarm = config.get(
"tweaks", "installAnchorAlarm", true, "Wake up passive & personal anchors on player login")
.getBoolean();
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ public enum Mixins {
"minecraft.MixinEntityRenderer", () -> Hodgepodge.config.fixPerspectiveCamera, TargetedMod.VANILLA),
FENCE_CONNECTIONS_FIX(
"minecraft.MixinBlockFence", () -> Hodgepodge.config.fixFenceConnections, TargetedMod.VANILLA),
FIX_INVENTORY_OFFSET_WITH_POTIONS(
"minecraft.MixinInventoryEffectRenderer",
Side.CLIENT,
() -> Hodgepodge.config.fixPotionRenderOffset,
TargetedMod.VANILLA),
CHUNK_COORDINATES_HASHCODE(
"minecraft.MixinChunkCoordinates",
() -> Hodgepodge.config.speedupChunkCoordinatesHashCode,
Expand Down Expand Up @@ -238,7 +243,18 @@ public enum Mixins {
Side.CLIENT,
() -> Hodgepodge.config.fixIgnisFruitAABB,
TargetedMod.HARVESTTHENETHER),
;
FIX_BAUBLES_INVENTORY_OFFSET_WITH_POTIONS(
"baubles.MixinGuiEvents", Side.CLIENT, () -> Hodgepodge.config.fixPotionRenderOffset, TargetedMod.BAUBLES),
FIX_GALACTICRAFT_INVENTORY_OFFSET_WITH_POTIONS(
"galacticraftcore.MixinGuiExtendedInventory",
Side.CLIENT,
() -> Hodgepodge.config.fixPotionRenderOffset,
TargetedMod.GALACTICRAFT_CORE),
FIX_TRAVELLERSGEAR_INVENTORY_OFFSET_WITH_POTIONS(
"travellersgear.MixinClientProxy",
Side.CLIENT,
() -> Hodgepodge.config.fixPotionRenderOffset,
TargetedMod.TRAVELLERSGEAR);

public final List<String> mixinClass;
private final Supplier<Boolean> applyIf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public enum TargetedMod {
PROJECTE("ProjectE", "ProjectE-1.7.10", "projecte", true),
FASTCRAFT("FastCraft", "fastcraft", true),
HARVESTTHENETHER("harvestthenether", "Pam's Harvest the Nether"),
GALACTICRAFT_CORE("GalacticraftCore", "Galacticraft"),
BAUBLES("Baubles", "Baubles"),
TRAVELLERSGEAR("TravellersGear", "TravellersGear"),
// Temporary solution to force load it early
GTNHLIB("GTNHLib", "gtnhlib"),
;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mitchej123.hodgepodge.mixins.baubles;

import baubles.client.gui.GuiEvents;
import java.util.Collection;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(GuiEvents.class)
public class MixinGuiEvents {

@Redirect(
method = "guiPostInit",
at = @At(value = "INVOKE", target = "Ljava/util/Collection;isEmpty()Z", remap = false),
remap = false)
public boolean hodgepodge$fixPotionOffset(@SuppressWarnings("rawtypes") Collection instance) {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.mitchej123.hodgepodge.mixins.galacticraftcore;

import micdoodle8.mods.galacticraft.core.client.gui.container.GuiExtendedInventory;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@Mixin(value = GuiExtendedInventory.class)
public class MixinGuiExtendedInventory {

@Redirect(
method = "initGui",
at =
@At(
value = "INVOKE",
target =
"Lmicdoodle8/mods/galacticraft/core/client/gui/container/GuiExtendedInventory;getPotionOffset()I",
remap = false))
public int hodgepodge$fixPotionOffset1(GuiExtendedInventory instance) {
return 0;
}

@Redirect(
method = "initGui",
at =
@At(
value = "INVOKE",
target =
"Lmicdoodle8/mods/galacticraft/core/client/gui/container/GuiExtendedInventory;getPotionOffsetNEI()I",
remap = false))
public int hodgepodge$fixPotionOffset2(GuiExtendedInventory instance) {
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.mitchej123.hodgepodge.mixins.minecraft;

import net.minecraft.client.renderer.InventoryEffectRenderer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(InventoryEffectRenderer.class)
public class MixinInventoryEffectRenderer {

@ModifyConstant(method = "initGui", constant = @Constant(intValue = 160, ordinal = 0))
public int hodgepodge$fixPotionOffset1(int i) {
return 0;
}

@ModifyConstant(method = "initGui", constant = @Constant(intValue = 200, ordinal = 0))
public int hodgepodge$fixPotionOffset2(int i) {
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mitchej123.hodgepodge.mixins.travellersgear;

import java.util.Collection;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import travellersgear.client.ClientProxy;

@Mixin(ClientProxy.class)
public class MixinClientProxy {

@Redirect(
method = "guiPostInit",
at = @At(value = "INVOKE", target = "Ljava/util/Collection;isEmpty()Z", remap = false),
remap = false)
public boolean hodgepodge$fixPotionOffset(@SuppressWarnings("rawtypes") Collection instance) {
return true;
}
}

0 comments on commit eb6c039

Please sign in to comment.