diff options
Diffstat (limited to 'src')
5 files changed, 66 insertions, 1 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java b/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java index 769749d..9a58a9d 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java @@ -6,6 +6,7 @@ import net.minecraft.item.ArmorItem; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.Hand; +import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; import net.minecraft.world.World; import shcm.shsupercm.fabric.citresewn.pack.cits.*; @@ -66,4 +67,12 @@ public class ActiveCITs { return bakedModel; } + + public Identifier getElytraTexture(ItemStack stack, World world, LivingEntity livingEntity) { + for (CITElytra citElytra : citElytra) + if (citElytra.test(stack, Hand.MAIN_HAND, world, livingEntity)) + return citElytra.textureIdentifier; + + return null; + } } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ElytraFeatureRendererMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ElytraFeatureRendererMixin.java new file mode 100644 index 0000000..39dfa73 --- /dev/null +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ElytraFeatureRendererMixin.java @@ -0,0 +1,46 @@ +package shcm.shsupercm.fabric.citresewn.mixin; + +import net.minecraft.client.render.RenderLayer; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.entity.feature.ElytraFeatureRenderer; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.LivingEntity; +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import shcm.shsupercm.fabric.citresewn.CITResewn; + +import java.lang.ref.WeakReference; + +@Mixin(ElytraFeatureRenderer.class) +public class ElytraFeatureRendererMixin { + private WeakReference<ItemStack> elytraItemCached = new WeakReference<>(null); + 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) { + if (CITResewn.INSTANCE.activeCITs == null) + return; + + this.elytraItemCached = new WeakReference<>(livingEntity.getEquippedStack(EquipmentSlot.CHEST)); + this.livingEntityCached = new WeakReference<>(livingEntity); + } + + @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/RenderLayer;getArmorCutoutNoCull(Lnet/minecraft/util/Identifier;)Lnet/minecraft/client/render/RenderLayer;")) + public RenderLayer getArmorCutoutNoCull(Identifier originalIdentifier) { + ItemStack itemStack = this.elytraItemCached.get(); + LivingEntity livingEntity = livingEntityCached.get(); + if (itemStack != null && livingEntity != null) { + Identifier elytraTexture = CITResewn.INSTANCE.activeCITs.getElytraTexture(itemStack, livingEntity.world, livingEntity); + if (elytraTexture != null) + return RenderLayer.getArmorCutoutNoCull(elytraTexture); + } + + return RenderLayer.getArmorCutoutNoCull(originalIdentifier); + } +} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ItemRendererMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ItemRendererMixin.java index fd593ee..f2c15ec 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ItemRendererMixin.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/ItemRendererMixin.java @@ -14,7 +14,7 @@ import shcm.shsupercm.fabric.citresewn.CITResewn; @Mixin(ItemRenderer.class) public class ItemRendererMixin { @Inject(method = "getHeldItemModel", cancellable = true, at = @At("RETURN")) - public void getItemModel(ItemStack stack, World world, LivingEntity entity, int seed, CallbackInfoReturnable<BakedModel> cir) { + public void injectCIT(ItemStack stack, World world, LivingEntity entity, int seed, CallbackInfoReturnable<BakedModel> cir) { if (CITResewn.INSTANCE.activeCITs == null) return; 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 index e09e4fb..8c5bea8 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITElytra.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITElytra.java @@ -7,7 +7,16 @@ import shcm.shsupercm.fabric.citresewn.pack.CITPack; import java.util.Properties; public class CITElytra extends CIT { + public final Identifier textureIdentifier; + public CITElytra(CITPack pack, Identifier identifier, Properties properties) throws CITParseException { super(pack, identifier, properties); + try { + textureIdentifier = resolvePath(identifier, properties.getProperty("texture"), ".png", pack.resourcePack); + if (textureIdentifier == null) + throw new Exception("Cannot resolve texture"); + } catch (Exception e) { + throw new CITParseException(pack.resourcePack, identifier, (e.getClass() == Exception.class ? "" : e.getClass().getSimpleName() + ": ") + e.getMessage()); + } } } diff --git a/src/main/resources/citresewn.mixins.json b/src/main/resources/citresewn.mixins.json index fe412be..22f06a1 100644 --- a/src/main/resources/citresewn.mixins.json +++ b/src/main/resources/citresewn.mixins.json @@ -4,6 +4,7 @@ "package": "shcm.shsupercm.fabric.citresewn.mixin", "compatibilityLevel": "JAVA_16", "mixins": [ + "ElytraFeatureRendererMixin", "IdentifierMixin", "ItemRendererMixin", "JsonUnbakedModelAccessor", |