-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(primalcore): stop crash from dropping a torch into a barrel
- Loading branch information
Showing
6 changed files
with
54 additions
and
3 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
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
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
43 changes: 43 additions & 0 deletions
43
src/main/java/tv/darkosto/sevpatches/core/patches/PatchPrimalBarrel.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,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; | ||
} | ||
} |
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