mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-02 13:37:45 -05:00
mark Loom 0.2.0, update Mixin library
This commit is contained in:
@@ -25,41 +25,109 @@
|
||||
package net.fabricmc.loom.mixin;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
import org.spongepowered.asm.service.IClassBytecodeProvider;
|
||||
import org.spongepowered.asm.service.mojang.MixinServiceLaunchWrapper;
|
||||
import com.strobel.collections.ImmutableList;
|
||||
import org.spongepowered.asm.lib.ClassReader;
|
||||
import org.spongepowered.asm.lib.tree.ClassNode;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.service.*;
|
||||
import org.spongepowered.asm.util.ReEntranceLock;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
public class MixinServiceGradle extends MixinServiceLaunchWrapper implements IClassBytecodeProvider {
|
||||
|
||||
public class MixinServiceGradle implements IClassBytecodeProvider, IClassProvider, IMixinService {
|
||||
private static List<JarFile> jars = new ArrayList<>();
|
||||
private final ReEntranceLock lock = new ReEntranceLock(1);
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "FabricGradle";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public MixinEnvironment.Phase getInitialPhase() {
|
||||
return MixinEnvironment.Phase.DEFAULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beginPhase() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkEnv(Object bootSource) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReEntranceLock getReEntranceLock() {
|
||||
return lock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IClassProvider getClassProvider() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream getResourceAsStream(String name) {
|
||||
for(JarFile file : jars){
|
||||
for (JarFile file : jars) {
|
||||
ZipEntry entry = file.getEntry(name);
|
||||
if(entry != null){
|
||||
try {
|
||||
InputStream stream = file.getInputStream(entry);
|
||||
return stream;
|
||||
return file.getInputStream(entry);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to read mod file", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.getResourceAsStream(name);
|
||||
|
||||
return getClass().getClassLoader().getResourceAsStream(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerInvalidClass(String className) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClassLoaded(String className) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassRestrictions(String className) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ITransformer> getTransformers() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSideName() {
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
public static void setupModFiles(Set<File> mods, File minecraft) throws IOException {
|
||||
@@ -76,13 +144,48 @@ public class MixinServiceGradle extends MixinServiceLaunchWrapper implements ICl
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getPlatformAgents() {
|
||||
return ImmutableList.of("org.spongepowered.asm.launch.platform.MixinPlatformAgentDefault");
|
||||
}
|
||||
|
||||
public byte[] getClassBytes(String name, String transformedName) throws IOException {
|
||||
InputStream inputStream = getResourceAsStream(name.replace(".", "/") + ".class");
|
||||
byte[] classBytes = ByteStreams.toByteArray(inputStream);
|
||||
inputStream.close();
|
||||
if(classBytes == null){
|
||||
return super.getClassBytes(name, transformedName);
|
||||
}
|
||||
return classBytes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getClassBytes(String name, boolean runTransformers) throws ClassNotFoundException, IOException {
|
||||
return getClassBytes(name, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassNode getClassNode(String name) throws ClassNotFoundException, IOException {
|
||||
ClassReader reader = new ClassReader(getClassBytes(name, name));
|
||||
ClassNode node = new ClassNode();
|
||||
reader.accept(node, 0);
|
||||
return node;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL[] getClassPath() {
|
||||
return new URL[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> findClass(String name) throws ClassNotFoundException {
|
||||
return Class.forName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> findClass(String name, boolean initialize) throws ClassNotFoundException {
|
||||
return Class.forName(name, initialize, getClass().getClassLoader());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> findAgentClass(String name, boolean initialize) throws ClassNotFoundException {
|
||||
return Class.forName(name, initialize, getClass().getClassLoader());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user