Skip to content

Commit 0f64cf9

Browse files
committed
[resource loader] fix direct path resources not working from default resource pack
1 parent bc2b616 commit 0f64cf9

10 files changed

Lines changed: 152 additions & 36 deletions

File tree

libraries/resource-loader/resource-loader-mc1.8.2-pre5-mc1.12.2/src/main/java/net/ornithemc/osl/resource/loader/impl/ResourceLoaderMixinPlugin.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
3131
if ("net.ornithemc.osl.resource.loader.impl.mixin.client.LegacyResourcePackAccess".equals(mixinClassName)) {
3232
return MinecraftVersion.resolve().compareTo("16w32a") >= 0;
3333
}
34+
if ("net.ornithemc.osl.resource.loader.impl.mixin.client.BuiltInResourcePackMixinNew".equals(mixinClassName)) {
35+
return MinecraftVersion.resolve().compareTo("16w32b") >= 0;
36+
}
37+
if ("net.ornithemc.osl.resource.loader.impl.mixin.client.BuiltInResourcePackMixinOld".equals(mixinClassName)) {
38+
return MinecraftVersion.resolve().compareTo("16w32b") < 0;
39+
}
3440

3541
return true;
3642
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package net.ornithemc.osl.resource.loader.impl.adapter;
2+
3+
import net.minecraft.resource.Identifier;
4+
5+
/**
6+
* Path-only Identifier impl for accessing direct-path resources from the jar and the assets index.
7+
*/
8+
public class FilePathIdentifier extends Identifier {
9+
10+
public FilePathIdentifier(String path) {
11+
super(path);
12+
}
13+
14+
@Override
15+
public String toString() {
16+
return this.getPath();
17+
}
18+
}

libraries/resource-loader/resource-loader-mc1.8.2-pre5-mc1.12.2/src/main/java/net/ornithemc/osl/resource/loader/impl/adapter/WrappedResourcePack.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private boolean hasResourceFromPack(net.minecraft.client.resource.pack.ResourceP
5252
if (ResourcePacks.getSupportedFormat() > 2 && pack instanceof LegacyResourcePack) {
5353
return this.hasResourceFromPack(((LegacyResourcePackAccess) pack).accessPack(), path);
5454
} else if (pack instanceof BuiltInResourcePack) {
55-
return ((BuiltInResourcePack) pack).hasResource(new PathIdentifier(path))
55+
return ((BuiltInResourcePack) pack).hasResource(new FilePathIdentifier(path))
5656
|| ((BuiltInResourcePack) pack).hasResource(new Identifier(path));
5757
} else if (pack instanceof CustomResourcePack) {
5858
return ((CustomResourcePackAccess) pack).invokeHasResource(path);
@@ -72,8 +72,8 @@ private InputStream getResourceFromPack(net.minecraft.client.resource.pack.Resou
7272
if (ResourcePacks.getSupportedFormat() > 2 && pack instanceof LegacyResourcePack) {
7373
return this.getResourceFromPack(((LegacyResourcePackAccess) pack).accessPack(), path);
7474
} else if (pack instanceof BuiltInResourcePack) {
75-
return ((BuiltInResourcePack) pack).hasResource(new PathIdentifier(path))
76-
? ((BuiltInResourcePack) pack).getResource(new PathIdentifier(path))
75+
return ((BuiltInResourcePack) pack).hasResource(new FilePathIdentifier(path))
76+
? ((BuiltInResourcePack) pack).getResource(new FilePathIdentifier(path))
7777
: ((BuiltInResourcePack) pack).getResource(new Identifier(path));
7878
} else if (pack instanceof CustomResourcePack) {
7979
return ((CustomResourcePackAccess) pack).invokeOpenResource(path);
@@ -136,19 +136,4 @@ private void findResourcesInPack(net.minecraft.client.resource.pack.ResourcePack
136136
((ResourcePackAdapter) pack).pack.findResources(type, namespace, directory, consumer);
137137
}
138138
}
139-
140-
/**
141-
* Path-only Identifier impl for accessing direct-path resources from the assets index.
142-
*/
143-
private static class PathIdentifier extends Identifier {
144-
145-
private PathIdentifier(String path) {
146-
super(path);
147-
}
148-
149-
@Override
150-
public String toString() {
151-
return this.getPath();
152-
}
153-
}
154139
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package net.ornithemc.osl.resource.loader.impl.mixin.client;
2+
3+
import org.spongepowered.asm.mixin.Mixin;
4+
import org.spongepowered.asm.mixin.injection.At;
5+
import org.spongepowered.asm.mixin.injection.At.Shift;
6+
import org.spongepowered.asm.mixin.injection.ModifyVariable;
7+
8+
import com.llamalad7.mixinextras.sugar.Local;
9+
10+
import net.minecraft.client.resource.pack.BuiltInResourcePack;
11+
import net.minecraft.resource.Identifier;
12+
13+
import net.ornithemc.osl.resource.loader.impl.adapter.FilePathIdentifier;
14+
15+
@Mixin(BuiltInResourcePack.class)
16+
public class BuiltInResourcePackMixinNew {
17+
18+
@ModifyVariable(
19+
method = "openResource",
20+
at = @At(
21+
value = "INVOKE",
22+
target = "Ljava/lang/Class;getResource(Ljava/lang/String;)Ljava/net/URL;",
23+
shift = Shift.BEFORE // shift to before the try { } block
24+
)
25+
)
26+
private String osl$resource_loader$getResourceFromFilePathIdentifier(String path, @Local Identifier location) {
27+
if (location instanceof FilePathIdentifier) {
28+
path = "/" + location.toString();
29+
}
30+
31+
return path;
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package net.ornithemc.osl.resource.loader.impl.mixin.client;
2+
3+
import java.io.InputStream;
4+
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.injection.At;
7+
8+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
9+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
10+
import com.llamalad7.mixinextras.sugar.Local;
11+
12+
import net.minecraft.client.resource.pack.BuiltInResourcePack;
13+
import net.minecraft.resource.Identifier;
14+
15+
import net.ornithemc.osl.resource.loader.impl.adapter.FilePathIdentifier;
16+
17+
@Mixin(BuiltInResourcePack.class)
18+
public class BuiltInResourcePackMixinOld {
19+
20+
@WrapOperation(
21+
method = "openResource",
22+
at = @At(
23+
value = "INVOKE",
24+
target = "Ljava/lang/Class;getResourceAsStream(Ljava/lang/String;)Ljava/io/InputStream;"
25+
)
26+
)
27+
private InputStream osl$resource_loader$getResourceFromFilePathIdentifier(Class<?> cls, String path, Operation<InputStream> op, @Local Identifier location) {
28+
if (location instanceof FilePathIdentifier) {
29+
path = "/" + location.toString();
30+
}
31+
32+
return op.call(cls, path);
33+
}
34+
}

libraries/resource-loader/resource-loader-mc1.8.2-pre5-mc1.12.2/src/main/resources/osl.resource-loader.mixins.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
"common.CraftingManagerMixin"
1010
],
1111
"client": [
12+
"client.BuiltInResourcePackMixinNew",
13+
"client.BuiltInResourcePackMixinOld",
1214
"client.CustomResourcePackAccess",
1315
"client.LegacyResourcePackAccess",
1416
"client.MinecraftMixin",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package net.ornithemc.osl.resource.loader.impl.adapter;
2+
3+
import net.minecraft.resource.Identifier;
4+
5+
/**
6+
* Path-only Identifier impl for accessing direct-path resources from the jar and the assets index.
7+
*/
8+
public class FilePathIdentifier extends Identifier {
9+
10+
public FilePathIdentifier(String path) {
11+
super(path);
12+
}
13+
14+
@Override
15+
public String toString() {
16+
return this.getPath();
17+
}
18+
}

libraries/resource-loader/resource-loader-mc13w26a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/resource/loader/impl/adapter/WrappedResourcePack.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public boolean hasResource(String path) {
4848

4949
private boolean hasResourceFromPack(net.minecraft.client.resource.pack.ResourcePack pack, String path) {
5050
if (pack instanceof BuiltInResourcePack) {
51-
return ((BuiltInResourcePack) pack).hasResource(new PathIdentifier(path))
51+
return ((BuiltInResourcePack) pack).hasResource(new FilePathIdentifier(path))
5252
|| ((BuiltInResourcePack) pack).hasResource(new Identifier(path));
5353
} else if (pack instanceof CustomResourcePack) {
5454
return ((CustomResourcePackAccess) pack).invokeHasResource(path);
@@ -66,8 +66,8 @@ public InputStream getResource(String path) throws IOException {
6666

6767
private InputStream getResourceFromPack(net.minecraft.client.resource.pack.ResourcePack pack, String path) throws IOException {
6868
if (pack instanceof BuiltInResourcePack) {
69-
return ((BuiltInResourcePack) pack).hasResource(new PathIdentifier(path))
70-
? ((BuiltInResourcePack) pack).getResource(new PathIdentifier(path))
69+
return ((BuiltInResourcePack) pack).hasResource(new FilePathIdentifier(path))
70+
? ((BuiltInResourcePack) pack).getResource(new FilePathIdentifier(path))
7171
: ((BuiltInResourcePack) pack).getResource(new Identifier(path));
7272
} else if (pack instanceof CustomResourcePack) {
7373
return ((CustomResourcePackAccess) pack).invokeOpenResource(path);
@@ -128,19 +128,4 @@ private void findResourcesInPack(net.minecraft.client.resource.pack.ResourcePack
128128
((ResourcePackAdapter) pack).pack.findResources(type, namespace, directory, consumer);
129129
}
130130
}
131-
132-
/**
133-
* Path-only Identifier impl for accessing direct-path resources from the assets index.
134-
*/
135-
private static class PathIdentifier extends Identifier {
136-
137-
private PathIdentifier(String path) {
138-
super(path);
139-
}
140-
141-
@Override
142-
public String toString() {
143-
return this.getPath();
144-
}
145-
}
146131
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package net.ornithemc.osl.resource.loader.impl.mixin.client;
2+
3+
import java.io.InputStream;
4+
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.injection.At;
7+
8+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
9+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
10+
import com.llamalad7.mixinextras.sugar.Local;
11+
12+
import net.minecraft.client.resource.pack.BuiltInResourcePack;
13+
import net.minecraft.resource.Identifier;
14+
15+
import net.ornithemc.osl.resource.loader.impl.adapter.FilePathIdentifier;
16+
17+
@Mixin(BuiltInResourcePack.class)
18+
public class BuiltInResourcePackMixin {
19+
20+
@WrapOperation(
21+
method = "openResource",
22+
at = @At(
23+
value = "INVOKE",
24+
target = "Ljava/lang/Class;getResourceAsStream(Ljava/lang/String;)Ljava/io/InputStream;"
25+
)
26+
)
27+
private InputStream osl$resource_loader$getResourceFromFilePathIdentifier(Class<?> cls, String path, Operation<InputStream> op, @Local Identifier location) {
28+
if (location instanceof FilePathIdentifier) {
29+
path = "/" + location.toString();
30+
}
31+
32+
return op.call(cls, path);
33+
}
34+
}

libraries/resource-loader/resource-loader-mc13w26a-mc1.8.2-pre4/src/main/resources/osl.resource-loader.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"mixins": [
77
],
88
"client": [
9+
"client.BuiltInResourcePackMixin",
910
"client.CustomResourcePackAccess",
1011
"client.MinecraftMixin",
1112
"client.ResourcePacksMixin",

0 commit comments

Comments
 (0)