Skip to content

Commit

Permalink
Fix Fabric API 0.86.0+ (Chocohead#1179 port)
Browse files Browse the repository at this point in the history
  • Loading branch information
XXMA16 committed Sep 2, 2023
1 parent 6bb9335 commit fa76b17
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class ModMixinFixer {
private final List<IMixinFixer> classFixes = new ArrayList<>();

private ModMixinFixer() {
addFixer(new ModelLoaderBakerImplFixer());
}

public void addFixer(IMixinFixer fixer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package me.modmuss50.optifabric.compat.fix;

import me.modmuss50.optifabric.util.RemappingUtils;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
import org.spongepowered.asm.util.Annotations;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static me.modmuss50.optifabric.compat.fix.ModMixinFixer.addParams;

public class ModelLoaderBakerImplFixer implements IMixinFixer {
@Override
public List<String> getTargets() {
return Collections.singletonList("net/fabricmc/fabric/mixin/client/model/loading/ModelLoaderBakerImplMixin");
}

@Override
public void fix(IMixinInfo mixinInfo, ClassNode mixinNode) {
for (MethodNode method : mixinNode.methods) {
List<String> injectMethod = new ArrayList<>();
String bakeDesc = RemappingUtils.mapMethodDescriptor("(Lnet/minecraft/class_2960;Lnet/minecraft/class_3665;Ljava/util/function/Function;)Lnet/minecraft/class_1087;");
injectMethod.add('L' + RemappingUtils.getClassName("class_1088$class_7778") + ";bake" + bakeDesc); //optifine method
AnnotationNode annotation;
switch (method.name) {
case "invokeModifyBeforeBake":
addParams(method, mixinInfo, "Ljava/util/function/Function;");
//no break is intentional
case "invokeModifyAfterBake":
annotation = InjectionInfo.getInjectorAnnotation(mixinInfo, method);
Annotations.setValue(annotation, "method", injectMethod);
break;
}
}
}

@Override
public boolean shouldUpdateClassInfo() {
return true;
}
}
6 changes: 6 additions & 0 deletions src/main/java/me/modmuss50/optifabric/mod/OptifineSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ private static IMappingProvider createMappings(String from, String to, IMappingP
ClassDef builtChunk = nameToClass.get("net/minecraft/class_846$class_851");
extraFields.put(new Member(rebuildTask.getName(from), "this$1", 'L' + builtChunk.getName(from) + ';'), "field_20839");

ClassDef bakerImpl = nameToClass.get("net/minecraft/class_1088$class_7778");
if (bakerImpl != null) {//Only present in 1.19.3+
ClassDef modelLoader = nameToClass.get("net/minecraft/class_1088");
extraFields.put(new Member(bakerImpl.getName(from), "this$0", 'L' + modelLoader.getName(from) + ';'), "field_40571");
}

ClassDef particleManager = nameToClass.get("net/minecraft/class_702");
particleManager.getFields().stream().filter(field -> "field_3835".equals(field.getName("intermediary"))).forEach(field -> {
extraFields.put(new Member(particleManager.getName(from), field.getName(from), "Ljava/util/Map;"), field.getName(to));
Expand Down

0 comments on commit fa76b17

Please sign in to comment.