-
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.
- Loading branch information
Showing
7 changed files
with
250 additions
and
219 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
87 changes: 0 additions & 87 deletions
87
alicefixes/src/com/skcraft/alicefixes/TransformBlockBreaker.java
This file was deleted.
Oops, something went wrong.
119 changes: 0 additions & 119 deletions
119
alicefixes/src/com/skcraft/alicefixes/TransformMiningLaser.java
This file was deleted.
Oops, something went wrong.
103 changes: 103 additions & 0 deletions
103
alicefixes/src/com/skcraft/alicefixes/transformers/TransformBlockBreaker.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,103 @@ | ||
package com.skcraft.alicefixes.transformers; | ||
|
||
import static org.objectweb.asm.Opcodes.*; | ||
|
||
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.BreakerBlacklist; | ||
import com.skcraft.alicefixes.util.CoordHelper; | ||
import com.skcraft.alicefixes.util.ObfNames; | ||
|
||
import net.minecraft.tileentity.TileEntity; | ||
import cpw.mods.fml.relauncher.IClassTransformer; | ||
|
||
// THIS MAY NOT WORK ANYMORE! | ||
public class TransformBlockBreaker implements IClassTransformer { | ||
|
||
@Override | ||
public byte[] transform(String name, String transformedName, byte[] bytes) { | ||
if(name.equals("com.eloraam.redpower.machine.TileBreaker")) { | ||
return handleBreakerTransform(bytes); | ||
} | ||
return bytes; | ||
} | ||
|
||
private byte[] handleBreakerTransform(byte[] bytes) { | ||
ClassReader cr = new ClassReader(bytes); | ||
ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS); | ||
|
||
cr.accept(new TileBreakerVisitor(cw), 0); | ||
return cw.toByteArray(); | ||
} | ||
|
||
public static boolean canMine(TileEntity tile, int rotation) { | ||
|
||
CoordHelper facingCoords = new CoordHelper(tile.xCoord, tile.yCoord, | ||
tile.zCoord); | ||
facingCoords.addFacingAsOffset(rotation); | ||
|
||
int id = tile.worldObj.getBlockId(facingCoords.x, facingCoords.y, | ||
facingCoords.z); | ||
|
||
for(int i = 0; i < BreakerBlacklist.forbiddenIds.length; i++) { | ||
if(id == BreakerBlacklist.forbiddenIds[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
class TileBreakerVisitor extends ClassVisitor { | ||
|
||
public TileBreakerVisitor(ClassVisitor cv) { | ||
super(ASM4, cv); | ||
} | ||
|
||
@Override | ||
public MethodVisitor visitMethod(int access, String name, String desc, | ||
String signature, String[] exceptions) { | ||
|
||
if(name.equals("onBlockNeighborChange")) { | ||
return new OnNeighborChangeVisitor(super.visitMethod(access, | ||
name, desc, signature, exceptions)); | ||
} | ||
return super.visitMethod(access, name, desc, signature, | ||
exceptions); | ||
} | ||
} | ||
|
||
class OnNeighborChangeVisitor extends MethodVisitor { | ||
|
||
public OnNeighborChangeVisitor(MethodVisitor mv) { | ||
super(ASM4, mv); | ||
} | ||
|
||
@Override | ||
public void visitCode() { | ||
Label l0 = new Label(); | ||
mv.visitLabel(l0); | ||
mv.visitVarInsn(ALOAD, 0); | ||
mv.visitVarInsn(ALOAD, 0); | ||
mv.visitFieldInsn(GETFIELD, | ||
"com/eloraam/redpower/machine/TileBreaker", | ||
"Rotation", | ||
"I"); | ||
mv.visitMethodInsn(INVOKESTATIC, | ||
"com/skcraft/alicefixes/transformers/TransformBlockBreaker", | ||
"canMine", | ||
"(L" + ObfNames.TILE_ENTITY + ";I)Z"); | ||
Label l1 = new Label(); | ||
mv.visitJumpInsn(IFEQ, l1); | ||
Label l2 = new Label(); | ||
mv.visitLabel(l2); | ||
mv.visitInsn(RETURN); | ||
mv.visitLabel(l1); | ||
mv.visitCode(); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.