aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/shcm/shsupercm
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2021-08-27 20:00:19 +0300
committerSHsuperCM <shsupercm@gmail.com>2021-08-27 20:00:19 +0300
commitb650306cf3a8a9fe9d2141dea98ff9e63d5ba597 (patch)
treeed0ac32e1b7b430ac96f80141178944defe7d899 /src/main/java/shcm/shsupercm
parentbd9f8f607bb174a77559a89fcb98e3dc86213325 (diff)
downloadCITResewn-b650306cf3a8a9fe9d2141dea98ff9e63d5ba597.tar.gz
CITResewn-b650306cf3a8a9fe9d2141dea98ff9e63d5ba597.tar.bz2
CITResewn-b650306cf3a8a9fe9d2141dea98ff9e63d5ba597.zip
Made cit items work
Diffstat (limited to 'src/main/java/shcm/shsupercm')
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java15
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CIT.java69
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITItem.java22
3 files changed, 104 insertions, 2 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java b/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java
index 76473a0..769749d 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java
@@ -5,6 +5,7 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
+import net.minecraft.util.Hand;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import shcm.shsupercm.fabric.citresewn.pack.cits.*;
@@ -52,7 +53,17 @@ public class ActiveCITs {
}
public BakedModel getItemModel(ItemStack stack, BakedModel model, World world, LivingEntity entity) {
- //stub
- return null;
+ BakedModel bakedModel = null;
+ Hand hand = entity != null && stack == entity.getOffHandStack() ? Hand.OFF_HAND : Hand.MAIN_HAND;
+
+ List<CITItem> citItems = this.citItems.get(stack.getItem());
+ if (citItems != null)
+ for (CITItem citItem : citItems) {
+ bakedModel = citItem.getItemModel(stack, hand, model, world, entity);
+ if (bakedModel != null)
+ break;
+ }
+
+ return bakedModel;
}
}
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 f50f6e9..aaf6c2b 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,7 +1,11 @@
package shcm.shsupercm.fabric.citresewn.pack.cits;
+import net.minecraft.client.render.model.BakedModel;
import net.minecraft.enchantment.Enchantment;
+import net.minecraft.enchantment.EnchantmentHelper;
+import net.minecraft.entity.LivingEntity;
import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
import net.minecraft.nbt.*;
import net.minecraft.resource.ResourcePack;
import net.minecraft.resource.ResourceType;
@@ -9,6 +13,7 @@ import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.Pair;
import net.minecraft.util.registry.Registry;
+import net.minecraft.world.World;
import org.apache.commons.lang3.StringEscapeUtils;
import shcm.shsupercm.fabric.citresewn.ex.CITParseException;
import shcm.shsupercm.fabric.citresewn.mixin.NbtCompoundAccessor;
@@ -227,6 +232,70 @@ public abstract class CIT {
}
}
+ public boolean test(ItemStack stack, Hand hand, World world, LivingEntity entity) {
+ if (!damageAny && stack.getItem().isDamageable()) {
+ int damage = stack.getDamage();
+ if (damageMask != null)
+ damage &= damageMask;
+ if (damagePercentage)
+ damage = Math.round(100f * (float) stack.getDamage() / (float) stack.getMaxDamage());
+ if (damageRange ? (damage < damageMin || damage > damageMax) : (damage != damageMin))
+ return false;
+ }
+
+ if (!stackAny) {
+ int count = stack.getCount();
+ if (stackRange ? (count < stackMin || count > stackMax) : (count != stackMin))
+ return false;
+ }
+
+ if (this.hand != null && this.hand != hand)
+ return false;
+
+ if (!enchantmentsAny) {
+ Map<Enchantment, Integer> stackEnchantments = EnchantmentHelper.get(stack);
+
+ boolean matches = false;
+ for (Enchantment enchantment : enchantments) {
+ Integer level = stackEnchantments.get(enchantment);
+ if (level != null)
+ if (enchantmentLevelsAny) {
+ if (level > 0) {
+ matches = true;
+ break;
+ }
+ } else
+ for (Pair<Integer, Integer> levelRange : enchantmentLevels)
+ if (level >= levelRange.getLeft() && level <= levelRange.getRight()) {
+ matches = true;
+ break;
+ }
+ }
+
+ if (!matches)
+ return false;
+ } else if (!enchantmentLevelsAny) {
+ Collection<Integer> levels = EnchantmentHelper.get(stack).values();
+ levels.add(0);
+
+ boolean matches = false;
+
+ l: for (Integer level : levels) {
+ for (Pair<Integer, Integer> levelRange : enchantmentLevels) {
+ if (level >= levelRange.getLeft() && level <= levelRange.getRight()) {
+ matches = true;
+ break l;
+ }
+ }
+ }
+
+ if (!matches)
+ return false;
+ }
+
+ return nbt == null || nbt.test(stack.getNbt());
+ }
+
public void dispose() {
//stub
}
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 1774378..c9e8e67 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
@@ -7,8 +7,16 @@ import net.minecraft.client.render.model.json.JsonUnbakedModel;
import net.minecraft.client.render.model.json.ModelTransformation;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.client.util.SpriteIdentifier;
+import net.minecraft.enchantment.Enchantment;
+import net.minecraft.enchantment.EnchantmentHelper;
+import net.minecraft.entity.LivingEntity;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NbtList;
import net.minecraft.resource.ResourceManager;
+import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
+import net.minecraft.util.Pair;
+import net.minecraft.world.World;
import org.apache.commons.io.IOUtils;
import shcm.shsupercm.fabric.citresewn.ex.CITLoadException;
import shcm.shsupercm.fabric.citresewn.ex.CITParseException;
@@ -94,4 +102,18 @@ public class CITItem extends CIT {
}
throw new Exception("Unknown asset type");
}
+
+ public BakedModel getItemModel(ItemStack stack, Hand hand, BakedModel model, World world, LivingEntity entity) {
+ if (test(stack, hand, world, entity)) {
+ if (subItems != null) {
+ BakedModel subModel = subItems.get(model);
+ if (subModel != null)
+ return subModel;
+ }
+
+ return this.bakedModel;
+ }
+
+ return null;
+ }
}