-
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 a blacklist for TE's block breaker.
- Loading branch information
Showing
6 changed files
with
156 additions
and
5 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
35 changes: 35 additions & 0 deletions
35
src/main/java/com/skcraft/alicefixes/BreakerBlacklist.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,35 @@ | ||
package com.skcraft.alicefixes; | ||
|
||
import cpw.mods.fml.common.Loader; | ||
import net.minecraftforge.common.Configuration; | ||
|
||
import java.io.File; | ||
|
||
public class BreakerBlacklist { | ||
|
||
public static int[] blacklist = new int[] {}; | ||
|
||
public static void load() { | ||
File configDir = Loader.instance().getConfigDir(); | ||
configDir = new File(configDir, "/cofh/"); | ||
configDir.mkdir(); | ||
configDir = new File(configDir, "breakerblacklist.cfg"); | ||
Configuration list = new Configuration(configDir); | ||
|
||
try { | ||
list.load(); | ||
blacklist = list.get("Blacklist", "blacklist", new int[] {-1}, | ||
"List of block IDs that the block breaker cannot break. Add 1 ID per line.").getIntList(); | ||
} | ||
catch(Throwable t) { | ||
t.printStackTrace(); | ||
} | ||
finally { | ||
list.save(); | ||
} | ||
} | ||
|
||
public static int[] getBlacklist() { | ||
return blacklist; | ||
} | ||
} |
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
67 changes: 67 additions & 0 deletions
67
src/main/java/com/skcraft/alicefixes/transformers/TransformBreaker.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.skcraft.alicefixes.transformers; | ||
|
||
import com.skcraft.alicefixes.util.ASMHelper; | ||
import net.minecraft.launchwrapper.IClassTransformer; | ||
import org.objectweb.asm.*; | ||
|
||
import static org.objectweb.asm.Opcodes.*; | ||
|
||
public class TransformBreaker implements IClassTransformer { | ||
|
||
@Override | ||
public byte[] transform(String name, String transformedName, byte[] bytes) { | ||
if(name.equals("thermalexpansion.block.device.TileBreaker")) { | ||
ClassReader cr = new ClassReader(bytes); | ||
ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS); | ||
cr.accept(new BreakerVisitor(cw), 0); | ||
return cw.toByteArray(); | ||
} | ||
return bytes; | ||
} | ||
|
||
class BreakerVisitor extends ClassVisitor { | ||
public BreakerVisitor(ClassVisitor cv) { | ||
super(ASM4, cv); | ||
} | ||
|
||
@Override | ||
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { | ||
|
||
if(name.equals("breakBlock")) { | ||
return new BreakBlockVisitor(super.visitMethod(access, name, | ||
desc, signature, exceptions)); | ||
} | ||
return super.visitMethod(access, name, desc, signature, | ||
exceptions); | ||
} | ||
} | ||
|
||
class BreakBlockVisitor extends MethodVisitor { | ||
public BreakBlockVisitor(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, | ||
"thermalexpansion/block/device/TileBreaker", | ||
"facing", | ||
"B"); | ||
mv.visitMethodInsn(INVOKESTATIC, | ||
"com/skcraft/alicefixes/util/ASMHelper", | ||
"canTileMine", | ||
"(L" + ASMHelper.getObf("TileEntity") + ";B)Z"); | ||
Label l1 = new Label(); | ||
mv.visitJumpInsn(IFNE, l1); | ||
Label l2 = new Label(); | ||
mv.visitLabel(l2); | ||
mv.visitInsn(RETURN); | ||
mv.visitLabel(l1); | ||
mv.visitCode(); | ||
} | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
src/main/java/com/skcraft/alicefixes/util/CoordHelper.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,35 @@ | ||
package com.skcraft.alicefixes.util; | ||
|
||
public class CoordHelper { | ||
|
||
public int x, y, z; | ||
|
||
public CoordHelper(int x, int y, int z) { | ||
this.x = x; | ||
this.y = y; | ||
this.z = z; | ||
} | ||
|
||
public void addFacingAsOffset(byte facing) { | ||
switch (facing) | ||
{ | ||
case 0: | ||
y--; | ||
break; | ||
case 1: | ||
y++; | ||
break; | ||
case 2: | ||
z--; | ||
break; | ||
case 3: | ||
z++; | ||
break; | ||
case 4: | ||
x--; | ||
break; | ||
default: | ||
x++; | ||
} | ||
} | ||
} |