Skip to content

Commit

Permalink
Fix remap
Browse files Browse the repository at this point in the history
  • Loading branch information
wdog5734 committed Oct 17, 2024
1 parent e00f49e commit d8a1fcb
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.impl.transformer.FabricTransformer;
import org.objectweb.asm.ClassReader;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.mixin.transformer.IMixinTransformer;

import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -43,16 +45,18 @@ public void connect() throws IOException {
byte[] bytes = ByteStreams.toByteArray(url.openStream());
String className = new ClassReader(bytes).getClassName();
if (className.startsWith("net/minecraft/") || className.equals("com/mojang/brigadier/tree/CommandNode")) {
String handledName = className.replace('/', '.');
try {
bytes = FabricTransformer.transform(false, EnvType.SERVER, handledName, bytes);
} catch (Throwable e) {
throw new IOException(e);
}
bytes = fabricRemapClass(bytes);
}
this.array = Remapper.getResourceMapper().remapClassFile(bytes, GlobalClassRepo.INSTANCE);
}

public byte[] fabricRemapClass(byte[] cl) {
var name = new ClassReader(cl).getClassName();
var bytes = FabricTransformer.transform(false, EnvType.SERVER, name.replace('/', '.'), cl);
bytes = ((IMixinTransformer) MixinEnvironment.getCurrentEnvironment().getActiveTransformer()).transformClassBytes(name, name, bytes);
return bytes;
}

@Override
public InputStream getInputStream() throws IOException {
connect();
Expand Down

0 comments on commit d8a1fcb

Please sign in to comment.