-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamically change ContainerLevelAccess.create to craftCreate to bypa…
…ss mixins, fixes 'Not supported yet.' errors with containers
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
fmlcore/src/main/java/org/kettingpowered/ketting/patches/ContainerLevelAccess.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,30 @@ | ||
package org.kettingpowered.ketting.patches; | ||
|
||
import io.izzel.arclight.api.PluginPatcher; | ||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.ClassNode; | ||
import org.objectweb.asm.tree.FieldInsnNode; | ||
import org.objectweb.asm.tree.MethodInsnNode; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* This class redirects ContainerLevelAccess.create to craftCreate as mixins can overwrite create and mess up bukkit plugin compatibility | ||
*/ | ||
@SuppressWarnings("unused") | ||
public class ContainerLevelAccess implements PluginPatcher { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger("ContainerLevelAccessPatcher"); | ||
|
||
public void handleClass(ClassNode node, ClassRepo classRepo) { | ||
node.methods.forEach(m -> m.instructions.forEach(i -> { | ||
if (i instanceof MethodInsnNode min) { | ||
if (min.owner.equals("net/minecraft/world/inventory/ContainerLevelAccess") && min.name.equals("m_39289_") && min.desc.equals("(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/inventory/ContainerLevelAccess;")) { | ||
LOGGER.debug("Patching ContainerLevelAccess.create call in {}:{}", node.name, m.name); | ||
m.instructions.insertBefore(min, new MethodInsnNode(Opcodes.INVOKESTATIC, min.owner, "craftCreate", min.desc, true)); | ||
m.instructions.remove(min); | ||
} | ||
} | ||
})); | ||
} | ||
} |