From 3e60c7b5cf646fbda1c15b38877ba7e5022dd2e2 Mon Sep 17 00:00:00 2001 From: SHsuperCM Date: Sat, 9 Oct 2021 17:44:19 +0300 Subject: Setup for enchantment layer application #15 --- .../shcm/shsupercm/fabric/citresewn/ActiveCITs.java | 21 ++++++++++++++++++--- .../mixin/citenchantment/ItemRendererMixin.java | 8 ++++++++ .../mixin/citenchantment/ItemStackMixin.java | 8 ++++++++ .../shsupercm/fabric/citresewn/pack/cits/CIT.java | 5 ++++- .../fabric/citresewn/pack/cits/CITEnchantment.java | 2 -- 5 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/ItemRendererMixin.java create mode 100644 src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/ItemStackMixin.java (limited to 'src/main/java') diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java b/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java index f4d2b5b..9e39287 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java @@ -69,14 +69,14 @@ public class ActiveCITs { List citItems = this.citItems.get(stack.getItem()); if (citItems != null) for (CITItem citItem : citItems) - if (citItem.test(stack, hand, world, entity)) + if (citItem.test(stack, hand, world, entity, true)) return citItem; return null; } public CITElytra getCITElytra(ItemStack stack, World world, LivingEntity livingEntity) { for (CITElytra citElytra : citElytra) - if (citElytra.test(stack, Hand.MAIN_HAND, world, livingEntity)) + if (citElytra.test(stack, Hand.MAIN_HAND, world, livingEntity, true)) return citElytra; return null; } @@ -87,12 +87,27 @@ public class ActiveCITs { List citArmor = this.citArmor.get(item); if (citArmor != null) for (CITArmor armor : citArmor) - if (armor.test(stack, null, world, livingEntity)) + if (armor.test(stack, null, world, livingEntity, true)) return armor; } return null; } + public List getCITEnchantment(ItemStack stack, World world, LivingEntity livingEntity) { + Hand hand = livingEntity != null && stack == livingEntity.getOffHandStack() ? Hand.OFF_HAND : Hand.MAIN_HAND; + + List applied = new ArrayList<>(); + + for (List layer : this.citEnchantments) + for (CITEnchantment cit : layer) + if (cit.test(stack, hand, world, livingEntity, false)) { + applied.add(cit); + break; + } + + return applied; + } + public BakedModel getItemModelCached(ItemStack stack, World world, LivingEntity entity, int seed) { BakedModel bakedModel = null; diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/ItemRendererMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/ItemRendererMixin.java new file mode 100644 index 0000000..b19e901 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/ItemRendererMixin.java @@ -0,0 +1,8 @@ +package shcm.shsupercm.fabric.citresewn.mixin.citenchantment; + +import net.minecraft.client.render.item.ItemRenderer; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(ItemRenderer.class) +public class ItemRendererMixin { +} \ No newline at end of file diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/ItemStackMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/ItemStackMixin.java new file mode 100644 index 0000000..07faf22 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/ItemStackMixin.java @@ -0,0 +1,8 @@ +package shcm.shsupercm.fabric.citresewn.mixin.citenchantment; + +import net.minecraft.item.ItemStack; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(ItemStack.class) +public class ItemStackMixin { +} 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 ebfcaf1..db29fdd 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 @@ -251,7 +251,10 @@ public abstract class CIT { } } - public boolean test(ItemStack stack, Hand hand, World world, LivingEntity entity) { + public boolean test(ItemStack stack, Hand hand, World world, LivingEntity entity, boolean ignoreItemType) { + if (!ignoreItemType && !items.contains(stack.getItem())) + return false; + if (!damageAny && stack.getItem().isDamageable()) { int damage = stack.getDamage(); if (damageMask != null) 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 b1c37db..cd0b604 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 @@ -36,8 +36,6 @@ public class CITEnchantment extends CIT { 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()); } -- cgit