aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2021-09-03 10:10:18 +0300
committerSHsuperCM <shsupercm@gmail.com>2021-09-03 10:10:18 +0300
commit8fc272f9596b37e71bf4ff70f5d784a76bdef143 (patch)
treec5abc3158d773ffc94d5c4b79e3423e36d67b491 /src/main/java
parentec20dec8b923ac6fa4c794d4ab2242552b8fc2e7 (diff)
downloadCITResewn-8fc272f9596b37e71bf4ff70f5d784a76bdef143.tar.gz
CITResewn-8fc272f9596b37e71bf4ff70f5d784a76bdef143.tar.bz2
CITResewn-8fc272f9596b37e71bf4ff70f5d784a76bdef143.zip
Fixed path resolution not properly working in sub models
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java4
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CIT.java8
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITArmor.java3
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITElytra.java3
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITItem.java15
5 files changed, 18 insertions, 15 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java
index 78e1a69..e01aec8 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ModelLoaderMixin.java
@@ -139,7 +139,7 @@ public abstract class ModelLoaderMixin {
String originalPath = left.get().getTextureId().getPath();
String[] split = originalPath.split("/");
if (originalPath.startsWith("./") || (split.length > 2 && split[1].equals("cit"))) {
- Identifier resolvedIdentifier = CIT.resolvePath(id, originalPath, ".png", null);
+ Identifier resolvedIdentifier = CIT.resolvePath(id, originalPath, ".png", identifier -> resourceManager.containsResource(identifier));
if (resolvedIdentifier != null)
return Either.left(new SpriteIdentifier(left.get().getAtlasId(), new ResewnTextureIdentifier(resolvedIdentifier)));
}
@@ -151,7 +151,7 @@ public abstract class ModelLoaderMixin {
if (parentId != null) {
String[] parentIdPathSplit = parentId.getPath().split("/");
if (parentId.getPath().startsWith("./") || (parentIdPathSplit.length > 2 && parentIdPathSplit[1].equals("cit"))) {
- parentId = CIT.resolvePath(id, parentId.getPath(), ".json", null);
+ parentId = CIT.resolvePath(id, parentId.getPath(), ".json", identifier -> resourceManager.containsResource(identifier));
if (parentId != null)
((JsonUnbakedModelAccessor) json).setParentId(new ResewnItemModelIdentifier(parentId));
}
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CIT.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CIT.java
index 44b7e80..5c0bcf7 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CIT.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CIT.java
@@ -314,10 +314,10 @@ public abstract class CIT {
* It will first try using definedPath as an absolute path, if it cant resolve(or definedPath starts with ./), definedPath will be considered relative. <br>
* Relative paths support going to parent directories using "..".
*/
- public static Identifier resolvePath(Identifier propertyIdentifier, String path, String extension, ResourcePack pack) {
+ public static Identifier resolvePath(Identifier propertyIdentifier, String path, String extension, Predicate<Identifier> packContains) {
if (path == null) {
Identifier pathIdentifier = new Identifier(propertyIdentifier.getNamespace(), propertyIdentifier.getPath().replace(".properties", extension));
- return pack == null || pack.contains(ResourceType.CLIENT_RESOURCES, pathIdentifier) ? pathIdentifier : null;
+ return packContains.test(pathIdentifier) ? pathIdentifier : null;
}
Identifier pathIdentifier = new Identifier(path);
@@ -330,7 +330,7 @@ public abstract class CIT {
path = path.substring(2);
else if (!path.contains("..")) {
pathIdentifier = new Identifier(pathIdentifier.getNamespace(), path);
- if (pack == null || pack.contains(ResourceType.CLIENT_RESOURCES, pathIdentifier))
+ if (packContains.test(pathIdentifier))
return pathIdentifier;
}
@@ -352,7 +352,7 @@ public abstract class CIT {
pathIdentifier = new Identifier(propertyIdentifier.getNamespace(), path);
- return pack == null || pack.contains(ResourceType.CLIENT_RESOURCES, pathIdentifier) ? pathIdentifier : null;
+ return packContains.test(pathIdentifier) ? pathIdentifier : null;
}
/**
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITArmor.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITArmor.java
index 794167c..49a7d7b 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITArmor.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITArmor.java
@@ -2,6 +2,7 @@ package shcm.shsupercm.fabric.citresewn.pack.cits;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.Item;
+import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import shcm.shsupercm.fabric.citresewn.ex.CITParseException;
@@ -23,7 +24,7 @@ public class CITArmor extends CIT {
for (Object o : properties.keySet())
if (o instanceof String property && property.startsWith("texture.")) {
- Identifier textureIdentifier = resolvePath(identifier, properties.getProperty(property), ".png", pack.resourcePack);
+ Identifier textureIdentifier = resolvePath(identifier, properties.getProperty(property), ".png", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id));
if (textureIdentifier == null)
throw new Exception("Cannot resolve path for " + property);
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITElytra.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITElytra.java
index 8c5bea8..aa092b3 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITElytra.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITElytra.java
@@ -1,5 +1,6 @@
package shcm.shsupercm.fabric.citresewn.pack.cits;
+import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
import shcm.shsupercm.fabric.citresewn.ex.CITParseException;
import shcm.shsupercm.fabric.citresewn.pack.CITPack;
@@ -12,7 +13,7 @@ public class CITElytra extends CIT {
public CITElytra(CITPack pack, Identifier identifier, Properties properties) throws CITParseException {
super(pack, identifier, properties);
try {
- textureIdentifier = resolvePath(identifier, properties.getProperty("texture"), ".png", pack.resourcePack);
+ textureIdentifier = resolvePath(identifier, properties.getProperty("texture"), ".png", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id));
if (textureIdentifier == null)
throw new Exception("Cannot resolve texture");
} catch (Exception e) {
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITItem.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITItem.java
index 397f4a6..68eccea 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITItem.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITItem.java
@@ -11,6 +11,7 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceManager;
+import net.minecraft.resource.ResourceType;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
@@ -44,18 +45,18 @@ public class CITItem extends CIT {
throw new Exception("CIT must target at least one item type");
String modelProp = properties.getProperty("model");
- Identifier assetIdentifier = resolvePath(identifier, modelProp, ".json", pack.resourcePack);
+ Identifier assetIdentifier = resolvePath(identifier, modelProp, ".json", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id));
if (assetIdentifier != null)
assetIdentifiers.put(null, assetIdentifier);
else if (modelProp != null && !modelProp.startsWith("models")) {
- assetIdentifier = resolvePath(identifier, "models/" + modelProp, ".json", pack.resourcePack);
+ assetIdentifier = resolvePath(identifier, "models/" + modelProp, ".json", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id));
if (assetIdentifier != null)
assetIdentifiers.put(null, assetIdentifier);
}
for (Object o : properties.keySet())
if (o instanceof String property && property.startsWith("model.")) {
- Identifier subIdentifier = resolvePath(identifier, properties.getProperty(property), ".json", pack.resourcePack);
+ Identifier subIdentifier = resolvePath(identifier, properties.getProperty(property), ".json", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id));
if (subIdentifier == null)
throw new Exception("Cannot resolve path for " + property);
@@ -66,13 +67,13 @@ public class CITItem extends CIT {
if (assetIdentifiers.size() == 0) {
isTexture = true;
- assetIdentifier = resolvePath(identifier, properties.getProperty("texture"), ".png", pack.resourcePack);
+ assetIdentifier = resolvePath(identifier, properties.getProperty("texture"), ".png", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id));
if (assetIdentifier != null)
assetIdentifiers.put(null, assetIdentifier);
for (Object o : properties.keySet())
if (o instanceof String property && property.startsWith("texture.")) {
- Identifier subIdentifier = resolvePath(identifier, properties.getProperty(property), ".png", pack.resourcePack);
+ Identifier subIdentifier = resolvePath(identifier, properties.getProperty(property), ".png", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id));
if (subIdentifier == null)
throw new Exception("Cannot resolve path for " + property);
@@ -166,7 +167,7 @@ public class CITItem extends CIT {
String originalPath = left.get().getTextureId().getPath();
String[] split = originalPath.split("/");
if (originalPath.startsWith("./") || (split.length > 2 && split[1].equals("cit"))) {
- Identifier resolvedIdentifier = CIT.resolvePath(identifier, originalPath, ".png", pack.resourcePack);
+ Identifier resolvedIdentifier = CIT.resolvePath(identifier, originalPath, ".png", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id));
if (resolvedIdentifier != null)
return Either.left(new SpriteIdentifier(left.get().getAtlasId(), new ResewnTextureIdentifier(resolvedIdentifier)));
}
@@ -178,7 +179,7 @@ public class CITItem extends CIT {
if (parentId != null) {
String[] parentIdPathSplit = parentId.getPath().split("/");
if (parentId.getPath().startsWith("./") || (parentIdPathSplit.length > 2 && parentIdPathSplit[1].equals("cit"))) {
- parentId = resolvePath(identifier, parentId.getPath(), ".json", pack.resourcePack);
+ parentId = resolvePath(identifier, parentId.getPath(), ".json", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id));
if (parentId != null)
((JsonUnbakedModelAccessor) json).setParentId(new ResewnItemModelIdentifier(parentId));
}