aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2021-08-22 17:52:41 +0300
committerSHsuperCM <shsupercm@gmail.com>2021-08-22 17:52:41 +0300
commit9ede90c8610da18ebca8439a09f97f4e79bbe45d (patch)
tree6468646cd482f1f71350adcd586b4cd165d5376c /src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits
parentb3649beaa2cb2b04a7db65d0fdb5eac0468405d3 (diff)
downloadCITResewn-9ede90c8610da18ebca8439a09f97f4e79bbe45d.tar.gz
CITResewn-9ede90c8610da18ebca8439a09f97f4e79bbe45d.tar.bz2
CITResewn-9ede90c8610da18ebca8439a09f97f4e79bbe45d.zip
Removed texture/model handling from CIT head
Diffstat (limited to 'src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits')
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CIT.java79
1 files changed, 49 insertions, 30 deletions
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 e5c0809..b4960f2 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
@@ -3,6 +3,7 @@ package shcm.shsupercm.fabric.citresewn.pack.cits;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.item.Item;
import net.minecraft.nbt.*;
+import net.minecraft.resource.ResourcePack;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
@@ -20,9 +21,6 @@ import java.util.regex.Pattern;
public abstract class CIT {
public final Set<Item> items = new HashSet<>();
- public final Identifier assetIdentifier;
- public final boolean needsModel;
-
public final int damageMin, damageMax;
public final boolean damageAny, damageRange, damagePercentage;
public final Integer damageMask;
@@ -50,33 +48,6 @@ public abstract class CIT {
if (this.items.size() == 0 && !properties.getProperty("type", "item").equals("enchantment"))
throw new Exception("CIT must target at least one item type");
- Identifier modelIdentifier = new Identifier(properties.getProperty("model", identifier.getPath().substring(0, identifier.getPath().length() - ".properties".length()) + ".json"));
- if (pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, modelIdentifier)) {
- this.assetIdentifier = modelIdentifier;
- this.needsModel = false;
- } else {
- String[] split = identifier.getPath().split("/");
- String parent = String.join("/", Arrays.copyOf(split, split.length - 1, String[].class));
- if (!parent.isEmpty())
- parent = parent + "/";
- modelIdentifier = new Identifier(parent + (modelIdentifier.getPath().endsWith(".json") ? modelIdentifier.getPath() : modelIdentifier.getPath() + ".json"));
- if (pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, modelIdentifier)) {
- this.assetIdentifier = modelIdentifier;
- this.needsModel = false;
- } else {
- Identifier textureIdentifier = new Identifier(properties.getProperty("texture", identifier.getPath().substring(0, identifier.getPath().length() - ".properties".length()) + ".png"));
- if (!pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, textureIdentifier)) {
- textureIdentifier = new Identifier(parent + (textureIdentifier.getPath().endsWith(".png") ? textureIdentifier.getPath() : textureIdentifier.getPath() + ".png"));
-
- if (!pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, textureIdentifier))
- throw new Exception("CIT must have either a texture or a model");
- }
-
- this.assetIdentifier = textureIdentifier;
- this.needsModel = true;
- }
- }
-
String damage = properties.getProperty("damage");
if (damageAny = damage == null) {
this.damageRange = false;
@@ -249,6 +220,54 @@ public abstract class CIT {
}
/**
+ * Takes a defined path and resolves it to an identifier pointing to the resourcepack's path of the specified extension(returns null if no path can be resolved).<br>
+ * If definedPath is null, will try to resolve a relative file with the same name as the propertyIdentifier with the extension, otherwise: <br>
+ * definedPath will be formatted to replace "\\" with "/" the extension will be appended if not there already. <br>
+ * 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) {
+ if (path == null) {
+ Identifier pathIdentifier = new Identifier(propertyIdentifier.getNamespace(), propertyIdentifier.getPath().replace(".properties", extension));
+ return pack.contains(ResourceType.CLIENT_RESOURCES, pathIdentifier) ? pathIdentifier : null;
+ }
+
+ Identifier pathIdentifier = new Identifier(path);
+
+ path = pathIdentifier.getPath().replace('\\', '/');
+ if (!path.endsWith(extension))
+ path = path + extension;
+
+ if (path.startsWith("./"))
+ path = path.substring(2);
+ else if (!path.contains("..")) {
+ pathIdentifier = new Identifier(pathIdentifier.getNamespace(), path);
+ if (pack.contains(ResourceType.CLIENT_RESOURCES, pathIdentifier))
+ return pathIdentifier;
+ }
+
+ LinkedList<String> pathParts = new LinkedList<>(Arrays.asList(propertyIdentifier.getPath().split("/")));
+ pathParts.removeLast();
+
+ if (path.contains("/")) {
+ for (String part : path.split("/")) {
+ if (part.equals("..")) {
+ if (pathParts.size() == 0)
+ return null;
+ pathParts.removeLast();
+ } else
+ pathParts.addLast(part);
+ }
+ } else
+ pathParts.addLast(path);
+ path = String.join("/", pathParts);
+
+ pathIdentifier = new Identifier(propertyIdentifier.getNamespace(), path);
+
+ return pack.contains(ResourceType.CLIENT_RESOURCES, pathIdentifier) ? pathIdentifier : null;
+ }
+
+ /**
* Author: Paul "prupe" Rupe<br>
* Taken from MCPatcher under public domain licensing.<br>
* https://bitbucket.org/prupe/mcpatcher/src/1aa45839b2cd029143809edfa60ec59e5ef75f80/newcode/src/com/prupe/mcpatcher/mal/nbt/NBTRule.java#lines-269:301