Skip to content

Commit

Permalink
Reorganized into packages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe12o committed Jul 23, 2013
1 parent d012d5b commit 3922e7f
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 219 deletions.
9 changes: 0 additions & 9 deletions alicefixes/src/com/skcraft/alicefixes/ObfNames.java

This file was deleted.

87 changes: 0 additions & 87 deletions alicefixes/src/com/skcraft/alicefixes/TransformBlockBreaker.java

This file was deleted.

119 changes: 0 additions & 119 deletions alicefixes/src/com/skcraft/alicefixes/TransformMiningLaser.java

This file was deleted.

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();
}

}
}
Loading

0 comments on commit 3922e7f

Please sign in to comment.