-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added transformers for the items Shadow told me about.
- Loading branch information
Showing
7 changed files
with
724 additions
and
9 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
106 changes: 106 additions & 0 deletions
106
alicefixes/src/com/skcraft/alicefixes/transformers/TransformDislocWand.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,106 @@ | ||
package com.skcraft.alicefixes.transformers; | ||
|
||
import static org.objectweb.asm.Opcodes.*; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import net.minecraft.entity.player.EntityPlayer; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.block.BlockBreakEvent; | ||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassVisitor; | ||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.Label; | ||
import org.objectweb.asm.MethodVisitor; | ||
|
||
import com.skcraft.alicefixes.util.ObfNames; | ||
|
||
import cpw.mods.fml.relauncher.IClassTransformer; | ||
|
||
public class TransformDislocWand implements IClassTransformer { | ||
|
||
@Override | ||
public byte[] transform(String name, String transformedName, byte[] bytes) { | ||
|
||
if(name.equals("vazkii.tinkerer.item.ItemWandDislocation")) { | ||
ClassReader cr = new ClassReader(bytes); | ||
ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS); | ||
cr.accept(new WandVisitor(cw), 0); | ||
return cw.toByteArray(); | ||
} | ||
return bytes; | ||
} | ||
|
||
public static boolean canMine(EntityPlayer player, int x, int y, int z) { | ||
try { | ||
Method m = player.getClass() | ||
.getDeclaredMethod("getBukkitEntity", new Class[] {}); | ||
org.bukkit.entity.Entity ent = | ||
(org.bukkit.entity.Entity)m.invoke(player); | ||
if ((ent instanceof Player)) { | ||
Player bukkitPlayer = (Player)ent; | ||
org.bukkit.World bukkitWorld = bukkitPlayer.getWorld(); | ||
BlockBreakEvent breakEv = new BlockBreakEvent( | ||
bukkitWorld.getBlockAt(x, y, z), bukkitPlayer); | ||
Bukkit.getPluginManager().callEvent(breakEv); | ||
if (breakEv.isCancelled()) { | ||
return false; | ||
} | ||
breakEv.setCancelled(true); | ||
} | ||
} | ||
catch(Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return true; | ||
} | ||
|
||
class WandVisitor extends ClassVisitor { | ||
|
||
public WandVisitor(ClassVisitor cv) { | ||
super(ASM4, cv); | ||
} | ||
|
||
@Override | ||
public MethodVisitor visitMethod(int access, String name, String desc, | ||
String signature, String[] exceptions) { | ||
|
||
if(name.equals("onItemUseFirst")) { | ||
return new OnItemUseFirstVisitor(super.visitMethod(access, name, | ||
desc, signature, exceptions)); | ||
} | ||
return super.visitMethod(access, name, desc, signature, | ||
exceptions); | ||
} | ||
} | ||
|
||
class OnItemUseFirstVisitor extends MethodVisitor { | ||
|
||
public OnItemUseFirstVisitor(MethodVisitor mv) { | ||
super(ASM4, mv); | ||
} | ||
|
||
@Override | ||
public void visitCode() { | ||
Label l0 = new Label(); | ||
mv.visitLabel(l0); | ||
mv.visitVarInsn(ALOAD, 2); | ||
mv.visitVarInsn(ILOAD, 4); | ||
mv.visitVarInsn(ILOAD, 5); | ||
mv.visitVarInsn(ILOAD, 6); | ||
mv.visitMethodInsn(INVOKESTATIC, "com/skcraft/alicefixes/transformers/TransformDislocWand", | ||
"canMine", "(L" + ObfNames.ENTITY_PLAYER +";III)Z"); | ||
Label l1 = new Label(); | ||
mv.visitJumpInsn(IFNE, l1); | ||
Label l2 = new Label(); | ||
mv.visitLabel(l2); | ||
mv.visitInsn(ICONST_1); | ||
mv.visitInsn(IRETURN); | ||
mv.visitLabel(l1); | ||
mv.visitCode(); | ||
} | ||
} | ||
|
||
} |
104 changes: 104 additions & 0 deletions
104
alicefixes/src/com/skcraft/alicefixes/transformers/TransformElemAxe.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,104 @@ | ||
package com.skcraft.alicefixes.transformers; | ||
|
||
import static org.objectweb.asm.Opcodes.*; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import net.minecraft.entity.player.EntityPlayer; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.block.BlockBreakEvent; | ||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassVisitor; | ||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.Label; | ||
import org.objectweb.asm.MethodVisitor; | ||
|
||
import com.skcraft.alicefixes.util.ObfNames; | ||
|
||
import cpw.mods.fml.relauncher.IClassTransformer; | ||
|
||
public class TransformElemAxe implements IClassTransformer { | ||
|
||
@Override | ||
public byte[] transform(String name, String transformedName, byte[] bytes) { | ||
|
||
if(name.equals("thaumcraft.common.items.equipment.ItemElementalAxe")) { | ||
ClassReader cr = new ClassReader(bytes); | ||
ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS); | ||
cr.accept(new AxeVisitor(cw), 0); | ||
return cw.toByteArray(); | ||
} | ||
return bytes; | ||
} | ||
|
||
public static boolean canMine(EntityPlayer player, int x, int y, int z) { | ||
try { | ||
Method m = player.getClass() | ||
.getDeclaredMethod("getBukkitEntity", new Class[] {}); | ||
org.bukkit.entity.Entity ent = | ||
(org.bukkit.entity.Entity)m.invoke(player); | ||
if ((ent instanceof Player)) { | ||
Player bukkitPlayer = (Player)ent; | ||
org.bukkit.World bukkitWorld = bukkitPlayer.getWorld(); | ||
BlockBreakEvent breakEv = new BlockBreakEvent( | ||
bukkitWorld.getBlockAt(x, y, z), bukkitPlayer); | ||
Bukkit.getPluginManager().callEvent(breakEv); | ||
if (breakEv.isCancelled()) { | ||
return false; | ||
} | ||
breakEv.setCancelled(true); | ||
} | ||
} | ||
catch(Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return true; | ||
} | ||
|
||
class AxeVisitor extends ClassVisitor { | ||
|
||
public AxeVisitor(ClassVisitor cv) { | ||
super(ASM4, cv); | ||
} | ||
|
||
@Override | ||
public MethodVisitor visitMethod(int access, String name, String desc, | ||
String signature, String[] exceptions) { | ||
|
||
if(name.equals("breakFurthestBlock")) { | ||
return new BreakFurthestBlockVisitor(super.visitMethod(access, name, | ||
desc, signature, exceptions)); | ||
} | ||
return super.visitMethod(access, name, desc, signature, | ||
exceptions); | ||
} | ||
} | ||
|
||
class BreakFurthestBlockVisitor extends MethodVisitor { | ||
|
||
public BreakFurthestBlockVisitor(MethodVisitor mv) { | ||
super(ASM4, mv); | ||
} | ||
|
||
@Override | ||
public void visitCode() { | ||
Label l0 = new Label(); | ||
mv.visitLabel(l0); | ||
mv.visitVarInsn(ALOAD, 7); | ||
mv.visitVarInsn(ILOAD, 3); | ||
mv.visitVarInsn(ILOAD, 4); | ||
mv.visitVarInsn(ILOAD, 5); | ||
mv.visitMethodInsn(INVOKESTATIC, "com/skcraft/alicefixes/transformers/TransformElemAxe", | ||
"canMine", "(L" + ObfNames.ENTITY_PLAYER +";III)Z"); | ||
Label l1 = new Label(); | ||
mv.visitJumpInsn(IFNE, l1); | ||
Label l2 = new Label(); | ||
mv.visitLabel(l2); | ||
mv.visitInsn(RETURN); | ||
mv.visitLabel(l1); | ||
mv.visitCode(); | ||
} | ||
} | ||
} |
140 changes: 140 additions & 0 deletions
140
alicefixes/src/com/skcraft/alicefixes/transformers/TransformElemShovel.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,140 @@ | ||
package com.skcraft.alicefixes.transformers; | ||
|
||
import static org.objectweb.asm.Opcodes.*; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import net.minecraft.entity.EntityLiving; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.block.BlockBreakEvent; | ||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassVisitor; | ||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.Label; | ||
import org.objectweb.asm.MethodVisitor; | ||
|
||
import com.skcraft.alicefixes.util.ObfNames; | ||
|
||
import cpw.mods.fml.relauncher.IClassTransformer; | ||
|
||
public class TransformElemShovel implements IClassTransformer { | ||
|
||
@Override | ||
public byte[] transform(String name, String transformedName, byte[] bytes) { | ||
|
||
if(name.equals("thaumcraft.common.items.equipment.ItemElementalShovel")) { | ||
ClassReader cr = new ClassReader(bytes); | ||
ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS); | ||
cr.accept(new ShovelVisitor(cw), 0); | ||
return cw.toByteArray(); | ||
} | ||
return bytes; | ||
} | ||
|
||
public static boolean canMine(EntityLiving entity, int x, int y, int z) { | ||
if(entity instanceof EntityPlayer) { | ||
EntityPlayer player = (EntityPlayer)entity; | ||
try { | ||
Method m = player.getClass() | ||
.getDeclaredMethod("getBukkitEntity", new Class[] {}); | ||
org.bukkit.entity.Entity ent = | ||
(org.bukkit.entity.Entity)m.invoke(player); | ||
if ((ent instanceof Player)) { | ||
Player bukkitPlayer = (Player)ent; | ||
org.bukkit.World bukkitWorld = bukkitPlayer.getWorld(); | ||
BlockBreakEvent breakEv = new BlockBreakEvent( | ||
bukkitWorld.getBlockAt(x, y, z), bukkitPlayer); | ||
Bukkit.getPluginManager().callEvent(breakEv); | ||
if (breakEv.isCancelled()) { | ||
return false; | ||
} | ||
breakEv.setCancelled(true); | ||
} | ||
} | ||
catch(Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
class ShovelVisitor extends ClassVisitor { | ||
|
||
public ShovelVisitor(ClassVisitor cv) { | ||
super(ASM4, cv); | ||
} | ||
|
||
@Override | ||
public MethodVisitor visitMethod(int access, String name, String desc, | ||
String signature, String[] exceptions) { | ||
|
||
if(name.equals("func_77648_a")) { | ||
return new OnItemUseVisitor(super.visitMethod(access, name, | ||
desc, signature, exceptions)); | ||
} else if(name.equals("func_77660_a")) { | ||
return new OnBlockDestroyedVisitor(super.visitMethod(access, name, | ||
desc, signature, exceptions)); | ||
} | ||
return super.visitMethod(access, name, desc, signature, | ||
exceptions); | ||
} | ||
} | ||
|
||
class OnItemUseVisitor extends MethodVisitor { | ||
|
||
public OnItemUseVisitor(MethodVisitor mv) { | ||
super(ASM4, mv); | ||
} | ||
|
||
@Override | ||
public void visitCode() { | ||
Label l0 = new Label(); | ||
mv.visitLabel(l0); | ||
mv.visitVarInsn(ALOAD, 2); | ||
mv.visitVarInsn(ILOAD, 4); | ||
mv.visitVarInsn(ILOAD, 5); | ||
mv.visitVarInsn(ILOAD, 6); | ||
mv.visitMethodInsn(INVOKESTATIC, "com/skcraft/alicefixes/transformers/TransformElemShovel", | ||
"canMine", "(L" + ObfNames.ENTITY_LIVING +";III)Z"); | ||
Label l1 = new Label(); | ||
mv.visitJumpInsn(IFNE, l1); | ||
Label l2 = new Label(); | ||
mv.visitLabel(l2); | ||
mv.visitInsn(ICONST_0); | ||
mv.visitInsn(IRETURN); | ||
mv.visitLabel(l1); | ||
mv.visitCode(); | ||
} | ||
} | ||
|
||
class OnBlockDestroyedVisitor extends MethodVisitor { | ||
|
||
public OnBlockDestroyedVisitor(MethodVisitor mv) { | ||
super(ASM4, mv); | ||
} | ||
|
||
@Override | ||
public void visitCode() { | ||
Label l0 = new Label(); | ||
mv.visitLabel(l0); | ||
mv.visitVarInsn(ALOAD, 7); | ||
mv.visitVarInsn(ILOAD, 4); | ||
mv.visitVarInsn(ILOAD, 5); | ||
mv.visitVarInsn(ILOAD, 6); | ||
mv.visitMethodInsn(INVOKESTATIC, "com/skcraft/alicefixes/transformers/TransformElemShovel", | ||
"canMine", "(L" + ObfNames.ENTITY_LIVING + ";III)Z"); | ||
Label l1 = new Label(); | ||
mv.visitJumpInsn(IFNE, l1); | ||
Label l2 = new Label(); | ||
mv.visitLabel(l2); | ||
mv.visitInsn(ICONST_0); | ||
mv.visitInsn(IRETURN); | ||
mv.visitLabel(l1); | ||
mv.visitCode(); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.