diff options
author | SHsuperCM <shsupercm@gmail.com> | 2021-08-29 17:19:39 +0300 |
---|---|---|
committer | SHsuperCM <shsupercm@gmail.com> | 2021-08-29 17:19:39 +0300 |
commit | a96cbd1dc47330d655c05e6467153db104116e58 (patch) | |
tree | 2fd309250b1f5ee7d78147ed6acca58cc494ef73 /src/main/java/shcm/shsupercm/fabric | |
parent | 3a88b20abf6e1d79f34bc943d2abba4ac23928f9 (diff) | |
download | CITResewn-a96cbd1dc47330d655c05e6467153db104116e58.tar.gz CITResewn-a96cbd1dc47330d655c05e6467153db104116e58.tar.bz2 CITResewn-a96cbd1dc47330d655c05e6467153db104116e58.zip |
Implemented type=armor cits
Diffstat (limited to 'src/main/java/shcm/shsupercm/fabric')
5 files changed, 91 insertions, 17 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java b/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java index 9a58a9d..b0d97ab 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java @@ -75,4 +75,16 @@ public class ActiveCITs { return null; } + + public Map<String, Identifier> getArmorTextures(ItemStack itemStack, World world, LivingEntity livingEntity) { + Item item = itemStack.getItem(); + if (item instanceof ArmorItem) { + List<CITArmor> citArmor = this.citArmor.get(item); + if (citArmor != null) + for (CITArmor armor : citArmor) + if (armor.test(itemStack, null, world, livingEntity)) + return armor.textures; + } + return null; + } } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java index cbc7342..cf85a2c 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java @@ -21,20 +21,5 @@ public class CITResewn implements ClientModInitializer { INSTANCE = this; config = CITResewnConfig.read(); - - /*net.minecraft.client.render.entity.feature.ArmorFeatureRenderer#renderArmor - take entity.getEquippedStack(armorSlot) - eval override - save shadow String cachedOverride /null - - /*net.minecraft.client.render.entity.feature.ArmorFeatureRenderer#getArmorTexture - if(shadow cachedOverride != null) - mxreturn shadow cachedOverride - - */ - - /* - - */ } } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ArmorFeatureRendererMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ArmorFeatureRendererMixin.java new file mode 100644 index 0000000..02f4689 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ArmorFeatureRendererMixin.java @@ -0,0 +1,54 @@ +package shcm.shsupercm.fabric.citresewn.mixin; + +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.entity.feature.ArmorFeatureRenderer; +import net.minecraft.client.render.entity.model.BipedEntityModel; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ArmorItem; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Identifier; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import shcm.shsupercm.fabric.citresewn.CITResewn; +import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; + +import java.lang.ref.WeakReference; +import java.util.Map; + +@Mixin(ArmorFeatureRenderer.class) +public class ArmorFeatureRendererMixin<T extends LivingEntity, M extends BipedEntityModel<T>, A extends BipedEntityModel<T>> { + private WeakReference<Map<String, Identifier>> armorTexturesCached = null; + + @Inject(method = "renderArmor", cancellable = true, at = @At("HEAD")) + public void renderArmor(MatrixStack matrices, VertexConsumerProvider vertexConsumers, T entity, EquipmentSlot armorSlot, int light, A model, CallbackInfo ci) { + if (!CITResewnConfig.INSTANCE().enabled || CITResewn.INSTANCE.activeCITs == null) + return; + + ItemStack itemStack = entity.getEquippedStack(armorSlot); + Map<String, Identifier> armorTextures = CITResewn.INSTANCE.activeCITs.getArmorTextures(itemStack, entity.world, entity); + if (armorTextures != null) { + armorTexturesCached = new WeakReference<>(armorTextures); + return; + } + + armorTexturesCached = null; + } + + @Inject(method = "getArmorTexture", cancellable = true, at = @At("HEAD")) + public void getArmorTexture(ArmorItem item, boolean legs, String overlay, CallbackInfoReturnable<Identifier> cir) { + if (armorTexturesCached == null) + return; + Map<String, Identifier> armorTextures = armorTexturesCached.get(); + if (armorTextures == null) + return; + + Identifier identifier = armorTextures.get(item.getMaterial().getName() + "_layer_" + (legs ? "2" : "1") + (overlay == null ? "" : "_" + overlay)); + if (identifier != null) + cir.setReturnValue(identifier); + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ElytraFeatureRendererMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ElytraFeatureRendererMixin.java index 37f0dd9..a774de4 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ElytraFeatureRendererMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ElytraFeatureRendererMixin.java @@ -24,7 +24,7 @@ public class ElytraFeatureRendererMixin { private WeakReference<LivingEntity> livingEntityCached = new WeakReference<>(null); @Inject(method = "render", cancellable = true, at = @At("HEAD")) - public void injectCIT(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, LivingEntity livingEntity, float f, float g, float h, float j, float k, float l, CallbackInfo ci) { + public void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, LivingEntity livingEntity, float f, float g, float h, float j, float k, float l, CallbackInfo ci) { if (!CITResewnConfig.INSTANCE().enabled || CITResewn.INSTANCE.activeCITs == null) return; 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 index bc6f6e8..794167c 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITArmor.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITArmor.java @@ -1,13 +1,36 @@ package shcm.shsupercm.fabric.citresewn.pack.cits; +import net.minecraft.item.ArmorItem; +import net.minecraft.item.Item; 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.Properties; +import java.util.*; public class CITArmor extends CIT { + public final Map<String, Identifier> textures = new HashMap<>(); + public CITArmor(CITPack pack, Identifier identifier, Properties properties) throws CITParseException { super(pack, identifier, properties); + try { + if (this.items.size() == 0) + throw new Exception("CIT must target at least one item type"); + for (Item item : this.items) + if (!(item instanceof ArmorItem)) + throw new Exception("Armor CIT must target armor items only(" + Registry.ITEM.getId(item) + " is not armor)"); + + for (Object o : properties.keySet()) + if (o instanceof String property && property.startsWith("texture.")) { + Identifier textureIdentifier = resolvePath(identifier, properties.getProperty(property), ".png", pack.resourcePack); + if (textureIdentifier == null) + throw new Exception("Cannot resolve path for " + property); + + this.textures.put(property.substring(8), textureIdentifier); + } + } catch (Exception e) { + throw new CITParseException(pack.resourcePack, identifier, (e.getClass() == Exception.class ? "" : e.getClass().getSimpleName() + ": ") + e.getMessage()); + } } } |