Skip to content

Commit

Permalink
Revert "trying to fix resource loading"
Browse files Browse the repository at this point in the history
This reverts commit 5c3b38b.
  • Loading branch information
thecatcore committed May 26, 2023
1 parent 04728f3 commit 0678c19
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 45 deletions.
67 changes: 29 additions & 38 deletions src/main/java/org/dimdev/rift/mixin/core/MixinVanillaPack.java
Original file line number Diff line number Diff line change
@@ -1,61 +1,52 @@
package org.dimdev.rift.mixin.core;

import net.minecraft.resources.FolderPack;
import net.minecraft.resources.ResourcePackType;
import net.minecraft.resources.VanillaPack;
import net.minecraft.util.ResourceLocation;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

import java.io.File;
import javax.annotation.Nullable;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.nio.file.Files;
import java.nio.file.Path;

@Mixin(VanillaPack.class)
public class MixinVanillaPack {
@Shadow public static Path field_14196;

/**
* @reason Give priority to resources in the Minecraft jar to avoid them
* from being overwritten by mods.
* @author Runemoro, InsomniaKitten, Cat Core
* @author Runemoro, InsomniaKitten
*/
@Inject(method = "method_14416", at = @At("HEAD"), cancellable = true)
private void findInputStream(ResourcePackType resourceType, ResourceLocation identifier, CallbackInfoReturnable<InputStream> callback) {
if (VanillaPack.field_14196 != null) {
// Fall through to Vanilla logic, they have a special case here.
return;
}

String path = resourceType.getDirectoryName() + "/" + identifier.getNamespace() + "/" + identifier.getPath();
URL found = null;

try {
Enumeration<URL> candidates = VanillaPack.class.getClassLoader().getResources(path);

// Get the last element
while (candidates.hasMoreElements()) {
found = candidates.nextElement();
@Overwrite
@Nullable
protected @org.jetbrains.annotations.Nullable InputStream method_14416(ResourcePackType type, ResourceLocation location) {
String pathString = type.getDirectoryName() + "/" + location.getNamespace() + "/" + location.getPath();

if (field_14196 != null) {
Path path = field_14196.resolve(pathString);
if (Files.exists(path)) {
try {
return Files.newInputStream(path);
} catch (IOException ignored) {}
}

if (found == null || !FolderPack.method_14402(new File(found.getFile()), "/" + path)) {
// Mimics vanilla behavior

callback.setReturnValue(null);
return;
}
} catch (IOException var6) {
// Default path
}

try {
if (found != null) {
callback.setReturnValue(found.openStream());
}
} catch (Exception e) {
// Default path
}
URL rootMarker = VanillaPack.class.getResource("/" + type.getDirectoryName() + "/.mcassetsroot");
String root = rootMarker.toString().substring(0, rootMarker.toString().length() - ".mcassetsroot".length());
String path = location.getNamespace() + "/" + location.getPath();
return new URL(root + path).openStream();
} catch (IOException ignored) {}

// Realms and Optifine just add resources to the classpath. If no resources were
// found in the Minecraft jar, fall back to looking on the classpath. Duplicates
// will be handled by the classpath order.
return VanillaPack.class.getResourceAsStream("/" + type.getDirectoryName() + "/" + location.getNamespace() + "/" + location.getPath());
}
}
7 changes: 0 additions & 7 deletions src/main/java/org/dimdev/riftloader/RiftLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import fr.catcore.modremapperapi.utils.Constants;
import net.fabricmc.loader.api.FabricLoader;
//import net.minecraft.launchwrapper.Launch;
import net.fabricmc.loader.impl.launch.FabricLauncherBase;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dimdev.accesstransform.AccessTransformationSet;
Expand All @@ -24,7 +23,6 @@
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
Expand Down Expand Up @@ -202,11 +200,6 @@ private void initMods() {
private static void addURLToClasspath(URL url) {
ReflectionUtils.addURLToClasspath(url);
// Launch.classLoader.addURL(url);
try {
FabricLauncherBase.getLauncher().addToClassPath(new File(url.toURI()).toPath());
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}

private void initAccessTransformer() {
Expand Down

0 comments on commit 0678c19

Please sign in to comment.