-
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 block breaker blacklist. Also tabs -> spaces.
- Loading branch information
Showing
8 changed files
with
332 additions
and
159 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,15 @@ | ||
package com.skcraft.alicefixes; | ||
|
||
import cpw.mods.fml.common.Mod; | ||
import cpw.mods.fml.common.Mod.PreInit; | ||
import cpw.mods.fml.common.event.FMLPreInitializationEvent; | ||
|
||
@Mod(modid = "aliceFixes", version = "0.1.0") | ||
public class AliceFixes { | ||
|
||
@PreInit | ||
public void preInit(FMLPreInitializationEvent evt) { | ||
BreakerBlacklist.load(); | ||
} | ||
|
||
} |
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
32 changes: 32 additions & 0 deletions
32
alicefixes/src/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,32 @@ | ||
package com.skcraft.alicefixes; | ||
|
||
import java.io.File; | ||
|
||
import cpw.mods.fml.common.Loader; | ||
import net.minecraftforge.common.Configuration; | ||
|
||
public class BreakerBlacklist { | ||
|
||
public static int[] forbiddenIds = new int[] {}; | ||
|
||
public static void load() { | ||
File configDir = Loader.instance().getConfigDir(); | ||
configDir = new File(configDir, "/redpower/"); | ||
configDir.mkdir(); | ||
configDir = new File(configDir, "blacklist.cfg"); | ||
Configuration blacklist = new Configuration(configDir); | ||
|
||
try { | ||
blacklist.load(); | ||
forbiddenIds = blacklist.get("Blacklist", "forbiddenBlocks", | ||
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 { | ||
blacklist.save(); | ||
} | ||
} | ||
|
||
} |
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,37 @@ | ||
package com.skcraft.alicefixes; | ||
|
||
public class CoordHelper { | ||
|
||
int x; | ||
int y; | ||
int z; | ||
|
||
public CoordHelper(int x, int y, int z) { | ||
this.x = x; | ||
this.y = y; | ||
this.z = z; | ||
} | ||
|
||
public void addFacingAsOffset(int facing) { | ||
switch (facing) | ||
{ | ||
case 0: | ||
this.y += 1; | ||
break; | ||
case 1: | ||
this.y -= 1; | ||
break; | ||
case 2: | ||
this.z += 1; | ||
break; | ||
case 3: | ||
this.z -= 1; | ||
break; | ||
case 4: | ||
this.x += 1; | ||
break; | ||
default: | ||
this.x -= 1; | ||
} | ||
} | ||
} |
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
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,8 +1,9 @@ | ||
package com.skcraft.alicefixes; | ||
|
||
public class ObfNames { | ||
|
||
public static final String ENTITY_LIVING = "md"; | ||
public static final String ENTITY = "lq"; | ||
|
||
|
||
public static final String ENTITY_LIVING = "md"; | ||
public static final String ENTITY = "lq"; | ||
public static final String TILE_ENTITY = "any"; | ||
|
||
} |
86 changes: 86 additions & 0 deletions
86
alicefixes/src/com/skcraft/alicefixes/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,86 @@ | ||
package com.skcraft.alicefixes; | ||
|
||
import static org.objectweb.asm.Opcodes.*; | ||
|
||
import java.util.Iterator; | ||
import java.util.logging.Level; | ||
|
||
import net.minecraft.tileentity.TileEntity; | ||
|
||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.tree.ClassNode; | ||
import org.objectweb.asm.tree.FieldInsnNode; | ||
import org.objectweb.asm.tree.InsnList; | ||
import org.objectweb.asm.tree.InsnNode; | ||
import org.objectweb.asm.tree.JumpInsnNode; | ||
import org.objectweb.asm.tree.LabelNode; | ||
import org.objectweb.asm.tree.MethodInsnNode; | ||
import org.objectweb.asm.tree.MethodNode; | ||
import org.objectweb.asm.tree.VarInsnNode; | ||
|
||
import cpw.mods.fml.common.FMLLog; | ||
import cpw.mods.fml.relauncher.IClassTransformer; | ||
|
||
public class TransformBlockBreaker implements IClassTransformer { | ||
|
||
@Override | ||
public byte[] transform(String name, byte[] bytes) { | ||
if(name.equals("com.eloraam.redpower.machine.TileBreaker")) { | ||
return handleBreakerTransform(bytes); | ||
} | ||
return bytes; | ||
} | ||
|
||
private byte[] handleBreakerTransform(byte[] bytes) { | ||
|
||
ClassNode classNode = new ClassNode(); | ||
ClassReader classReader = new ClassReader(bytes); | ||
classReader.accept(classNode, 0); | ||
|
||
Iterator<MethodNode> methods = classNode.methods.iterator(); | ||
while(methods.hasNext()) { | ||
MethodNode method = methods.next(); | ||
if(method.name.equals("onBlockNeighborChange")) { | ||
LabelNode l0 = new LabelNode(); | ||
LabelNode l1 = new LabelNode(); | ||
LabelNode l2 = new LabelNode(); | ||
InsnList toInject = new InsnList(); | ||
toInject.add(l0); | ||
toInject.add(new VarInsnNode(ALOAD, 0)); //this | ||
toInject.add(new VarInsnNode(ALOAD, 0)); //this | ||
toInject.add(new FieldInsnNode(GETFIELD, "com/eloraam/redpower/machine/TileBreaker", "Rotation", "I")); | ||
toInject.add(new MethodInsnNode(INVOKESTATIC, | ||
"com/skcraft/alicefixes/TransformBlockBreaker", | ||
"canMine", | ||
"(L" + ObfNames.TILE_ENTITY + ";I)Z")); //Invoke canMine() in this class | ||
toInject.add(new JumpInsnNode(IFNE, l1)); //if statement | ||
toInject.add(l2); | ||
toInject.add(new InsnNode(RETURN)); | ||
toInject.add(l1); | ||
|
||
method.instructions.insertBefore(method.instructions.getFirst(), toInject); //insert before first instruction | ||
FMLLog.log(Level.INFO, "Block Breaker successfully patched!"); | ||
break; | ||
} | ||
} | ||
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); | ||
classNode.accept(writer); | ||
return writer.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; | ||
} | ||
} |
Oops, something went wrong.