aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2021-08-20 19:13:31 +0300
committerSHsuperCM <shsupercm@gmail.com>2021-08-20 19:30:43 +0300
commitaf028c27f8b103e3ee86f5d7f09a4c1e3fc303d2 (patch)
treedce1e80e04da13f9fdfcac200da3e2c794ff307a
parentc684710b01ed4d1b9b5363c392e24f31d31c527a (diff)
downloadCITResewn-af028c27f8b103e3ee86f5d7f09a4c1e3fc303d2.tar.gz
CITResewn-af028c27f8b103e3ee86f5d7f09a4c1e3fc303d2.tar.bz2
CITResewn-af028c27f8b103e3ee86f5d7f09a4c1e3fc303d2.zip
Type/item parsing & standard exception format for skipped CITs
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/ex/CITParseException.java13
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java8
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java15
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CIT.java31
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITArmor.java13
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITElytra.java13
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITEnchantment.java13
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITItem.java13
8 files changed, 113 insertions, 6 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/ex/CITParseException.java b/src/main/java/shcm/shsupercm/fabric/citresewn/ex/CITParseException.java
new file mode 100644
index 0000000..e48f857
--- /dev/null
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/ex/CITParseException.java
@@ -0,0 +1,13 @@
+package shcm.shsupercm.fabric.citresewn.ex;
+
+import net.minecraft.resource.ResourcePack;
+import net.minecraft.util.Identifier;
+
+/**
+ * Thrown when a cit failed to be parsed
+ */
+public class CITParseException extends Exception {
+ public CITParseException(ResourcePack resourcePack, Identifier identifier, String message) {
+ super("Skipped: " + message + " in " + resourcePack.getName() + " -> " + identifier.getPath());
+ }
+}
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java
index 27b693a..0431e62 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java
@@ -1,7 +1,9 @@
package shcm.shsupercm.fabric.citresewn.pack;
import net.minecraft.resource.ResourcePack;
+import net.minecraft.util.Identifier;
import shcm.shsupercm.fabric.citresewn.CITResewn;
+import shcm.shsupercm.fabric.citresewn.ex.CITParseException;
import shcm.shsupercm.fabric.citresewn.pack.cits.CIT;
import java.util.ArrayList;
@@ -26,17 +28,17 @@ public class CITPack {
try {
cap = Integer.parseInt(properties.getProperty("cap", "8"));
} catch (NumberFormatException e) {
- CITResewn.LOG.error("Skipped property: cap is not a whole number in cit.properties inside " + resourcePack.getName());
+ CITResewn.LOG.error(new CITParseException(resourcePack, new Identifier("cit.properties"), "cap is not a whole number").getMessage());
}
try {
fade = Float.parseFloat(properties.getProperty("fade", "0.5"));
} catch (NumberFormatException e) {
- CITResewn.LOG.error("Skipped property: fade is not a number in cit.properties inside " + resourcePack.getName());
+ CITResewn.LOG.error(new CITParseException(resourcePack, new Identifier("cit.properties"), "fade is not a number").getMessage());
}
switch (properties.getProperty("useGlint", "true")) {
case "true" -> useGlint = true;
case "false" -> useGlint = false;
- default -> CITResewn.LOG.error("Skipped property: useGlint is not a boolean in cit.properties inside " + resourcePack.getName());
+ default -> CITResewn.LOG.error(new CITParseException(resourcePack, new Identifier("cit.properties"), "useGlint is not a boolean").getMessage());
}
}
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java
index c3db062..32aa18c 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java
@@ -3,7 +3,9 @@ package shcm.shsupercm.fabric.citresewn.pack;
import net.minecraft.resource.ResourcePack;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
-import shcm.shsupercm.fabric.citresewn.pack.cits.CIT;
+import shcm.shsupercm.fabric.citresewn.CITResewn;
+import shcm.shsupercm.fabric.citresewn.ex.CITParseException;
+import shcm.shsupercm.fabric.citresewn.pack.cits.*;
import java.io.InputStream;
import java.util.*;
@@ -54,6 +56,7 @@ public class CITParser { private CITParser() {}
citPack.cits.add(parseCIT(citPack, citIdentifier, citProperties));
} catch (Exception e) {
+ CITResewn.LOG.error(e.getMessage());
e.printStackTrace();
}
}
@@ -63,7 +66,13 @@ public class CITParser { private CITParser() {}
return cits;
}
- public static CIT parseCIT(CITPack pack, Identifier identifier, Properties properties) {
- return null;
+ public static CIT parseCIT(CITPack pack, Identifier identifier, Properties properties) throws CITParseException {
+ return switch (properties.getProperty("type", "item")) {
+ case "item" -> new CITItem(pack, identifier, properties);
+ case "armor" -> new CITArmor(pack, identifier, properties);
+ case "elytra" -> new CITElytra(pack, identifier, properties);
+ case "enchantment" -> new CITEnchantment(pack, identifier, properties);
+ default -> throw new CITParseException(pack.resourcePack, identifier, "Unknown cit type");
+ };
}
}
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 8d4dc65..25a4fc7 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
@@ -1,4 +1,35 @@
package shcm.shsupercm.fabric.citresewn.pack.cits;
+import net.minecraft.item.Item;
+import net.minecraft.item.Items;
+import net.minecraft.util.Identifier;
+import net.minecraft.util.registry.Registry;
+import shcm.shsupercm.fabric.citresewn.ex.CITParseException;
+import shcm.shsupercm.fabric.citresewn.pack.CITPack;
+
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+
public abstract class CIT {
+ public final Set<Item> items = new HashSet<>();
+
+ public CIT(CITPack pack, Identifier identifier, Properties properties) throws CITParseException {
+ try {
+ for (String itemId : (properties.getProperty("items", properties.getProperty("matchItems", " "))).split(" "))
+ if (!itemId.isEmpty()) {
+ Item item = Registry.ITEM.get(new Identifier(itemId));
+ if (item == Items.AIR)
+ throw new Exception("Unknown item " + itemId);
+ items.add(item);
+ }
+
+ if (items.size() == 0 && !properties.getProperty("type", "item").equals("enchantment"))
+ throw new Exception("CIT must target at least one item type");
+
+
+ } catch (Exception e) {
+ throw new CITParseException(pack.resourcePack, identifier, e.getMessage());
+ }
+ }
}
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
new file mode 100644
index 0000000..bc6f6e8
--- /dev/null
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITArmor.java
@@ -0,0 +1,13 @@
+package shcm.shsupercm.fabric.citresewn.pack.cits;
+
+import net.minecraft.util.Identifier;
+import shcm.shsupercm.fabric.citresewn.ex.CITParseException;
+import shcm.shsupercm.fabric.citresewn.pack.CITPack;
+
+import java.util.Properties;
+
+public class CITArmor extends CIT {
+ public CITArmor(CITPack pack, Identifier identifier, Properties properties) throws CITParseException {
+ super(pack, identifier, properties);
+ }
+}
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
new file mode 100644
index 0000000..e09e4fb
--- /dev/null
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITElytra.java
@@ -0,0 +1,13 @@
+package shcm.shsupercm.fabric.citresewn.pack.cits;
+
+import net.minecraft.util.Identifier;
+import shcm.shsupercm.fabric.citresewn.ex.CITParseException;
+import shcm.shsupercm.fabric.citresewn.pack.CITPack;
+
+import java.util.Properties;
+
+public class CITElytra extends CIT {
+ public CITElytra(CITPack pack, Identifier identifier, Properties properties) throws CITParseException {
+ super(pack, identifier, properties);
+ }
+}
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITEnchantment.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITEnchantment.java
new file mode 100644
index 0000000..6f8cc76
--- /dev/null
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITEnchantment.java
@@ -0,0 +1,13 @@
+package shcm.shsupercm.fabric.citresewn.pack.cits;
+
+import net.minecraft.util.Identifier;
+import shcm.shsupercm.fabric.citresewn.ex.CITParseException;
+import shcm.shsupercm.fabric.citresewn.pack.CITPack;
+
+import java.util.Properties;
+
+public class CITEnchantment extends CIT {
+ public CITEnchantment(CITPack pack, Identifier identifier, Properties properties) throws CITParseException {
+ super(pack, identifier, properties);
+ }
+}
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
new file mode 100644
index 0000000..7a7e963
--- /dev/null
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITItem.java
@@ -0,0 +1,13 @@
+package shcm.shsupercm.fabric.citresewn.pack.cits;
+
+import net.minecraft.util.Identifier;
+import shcm.shsupercm.fabric.citresewn.ex.CITParseException;
+import shcm.shsupercm.fabric.citresewn.pack.CITPack;
+
+import java.util.Properties;
+
+public class CITItem extends CIT {
+ public CITItem(CITPack pack, Identifier identifier, Properties properties) throws CITParseException {
+ super(pack, identifier, properties);
+ }
+}