-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
764e047
commit 58b88b1
Showing
5 changed files
with
86 additions
and
257 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.modularwarfare; | ||
|
||
import com.modularwarfare.client.ClientRenderHooks; | ||
import net.minecraft.client.Minecraft; | ||
|
||
public class InjectMethods { | ||
|
||
public static boolean isReloading() { | ||
return ClientRenderHooks.getAnimMachine(Minecraft.getMinecraft().player).reloading; | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
src/main/java/com/modularwarfare/mixin/ClassTransformer.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,67 @@ | ||
package com.modularwarfare.mixin; | ||
|
||
import net.minecraft.launchwrapper.IClassTransformer; | ||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.tree.*; | ||
|
||
import static org.objectweb.asm.Opcodes.*; | ||
|
||
public class ClassTransformer implements IClassTransformer { | ||
|
||
@Override | ||
public byte[] transform(String name, String transformedName, byte[] basicClass) { | ||
|
||
if (transformedName.equals("net.minecraft.client.Minecraft") || transformedName.equals("bib")) { | ||
|
||
ClassReader cr = new ClassReader(basicClass); | ||
ClassNode cn = new ClassNode(); | ||
cr.accept(cn, 0); | ||
|
||
for (MethodNode method : cn.methods) { | ||
|
||
if (!(method.name.equals("processKeyBinds") || method.name.equals("func_184117_aA") || method.name.equals("aE"))) continue; | ||
|
||
for (AbstractInsnNode ain : method.instructions.toArray()) { | ||
if (!(ain.getOpcode() == INVOKEVIRTUAL)) continue; | ||
|
||
MethodInsnNode min = (MethodInsnNode) ain; | ||
|
||
if (min.name.equals("onHotbarSelected") || min.name.equals("func_175260_a") || min.name.equals("a")) { | ||
|
||
LabelNode jumpLabel = null; | ||
|
||
for (int i = 1;; i++) { | ||
|
||
AbstractInsnNode insnNode = method.instructions.get(method.instructions.indexOf(min) + i); | ||
|
||
if (insnNode.getOpcode() == GOTO) { | ||
jumpLabel = ((JumpInsnNode) insnNode).label; | ||
} | ||
|
||
if(jumpLabel != null && insnNode.getOpcode() == ALOAD) { | ||
InsnList injectInsnList = new InsnList(); | ||
injectInsnList.add(new MethodInsnNode(INVOKESTATIC, "com/modularwarfare/InjectMethods", "isReloading", "()Z", false)); | ||
injectInsnList.add(new JumpInsnNode(IFNE, jumpLabel)); | ||
method.instructions.insertBefore(insnNode, injectInsnList); | ||
break; | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); | ||
cn.accept(cw); | ||
return cw.toByteArray(); | ||
|
||
} | ||
|
||
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
50 changes: 6 additions & 44 deletions
50
src/main/java/com/modularwarfare/mixin/client/MixinInventoryPlayer.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 |
---|---|---|
@@ -1,63 +1,25 @@ | ||
package com.modularwarfare.mixin.client; | ||
|
||
import com.modularwarfare.ModularWarfare; | ||
import com.modularwarfare.client.ClientRenderHooks; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.entity.player.InventoryPlayer; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.NonNullList; | ||
import net.minecraftforge.fml.relauncher.Side; | ||
import net.minecraftforge.fml.relauncher.SideOnly; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(InventoryPlayer.class) | ||
public abstract class MixinInventoryPlayer { | ||
|
||
@Shadow | ||
public int currentItem; | ||
|
||
@Shadow | ||
@Final | ||
public NonNullList<ItemStack> mainInventory; | ||
|
||
@Shadow | ||
public EntityPlayer player; | ||
|
||
@Shadow | ||
public abstract ItemStack getStackInSlot(int index); | ||
|
||
/** | ||
* @author | ||
*/ | ||
@Overwrite | ||
@SideOnly(Side.CLIENT) | ||
public void changeCurrentItem(int direction) { | ||
@Inject(method = "changeCurrentItem", at = @At("HEAD"), cancellable = true) | ||
public void inject_changeCurrentItem(CallbackInfo ci) { | ||
if(ClientRenderHooks.getAnimMachine(player).reloading){ | ||
return; | ||
} | ||
if (direction > 0) | ||
{ | ||
direction = 1; | ||
} | ||
|
||
if (direction < 0) | ||
{ | ||
direction = -1; | ||
} | ||
|
||
for (this.currentItem -= direction; this.currentItem < 0; this.currentItem += 9) | ||
{ | ||
; | ||
} | ||
|
||
while (this.currentItem >= 9) | ||
{ | ||
this.currentItem -= 9; | ||
ci.cancel(); | ||
} | ||
} | ||
|
||
|
||
} |
212 changes: 0 additions & 212 deletions
212
src/main/java/com/modularwarfare/mixin/client/MixinMinecraft.java
This file was deleted.
Oops, something went wrong.