diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java | 14 | ||||
-rw-r--r-- | src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITEnchantment.java | 38 |
2 files changed, 46 insertions, 6 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java b/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java index 790fb8c..db5bc04 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java @@ -22,12 +22,14 @@ public class ActiveCITs { public final Map<Item, List<CITItem>> citItems = new HashMap<>(); public final Map<ArmorItem, List<CITArmor>> citArmor = new HashMap<>(); public final List<CITElytra> citElytra = new ArrayList<>(); - public final List<CITEnchantment> citEnchantments = new ArrayList<>(); + public final List<List<CITEnchantment>> citEnchantments = new ArrayList<>(); public ActiveCITs(Collection<CIT> cits) { this.cits = cits; + Map<Integer, List<CITEnchantment>> citEnchantmentLayers = new TreeMap<>(); // order citEnchantments by layers + for (CIT cit : cits.stream().sorted(Comparator.<CIT>comparingInt(cit -> cit.weight).reversed().thenComparing(cit -> cit.propertiesIdentifier.toString())).collect(Collectors.toList())) { if (cit instanceof CITItem item) for (Item type : item.items) @@ -38,11 +40,13 @@ public class ActiveCITs { citArmor.computeIfAbsent(armorType, t -> new ArrayList<>()).add(armor); else CITResewn.logErrorLoading("Ignoring item type: " + Registry.ITEM.getId(type) + " is not armor in " + cit.pack.resourcePack.getName() + " -> " + cit.propertiesIdentifier.toString()); - else if (cit instanceof CITElytra) - citElytra.add((CITElytra) cit); - else if (cit instanceof CITEnchantment) - citEnchantments.add((CITEnchantment) cit); + else if (cit instanceof CITElytra elytra) + citElytra.add(elytra); + else if (cit instanceof CITEnchantment enchantment) + citEnchantmentLayers.computeIfAbsent(enchantment.layer, l -> new ArrayList<>()).add(enchantment); } + + citEnchantments.addAll(citEnchantmentLayers.values()); } public void dispose() { 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 index 6f8cc76..16222a7 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITEnchantment.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITEnchantment.java @@ -1,13 +1,49 @@ 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; +import java.util.Locale; import java.util.Properties; public class CITEnchantment extends CIT { + public final Identifier textureIdentifier; + public final float speed, rotation, duration; + public final int layer; + public final Blend blend; + public CITEnchantment(CITPack pack, Identifier identifier, Properties properties) throws CITParseException { super(pack, identifier, properties); + try { + textureIdentifier = resolvePath(identifier, properties.getProperty("texture"), ".png", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id)); + if (textureIdentifier == null) + throw new Exception("Cannot resolve texture"); + + layer = Integer.parseInt(properties.getProperty("layer", "0")); + + blend = Blend.valueOf(properties.getProperty("blend", "add").toUpperCase(Locale.ENGLISH)); + + speed = Float.parseFloat(properties.getProperty("speed", "0")); + + rotation = Float.parseFloat(properties.getProperty("rotation", "0")); + + duration = Float.max(0f, Float.parseFloat(properties.getProperty("duration", "0"))); + } catch (Exception e) { + throw new CITParseException(pack.resourcePack, identifier, (e.getClass() == Exception.class ? "" : e.getClass().getSimpleName() + ": ") + e.getMessage()); + } + } + + public enum Blend { + ADD, + SUBTRACT, + MULTIPLY, + DODGE, + BURN, + SCREEN, + REPLACE, + OVERLAY, + ALPHA; } -} +}
\ No newline at end of file |