-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to prevent Thaumcraft Taint Biome spread.
- Loading branch information
Showing
3 changed files
with
100 additions
and
0 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
69 changes: 69 additions & 0 deletions
69
src/main/java/myessentials/classtransformers/BlockTaintFibersTransformer.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,69 @@ | ||
package myessentials.classtransformers; | ||
|
||
import net.minecraft.launchwrapper.IClassTransformer; | ||
import net.minecraft.world.World; | ||
|
||
import org.objectweb.asm.*; | ||
import org.objectweb.asm.commons.GeneratorAdapter; | ||
|
||
/** | ||
* Patches BlockTaintFibers to add a hook for the {@link myessentials.event.ModifyBlockEvent}. | ||
* <br/> | ||
* | ||
*/ | ||
public class BlockTaintFibersTransformer implements IClassTransformer { | ||
|
||
private class BlockTaintFibersGeneratorAdapter extends GeneratorAdapter { | ||
|
||
protected BlockTaintFibersGeneratorAdapter(MethodVisitor mv, int access, String name, String desc) { | ||
super(Opcodes.ASM4, mv, access, name, desc); | ||
} | ||
|
||
@Override | ||
public void visitJumpInsn(int opcode, Label label) { | ||
super.visitJumpInsn(opcode, label); | ||
if(opcode == Opcodes.IF_ICMPLT) { | ||
super.visitVarInsn(Opcodes.ALOAD, 0); | ||
super.visitVarInsn(Opcodes.ILOAD, 1); | ||
super.visitVarInsn(Opcodes.ILOAD, 6); | ||
super.visitInsn(Opcodes.IADD); | ||
super.visitVarInsn(Opcodes.ILOAD, 3); | ||
super.visitVarInsn(Opcodes.ILOAD, 7); | ||
super.visitInsn(Opcodes.IADD); | ||
super.visitMethodInsn(Opcodes.INVOKESTATIC, "myessentials/event/ModifyBiomeEvent", "checkBiome", "(Lnet/minecraft/world/World;II)Z", false); | ||
|
||
Label elseLabel = new Label(); | ||
super.visitJumpInsn(Opcodes.IFEQ, elseLabel); | ||
super.visitInsn(Opcodes.RETURN); | ||
super.visitLabel(elseLabel); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public byte[] transform(String name, String srgName, byte[] bytes) { | ||
if("thaumcraft.common.blocks.BlockTaintFibres".equals(srgName)) { | ||
ClassReader reader = new ClassReader(bytes); | ||
ClassWriter writer = new ClassWriter(reader, Opcodes.ASM4); | ||
|
||
ClassVisitor visitor = new ClassVisitor(Opcodes.ASM4, writer) { | ||
@Override | ||
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { | ||
MethodVisitor methodVisitor = super.visitMethod(access, name, desc, signature, exceptions); | ||
|
||
if("taintBiomeSpread".equals(name)) { | ||
return new BlockTaintFibersGeneratorAdapter(methodVisitor, access, name, desc); | ||
} | ||
|
||
return methodVisitor; | ||
} | ||
}; | ||
|
||
reader.accept(visitor, ClassReader.EXPAND_FRAMES); | ||
|
||
bytes = writer.toByteArray(); | ||
} | ||
|
||
return bytes; | ||
} | ||
} |
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,30 @@ | ||
package myessentials.event; | ||
|
||
import cpw.mods.fml.common.eventhandler.Cancelable; | ||
import cpw.mods.fml.common.eventhandler.Event; | ||
import net.minecraft.block.Block; | ||
import net.minecraftforge.common.MinecraftForge; | ||
import net.minecraft.world.World; | ||
|
||
/** | ||
* Fired when a biome is about to be modified. | ||
* If the event is canceled the biome is not modified. | ||
*/ | ||
@Cancelable | ||
public class ModifyBiomeEvent extends Event | ||
{ | ||
public final int x; | ||
public final int z; | ||
public final World world; | ||
|
||
public ModifyBiomeEvent(World world, int x, int z) { | ||
this.x = x; | ||
this.z = z; | ||
this.world = world; | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static boolean checkBiome(World world, int x, int z) { | ||
return MinecraftForge.EVENT_BUS.post(new ModifyBiomeEvent(world, x, z)); | ||
} | ||
} |