Skip to content

Commit

Permalink
fix(primalcore): stop crash from dropping a torch into a barrel
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-kirby committed Nov 20, 2024
1 parent 568e77b commit 90e8f3f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version_base = 1.15.0
version_base = 1.16.0

# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
# This is required to provide enough memory for the Minecraft decompilation process.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public class SevPatchesLoadingPlugin implements IFMLLoadingPlugin {
public static String GRAB_MOUSE_CURSOR;
public static String UNGRAB_MOUSE_CURSOR;

public static String ENTITY_ON_ENTITY_COLLISION;
public static String ITEMSTACK_IS_ITEM_EQUAL;

public SevPatchesLoadingPlugin() {
LOGGER.info("setting up mixin environment");
MixinBootstrap.init();
Expand Down Expand Up @@ -135,6 +138,9 @@ public void injectData(Map<String, Object> data) {

SevPatchesLoadingPlugin.GRAB_MOUSE_CURSOR = dev ? "grabMouseCursor" : "a";
SevPatchesLoadingPlugin.UNGRAB_MOUSE_CURSOR = dev ? "ungrabMouseCursor" : "b";

SevPatchesLoadingPlugin.ENTITY_ON_ENTITY_COLLISION = dev ? "onEntityCollision" : "func_180634_a";
SevPatchesLoadingPlugin.ITEMSTACK_IS_ITEM_EQUAL = dev ? "isItemEqual" : "func_77969_a";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public byte[] transform(String name, String transformedName, byte[] basicClass)
return new PatchPrimalNicerHammerHeads(basicClass).apply();
case "nmd.primal.core.common.entities.living.EntityCanisCampestris":
return new PatchPrimalScaredyCat(basicClass).apply();
case "nmd.primal.core.common.blocks.machines.Barrel":
return new PatchPrimalBarrel(basicClass).apply();
case "realdrops.handlers.EventHandler":
return new PatchRidHandlerDeregister(basicClass).apply();
case "tehnut.harvest.ReplantHandlers":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected boolean patch() {
for (MethodNode method : classNode.methods) {
InsnList insnList = method.instructions;
Iterable<AbstractInsnNode> insnsIter = insnList::iterator;
Stream<AbstractInsnNode> insns = StreamSupport.stream(insnsIter.spliterator(), true);
Stream<AbstractInsnNode> insns = StreamSupport.stream(insnsIter.spliterator(), false);

insns.filter(insn -> insn instanceof MethodInsnNode)
.map(insn -> (MethodInsnNode) insn)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package tv.darkosto.sevpatches.core.patches;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;
import tv.darkosto.sevpatches.core.SevPatchesLoadingPlugin;
import tv.darkosto.sevpatches.core.utils.AsmUtils;

import java.util.Optional;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

public class PatchPrimalBarrel extends Patch {
public PatchPrimalBarrel(byte[] inputClass) {
super(inputClass);
}

@Override
protected boolean patch() {
MethodNode onEntityCollision = AsmUtils.findMethod(this.classNode, SevPatchesLoadingPlugin.ENTITY_ON_ENTITY_COLLISION);
if (onEntityCollision == null) return false;

InsnList insns = onEntityCollision.instructions;
Iterable<AbstractInsnNode> insnsIter = insns::iterator;
Stream<AbstractInsnNode> nodes = StreamSupport.stream(insnsIter.spliterator(), false);

Optional<MethodInsnNode> targetOpt = nodes.filter(node -> node instanceof MethodInsnNode)
.map(node -> (MethodInsnNode) node)
.filter(invoke -> invoke.owner.equals("net/minecraft/item/ItemStack") && invoke.name.equals(SevPatchesLoadingPlugin.ITEMSTACK_IS_ITEM_EQUAL))
.findFirst();

if (!targetOpt.isPresent()) return false;
MethodInsnNode target = targetOpt.get();

InsnList newCondition = new InsnList();
newCondition.add(new VarInsnNode(Opcodes.ALOAD, 13));
newCondition.add(new TypeInsnNode(Opcodes.INSTANCEOF, "nmd/primal/core/common/compat/vanilla/VanillaTorchItem"));
newCondition.add(new InsnNode(Opcodes.IAND));

onEntityCollision.instructions.insert(target, newCondition);

return true;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/mcmod.info
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"modid": "sevpatches",
"name": "SevPatches",
"description": "Consolidated patches for mods that are EOL used in SevTech: Ages",
"version": "1.14.1",
"version": "1.16.0",
"mcversion": "1.12.2",
"url": "https://www.curseforge.com/minecraft/mc-mods/sevpatches",
"updateUrl": "",
Expand Down

0 comments on commit 90e8f3f

Please sign in to comment.