Skip to content

Commit

Permalink
config to disable in-world concrete
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Aug 9, 2021
1 parent 2cd6159 commit 7f557a9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/gregtech/common/ConfigHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ public static class VanillaRecipes {

@Config.Comment("Whether to make vanilla tools and armor recipes harder. Excludes flint and steel, and buckets. Default: false")
public boolean hardToolArmorRecipes = false;

@Config.Comment("Whether to disable the vanilla Concrete from Powder with Water behavior, forcing the GT recipe. Default: false")
public boolean disableConcreteInWorld = false;
}

public static class NanoSaberConfiguration {
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/gregtech/common/asm/ConcretePowderVisitor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package gregtech.common.asm;

import gregtech.common.asm.util.ObfMapping;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

public class ConcretePowderVisitor extends MethodVisitor implements Opcodes {

public static final String TARGET_CLASS_NAME = "net/minecraft/block/BlockConcretePowder";
public static final String TARGET_SIGNATURE = "(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/state/IBlockState;)Z";
public static final ObfMapping TARGET_METHOD = new ObfMapping(TARGET_CLASS_NAME, "tryTouchWater", TARGET_SIGNATURE);

public ConcretePowderVisitor(MethodVisitor mv) {
super(Opcodes.ASM5, mv);
}

@Override
public void visitCode() {
mv.visitInsn(Opcodes.ICONST_0);
mv.visitInsn(Opcodes.IRETURN);
}
}
8 changes: 8 additions & 0 deletions src/main/java/gregtech/common/asm/GTCETransformer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gregtech.common.asm;

import gregtech.common.ConfigHolder;
import gregtech.common.asm.util.TargetClassVisitor;
import net.minecraft.launchwrapper.IClassTransformer;
import org.objectweb.asm.ClassReader;
Expand All @@ -16,6 +17,13 @@ public byte[] transform(String name, String transformedName, byte[] basicClass)
ClassWriter classWriter = new ClassWriter(0);
classReader.accept(new TargetClassVisitor(classWriter, JEIVisitor.TARGET_METHOD, JEIVisitor::new), 0);
return classWriter.toByteArray();
} else if (internalName.equals(ConcretePowderVisitor.TARGET_CLASS_NAME)) {
if (ConfigHolder.vanillaRecipes.disableConcreteInWorld) {
ClassReader classReader = new ClassReader(basicClass);
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
classReader.accept(new TargetClassVisitor(classWriter, ConcretePowderVisitor.TARGET_METHOD, ConcretePowderVisitor::new), 0);
return classWriter.toByteArray();
}
}
return basicClass;
}
Expand Down

0 comments on commit 7f557a9

Please sign in to comment.