Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
Update to support latest loader (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinolek authored and modmuss50 committed Nov 9, 2019
1 parent c3880b1 commit 9914418
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 78 deletions.
20 changes: 10 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
}
}
dependencies {
classpath "net.fabricmc:fabric-loom:0.2.5-SNAPSHOT"
classpath "net.fabricmc:fabric-loom:0.2.6-SNAPSHOT"
}
}

Expand Down Expand Up @@ -35,24 +35,24 @@ dependencies {
mappings "net.fabricmc:yarn:${project.yarn_mappings}"
modCompile "net.fabricmc:fabric-loader:${project.loader_version}"

modCompile 'net.fabricmc.fabric-api:fabric-api:0.3.0+build.200'
modCompile "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modCompile 'com.github.Chocohead:Fabric-ASM:9af0ebe992'
include 'com.github.Chocohead:Fabric-ASM:9af0ebe992'
modCompile "com.github.Chocohead:Fabric-ASM:${project.fabric_asm_version}"
include "com.github.Chocohead:Fabric-ASM:${project.fabric_asm_version}"

//Used to handle the zip processing
compile 'org.zeroturnaround:zt-zip:1.13'
include 'org.zeroturnaround:zt-zip:1.13'
compile "org.zeroturnaround:zt-zip:${project.zt_zip_version}"
include "org.zeroturnaround:zt-zip:${project.zt_zip_version}"

//Required for zt-zip, kinda annoying
include 'org.slf4j:slf4j-simple:1.7.26'
include 'org.slf4j:slf4j-api:1.7.26'
include "org.slf4j:slf4j-simple:${project.slf4j_version}"
include "org.slf4j:slf4j-api:${project.slf4j_version}"

//Used only in dev to generate the field names
compile ('net.fabricmc:stitch:0.2.1.61') {
compile ("net.fabricmc:stitch:${project.stitch_version}") {
transitive = false
}
include 'net.fabricmc:stitch:0.2.1.61'
include "net.fabricmc:stitch:${project.stitch_version}"
}

task unzip(type: Copy) {
Expand Down
12 changes: 9 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
org.gradle.jvmargs=-Xmx1G

minecraft_version=1.14.4
yarn_mappings=1.14.4+build.2
loader_version=0.4.8+build.155
yarn_mappings=1.14.4+build.14
loader_version=0.6.4+build.169

mod_version = 0.5.2
fabric_version=0.4.1+build.245-1.14
fabric_asm_version=697a7c18da
zt_zip_version=1.13
slf4j_version=1.7.29
stitch_version=0.3.0.66

mod_version = 0.5.3
maven_group = me.modmuss50
archives_base_name = optifabric
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import net.fabricmc.indigo.renderer.render.TerrainRenderContext;
import net.minecraft.client.render.chunk.ChunkRendererRegion;
import net.minecraft.util.math.BlockPos;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
Expand All @@ -18,9 +16,6 @@
public abstract class MixinChunkCacheOF implements AccessChunkRendererRegion {
private TerrainRenderContext fabric_renderer;

@Shadow @Final
private ChunkRendererRegion chunkCache;

//This was taken from https://github.com/FabricMC/fabric/blob/master/fabric-renderer-indigo/src/main/java/net/fabricmc/indigo/renderer/mixin/MixinChunkRenderTask.java honesly no idea what it does, but it doesnt crash the game here
@Inject(method = "<init>", at = @At("RETURN"), remap = false)
private void constructor(ChunkRendererRegion chunkCache, BlockPos posFromIn, BlockPos posToIn, int subIn, CallbackInfo info){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class MixinReflectorClass {
private boolean checked;

@Inject(method = "getTargetClass", at = @At("HEAD"), cancellable = true, remap = false)
public void getTargetClass(CallbackInfoReturnable<Class<?>> infoReturnable) {
private void getTargetClass(CallbackInfoReturnable<Class<?>> infoReturnable) {
if (!checked) {//Only check the target if it hasn't been done yet
String name = targetClassName.replaceAll("/", ".");
if (name.startsWith("net.minecraft.launchwrapper") || name.startsWith("net.minecraftforge") || "optifine.OptiFineClassTransformer".equals(name)) {
Expand Down
75 changes: 17 additions & 58 deletions src/main/java/me/modmuss50/optifabric/mod/OptifineSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import net.fabricmc.loader.util.UrlConversionException;
import net.fabricmc.loader.util.UrlUtil;
import net.fabricmc.loader.util.mappings.TinyRemapperMappingsHelper;
import net.fabricmc.mapping.reader.v2.TinyMetadata;
import net.fabricmc.mapping.tree.ClassDef;
import net.fabricmc.mapping.tree.TinyTree;
import net.fabricmc.mappings.*;
import net.fabricmc.stitch.commands.CommandProposeFieldNames;
import net.fabricmc.tinyremapper.IMappingProvider;
Expand Down Expand Up @@ -168,79 +171,35 @@ IMappingProvider createMappings(String from, String to) {
if (fabricLauncher.isDevelopment()) {
try {
File fullMappings = getDevMappings();
return (classMap, fieldMap, methodMap) -> {
RemapUtils.getTinyRemapper(fullMappings, from, to).load(classMap, fieldMap, methodMap);

Map<String, String> extra = new HashMap<>();
Pattern regex = Pattern.compile("(\\w+)\\/(\\w+);;([\\w/;]+)");

for (Entry<String, String> entry : fieldMap.entrySet()) {
if ("CLOUDS".equals(entry.getValue())) {
Matcher matcher = regex.matcher(entry.getKey());
if (!matcher.matches()) throw new IllegalStateException("Couldn't match " + entry.getKey() + " => " + entry.getValue());
extra.put(matcher.group(1) + "/CLOUDS;;" + matcher.group(3), "CLOUDS_OF");
}

if ("renderDistance".equals(entry.getValue())) {
Matcher matcher = regex.matcher(entry.getKey());
if (!matcher.matches()) throw new IllegalStateException("Couldn't match " + entry.getKey() + " => " + entry.getValue());
extra.put(matcher.group(1) + "/renderDistance;;" + matcher.group(3), "renderDistance_OF");
}
}

fieldMap.putAll(extra);
return (out) -> {
RemapUtils.getTinyRemapper(fullMappings, from, to).load(out);
out.acceptField(new IMappingProvider.Member("cyf", "CLOUDS", "Lcxt;"),
"CLOUDS_OF");
out.acceptField(new IMappingProvider.Member("dng", "renderDistance", "I"),
"renderDistance_OF");
};
} catch (Exception e) {
throw new RuntimeException(e);
}
}

//In prod
Mappings mappingsNew = new Mappings() {
private final Mappings mappings = mappingConfiguration.getMappings();
TinyTree mappingsNew = new TinyTree() {
private final TinyTree mappings = mappingConfiguration.getMappings();

This comment has been minimized.

Copy link
@liach

liach Nov 10, 2019

Can just pass the mappingConfiguration.getMappings() to the remapper

This comment has been minimized.

Copy link
@Dinolek

Dinolek Nov 10, 2019

Author Contributor

Right, I didn't notice that it's unused now


@Override
public Collection<String> getNamespaces() {
return mappings.getNamespaces();
public TinyMetadata getMetadata() {
return mappings.getMetadata();
}

@Override
public Collection<ClassEntry> getClassEntries() {
return mappings.getClassEntries();
}

@Override
public Collection<FieldEntry> getFieldEntries() {
Collection<FieldEntry> fields = mappings.getFieldEntries();
List<FieldEntry> extra = new ArrayList<>();

for (FieldEntry field : fields) {
String interName = field.get("intermediary").getName();

//Option#CLOUDS
if ("field_1937".equals(interName)) {
extra.add(namespace -> {
EntryTriple real = field.get(namespace);
return new EntryTriple(real.getOwner(), "official".equals(namespace) ? "CLOUDS" : "CLOUDS_OF", real.getDesc());
});
}

//WorldRenderer#renderDistance
if ("field_4062".equals(interName)) {
extra.add(namespace -> {
EntryTriple real = field.get(namespace);
return new EntryTriple(real.getOwner(), "official".equals(namespace) ? "renderDistance" : "renderDistance_OF", real.getDesc());
});
}
}

fields.addAll(extra);
return fields;
public Map<String, ClassDef> getDefaultNamespaceClassMap() {
return mappings.getDefaultNamespaceClassMap();
}

@Override
public Collection<MethodEntry> getMethodEntries() {
return mappings.getMethodEntries();
public Collection<ClassDef> getClasses() {
return mappings.getClasses();
}
};
return TinyRemapperMappingsHelper.create(mappingsNew, from, to);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private MethodNode findMethod(MethodNode optifineMethod, ClassNode optifineClass
}

@Override
public void load(Map<String, String> classMap, Map<String, String> fieldMap, Map<String, String> methodMap) {
public void load(MappingAcceptor out) {
methodMap.putAll(this.methodMap);
}
}

0 comments on commit 9914418

Please sign in to comment.