forked from modmuss50/OptiFabric
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Aiming to fix Andrews54757#15 Gets into the world, but seems to have trouble still with synced IDs
- Loading branch information
Showing
5 changed files
with
111 additions
and
7 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
45 changes: 45 additions & 0 deletions
45
src/main/java/me/modmuss50/optifabric/compat/multiconnect/MulticonnectMixinPlugin.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,45 @@ | ||
package me.modmuss50.optifabric.compat.multiconnect; | ||
|
||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.ClassNode; | ||
import org.objectweb.asm.tree.InsnList; | ||
import org.objectweb.asm.tree.InsnNode; | ||
import org.objectweb.asm.tree.JumpInsnNode; | ||
import org.objectweb.asm.tree.LabelNode; | ||
import org.objectweb.asm.tree.MethodInsnNode; | ||
import org.objectweb.asm.tree.MethodNode; | ||
|
||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo; | ||
|
||
import me.modmuss50.optifabric.compat.InterceptingMixinPlugin; | ||
import me.modmuss50.optifabric.util.RemappingUtils; | ||
|
||
public class MulticonnectMixinPlugin extends InterceptingMixinPlugin { | ||
@Override | ||
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { | ||
if ("ModelLoaderMixin".equals(mixinInfo.getName())) {//ResourceManager, BlockColors, Profiler | ||
//String constructorDesc = RemappingUtils.mapMethodDescriptor("(Lnet/minecraft/class_3300;Lnet/minecraft/class_324;Lnet/minecraft/class_3695;I)V"); | ||
String defaultedRegistry = RemappingUtils.getClassName("class_2348"); | ||
String getIds = RemappingUtils.getMethodName("class_2378", "method_10235", "()Ljava/util/Set;"); | ||
|
||
for (MethodNode method : targetClass.methods) { | ||
if ("<init>".equals(method.name)) {//Multiconnect does this to all constructors... | ||
LabelNode skip = new LabelNode(); | ||
|
||
InsnList extra = new InsnList(); | ||
extra.add(new JumpInsnNode(Opcodes.GOTO, skip)); | ||
extra.add(new InsnNode(Opcodes.ACONST_NULL)); | ||
extra.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, defaultedRegistry, getIds, "()Ljava/util/Set;", false)); | ||
extra.add(new InsnNode(Opcodes.ACONST_NULL)); | ||
extra.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, defaultedRegistry, "iterator", "()Ljava/util/Iterator;", false)); | ||
extra.add(new InsnNode(Opcodes.POP)); | ||
extra.add(skip); | ||
|
||
method.instructions.insertBefore(method.instructions.getLast(), extra); | ||
} | ||
} | ||
} | ||
|
||
super.preApply(targetClassName, targetClass, mixinClassName, mixinInfo); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/me/modmuss50/optifabric/compat/multiconnect/mixin/ModelLoaderMixin.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,36 @@ | ||
package me.modmuss50.optifabric.compat.multiconnect.mixin; | ||
|
||
import java.util.Iterator; | ||
import java.util.Set; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.client.render.model.ModelLoader; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.registry.DefaultedRegistry; | ||
|
||
import me.modmuss50.optifabric.compat.InterceptingMixin; | ||
import me.modmuss50.optifabric.compat.Shim; | ||
|
||
@Mixin(ModelLoader.class) | ||
@InterceptingMixin("net/earthcomputer/multiconnect/mixin/bridge/MixinModelLoader") | ||
abstract class ModelLoaderMixin { | ||
@Redirect(method = "processLoading", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/registry/DefaultedRegistry;getIds()Ljava/util/Set;", remap = true), remap = false) | ||
private Set<Identifier> redirectGetIDs(DefaultedRegistry<?> registry) { | ||
return redirectGetIds(registry); | ||
} | ||
|
||
@Shim | ||
private native Set<Identifier> redirectGetIds(DefaultedRegistry<?> registry); | ||
|
||
@Redirect(method = "processLoading", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/registry/DefaultedRegistry;iterator()Ljava/util/Iterator;", remap = true), remap = false) | ||
private Iterator<Block> doRedirectBlockRegistryIterator(DefaultedRegistry<Block> registry) { | ||
return redirectBlockRegistryIterator(registry); | ||
} | ||
|
||
@Shim | ||
private native Iterator<Block> redirectBlockRegistryIterator(DefaultedRegistry<Block> registry); | ||
} |
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
12 changes: 12 additions & 0 deletions
12
src/main/resources/optifabric.compat.multiconnect.mixins.json
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,12 @@ | ||
{ | ||
"required": true, | ||
"package": "me.modmuss50.optifabric.compat.multiconnect.mixin", | ||
"compatibilityLevel": "JAVA_8", | ||
"mixins": [ | ||
"ModelLoaderMixin" | ||
], | ||
"plugin": "me.modmuss50.optifabric.compat.multiconnect.MulticonnectMixinPlugin", | ||
"injectors": { | ||
"defaultRequire": 1 | ||
} | ||
} |