-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Keep the inventory centered when the player has potion effects (#100)
* 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
Showing
13 changed files
with
188 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/com/mitchej123/hodgepodge/asm/hooks/tconstruct/TabRegistryHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...in/java/com/mitchej123/hodgepodge/asm/transformers/tconstruct/TabRegistryTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/mitchej123/hodgepodge/mixins/baubles/MixinGuiEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...ain/java/com/mitchej123/hodgepodge/mixins/galacticraftcore/MixinGuiExtendedInventory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/mitchej123/hodgepodge/mixins/minecraft/MixinInventoryEffectRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/mitchej123/hodgepodge/mixins/travellersgear/MixinClientProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |