diff --git a/src/main/java/com/minelittlepony/api/model/ModelAttributes.java b/src/main/java/com/minelittlepony/api/model/ModelAttributes.java index faf7dd16..6a4dc40e 100644 --- a/src/main/java/com/minelittlepony/api/model/ModelAttributes.java +++ b/src/main/java/com/minelittlepony/api/model/ModelAttributes.java @@ -10,8 +10,8 @@ import java.util.*; import net.minecraft.client.render.entity.model.BipedEntityModel.ArmPose; import net.minecraft.entity.LivingEntity; -import net.minecraft.util.Arm; -import net.minecraft.util.Identifier; +import net.minecraft.item.ItemStack; +import net.minecraft.util.*; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; @@ -110,6 +110,11 @@ public class ModelAttributes { */ public IPonyData metadata = PonyData.NULL; + public Arm mainArm; + public Hand activeHand; + public ItemStack heldStack = ItemStack.EMPTY; + public int itemUseTime; + /** * Checks flying and speed conditions and sets rainboom to true if we're a species with wings and is going faaast. */ @@ -154,6 +159,9 @@ public class ModelAttributes { isLeftHanded = entity.getMainArm() == Arm.LEFT; isHorsey = MineLittlePony.getInstance().getConfig().horsieMode.get(); featureSkins = SkinsProxy.instance.getAvailableSkins(entity); + mainArm = entity.getMainArm(); + activeHand = entity.getActiveHand(); + itemUseTime = entity.getItemUseTimeLeft(); } public Interpolator getMainInterpolator() { diff --git a/src/main/java/com/minelittlepony/client/model/AbstractPonyModel.java b/src/main/java/com/minelittlepony/client/model/AbstractPonyModel.java index 72f7809f..9e4721f3 100644 --- a/src/main/java/com/minelittlepony/client/model/AbstractPonyModel.java +++ b/src/main/java/com/minelittlepony/client/model/AbstractPonyModel.java @@ -16,7 +16,7 @@ import net.minecraft.client.model.ModelPart; import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.LivingEntity; -import net.minecraft.util.Arm; +import net.minecraft.util.*; import net.minecraft.util.math.*; /** @@ -560,6 +560,38 @@ public abstract class AbstractPonyModel extends ClientPo parts.forEach(part -> part.setVisible(visible, attributes)); } + @Override + public final void setArmAngle(Arm arm, MatrixStack matrices) { + super.setArmAngle(arm, matrices); + positionheldItem(arm, matrices); + } + + protected void positionheldItem(Arm arm, MatrixStack matrices) { + float left = arm == Arm.LEFT ? -1 : 1; + + UseAction action = getAttributes().heldStack.getUseAction(); + + if (action == UseAction.SPYGLASS && getAttributes().itemUseTime > 0) { + + Arm main = getAttributes().mainArm; + if (getAttributes().activeHand == Hand.OFF_HAND) { + main = main.getOpposite(); + } + if (main == arm) { + matrices.translate(left * -0.05F, 0.5F, 0.2F); + matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-60)); + + return; + } + } + + if (getAttributes().isRidingInteractive) { + matrices.translate(left / 10, -0.2F, -0.5F); + } + + matrices.translate(left * 0.1F, 0.45F, 0); + } + @Override public void transform(BodyPart part, MatrixStack stack) { diff --git a/src/main/java/com/minelittlepony/client/model/ClientPonyModel.java b/src/main/java/com/minelittlepony/client/model/ClientPonyModel.java index 38e3b47b..504d257a 100644 --- a/src/main/java/com/minelittlepony/client/model/ClientPonyModel.java +++ b/src/main/java/com/minelittlepony/client/model/ClientPonyModel.java @@ -1,8 +1,12 @@ package com.minelittlepony.client.model; import net.minecraft.client.model.ModelPart; +import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.model.*; +import net.minecraft.client.render.model.json.ModelTransformationMode; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; import net.minecraft.util.Arm; import net.minecraft.util.Hand; @@ -23,7 +27,7 @@ import com.minelittlepony.mson.api.model.biped.MsonPlayer; * * Modders can extend this class to make their own pony models if they wish. */ -public abstract class ClientPonyModel extends MsonPlayer implements IPonyModel, ModelWithHat { +public abstract class ClientPonyModel extends MsonPlayer implements IPonyModel, ModelWithHat, ModelWithArms { /** * The model attributes. @@ -106,6 +110,10 @@ public abstract class ClientPonyModel extends MsonPlayer } + @Override + public void postItemRender(IPony pony, T entity, ItemStack drop, ModelTransformationMode transform, Arm hand, MatrixStack stack, VertexConsumerProvider renderContext) { + } + static void resetPivot(ModelPart part) { part.setPivot(part.getDefaultTransform().pivotX, part.getDefaultTransform().pivotY, part.getDefaultTransform().pivotZ); } diff --git a/src/main/java/com/minelittlepony/client/model/IPonyMixinModel.java b/src/main/java/com/minelittlepony/client/model/IPonyMixinModel.java index 38dadaf8..e3a2e64b 100644 --- a/src/main/java/com/minelittlepony/client/model/IPonyMixinModel.java +++ b/src/main/java/com/minelittlepony/client/model/IPonyMixinModel.java @@ -1,10 +1,13 @@ package com.minelittlepony.client.model; import net.minecraft.client.model.ModelPart; +import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.model.BipedEntityModel; import net.minecraft.client.render.entity.model.ModelWithArms; +import net.minecraft.client.render.model.json.ModelTransformationMode; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; import net.minecraft.util.Arm; import com.minelittlepony.api.model.BodyPart; @@ -90,6 +93,11 @@ public interface IPonyMixinModel return mixin().getBodyPart(part); } + @Override + default void postItemRender(IPony pony, T entity, ItemStack drop, ModelTransformationMode transform, Arm hand, MatrixStack stack, VertexConsumerProvider renderContext) { + mixin().postItemRender(pony, entity, drop, transform, hand, stack, renderContext); + } + interface Caster & IUnicorn, ArmModel> extends IPonyMixinModel, IUnicorn { @Override default boolean isCasting() { diff --git a/src/main/java/com/minelittlepony/client/model/IPonyModel.java b/src/main/java/com/minelittlepony/client/model/IPonyModel.java index 482bfe07..93a91915 100644 --- a/src/main/java/com/minelittlepony/client/model/IPonyModel.java +++ b/src/main/java/com/minelittlepony/client/model/IPonyModel.java @@ -1,8 +1,14 @@ package com.minelittlepony.client.model; import net.minecraft.client.model.ModelPart; +import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.model.BipedEntityModel; +import net.minecraft.client.render.entity.model.ModelWithArms; +import net.minecraft.client.render.model.json.ModelTransformationMode; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.LivingEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Arm; import com.minelittlepony.api.model.BodyPart; import com.minelittlepony.api.model.ICapitated; @@ -11,11 +17,13 @@ import com.minelittlepony.api.model.ModelAttributes; import com.minelittlepony.api.pony.IPony; import com.minelittlepony.mson.api.MsonModel; -public interface IPonyModel extends IModel, ICapitated, MsonModel { +public interface IPonyModel extends IModel, ICapitated, ModelWithArms, MsonModel { void copyAttributes(BipedEntityModel other); void updateLivingState(T entity, IPony pony, ModelAttributes.Mode mode); ModelPart getBodyPart(BodyPart part); + + void postItemRender(IPony pony, T entity, ItemStack drop, ModelTransformationMode transform, Arm hand, MatrixStack stack, VertexConsumerProvider renderContext); } diff --git a/src/main/java/com/minelittlepony/client/model/entity/GuardianPonyModel.java b/src/main/java/com/minelittlepony/client/model/entity/GuardianPonyModel.java index 8800f419..234344fe 100644 --- a/src/main/java/com/minelittlepony/client/model/entity/GuardianPonyModel.java +++ b/src/main/java/com/minelittlepony/client/model/entity/GuardianPonyModel.java @@ -1,12 +1,8 @@ package com.minelittlepony.client.model.entity; import net.minecraft.client.model.ModelPart; -import net.minecraft.client.render.VertexConsumer; -import net.minecraft.client.render.entity.model.EntityModel; import net.minecraft.client.render.entity.model.GuardianEntityModel; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.mob.GuardianEntity; - import com.minelittlepony.client.model.IPonyMixinModel; import com.minelittlepony.client.model.entity.race.SeaponyModel; @@ -18,26 +14,6 @@ public class GuardianPonyModel extends GuardianEntityModel implements IPonyMixin mixin = new SeaponyModel<>(tree); } - @Override - public void setAngles(GuardianEntity entity, float move, float swing, float ticks, float headYaw, float headPitch) { - mixin().setAngles(entity, move, swing, ticks, headYaw, headPitch); - } - - @Override - public void render(MatrixStack stack, VertexConsumer vertices, int overlayUv, int lightUv, float limbDistance, float limbAngle, float tickDelta, float alpha) { - mixin().render(stack, vertices, overlayUv, lightUv, limbDistance, limbAngle, tickDelta, alpha); - } - - @Override - public void animateModel(GuardianEntity entity, float move, float swing, float float_3) { - mixin().animateModel(entity, move, swing, float_3); - } - - @Override - public void copyStateTo(EntityModel model) { - mixin().copyStateTo(model); - } - @Override public SeaponyModel mixin() { return mixin; diff --git a/src/main/java/com/minelittlepony/client/model/entity/WitchPonyModel.java b/src/main/java/com/minelittlepony/client/model/entity/WitchPonyModel.java index 78c3a603..4f6aea7a 100644 --- a/src/main/java/com/minelittlepony/client/model/entity/WitchPonyModel.java +++ b/src/main/java/com/minelittlepony/client/model/entity/WitchPonyModel.java @@ -1,12 +1,15 @@ package com.minelittlepony.client.model.entity; import net.minecraft.client.model.ModelPart; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.mob.WitchEntity; +import net.minecraft.util.*; import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.RotationAxis; import com.minelittlepony.api.model.ModelAttributes; import com.minelittlepony.api.pony.IPony; -import com.minelittlepony.api.pony.meta.Wearable; +import com.minelittlepony.api.pony.meta.*; import com.minelittlepony.client.model.entity.race.EarthPonyModel; public class WitchPonyModel extends EarthPonyModel { @@ -60,6 +63,12 @@ public class WitchPonyModel extends EarthPonyModel { } } + @Override + protected void positionheldItem(Arm arm, MatrixStack matrices) { + super.positionheldItem(arm, matrices); + matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(10)); + } + @Override public boolean isWearing(Wearable wearable) { if (wearable == Wearable.HAT) { diff --git a/src/main/java/com/minelittlepony/client/model/entity/race/UnicornModel.java b/src/main/java/com/minelittlepony/client/model/entity/race/UnicornModel.java index a1011f66..5909d612 100644 --- a/src/main/java/com/minelittlepony/client/model/entity/race/UnicornModel.java +++ b/src/main/java/com/minelittlepony/client/model/entity/race/UnicornModel.java @@ -1,15 +1,22 @@ package com.minelittlepony.client.model.entity.race; -import com.minelittlepony.api.model.BodyPart; -import com.minelittlepony.api.model.IUnicorn; +import com.minelittlepony.api.model.*; +import com.minelittlepony.api.pony.IPony; +import com.minelittlepony.api.pony.meta.Size; +import com.minelittlepony.api.pony.meta.Sizes; import com.minelittlepony.client.MineLittlePony; import com.minelittlepony.client.model.part.UnicornHorn; +import com.minelittlepony.client.render.PonyRenderDispatcher; import com.minelittlepony.client.util.render.RenderList; import com.minelittlepony.mson.api.ModelView; import net.minecraft.client.model.ModelPart; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.model.json.ModelTransformationMode; +import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.LivingEntity; -import net.minecraft.util.Arm; +import net.minecraft.item.ItemStack; +import net.minecraft.util.*; /** * Used for both unicorns and alicorns since there's no logical way to keep them distinct and not duplicate stuff. @@ -73,4 +80,54 @@ public class UnicornModel extends EarthPonyModel impl } return super.getArm(side); } + + @Override + protected void positionheldItem(Arm arm, MatrixStack matrices) { + super.positionheldItem(arm, matrices); + + if (!MineLittlePony.getInstance().getConfig().tpsmagic.get() || !hasMagic()) { + return; + } + + float left = arm == Arm.LEFT ? -1 : 1; + + matrices.translate(-0.3F, -0.675F, -0.3F - (0.3F * left)); + + UseAction action = getAttributes().heldStack.getUseAction(); + + if ((action == UseAction.SPYGLASS || action == UseAction.BOW) && getAttributes().itemUseTime > 0) { + Arm main = getAttributes().mainArm; + if (getAttributes().activeHand == Hand.OFF_HAND) { + main = main.getOpposite(); + } + if (main == arm) { + if (action == UseAction.SPYGLASS) { + Size size = getSize(); + float x = 0.4F; + float z = -0.5F; + + if (size == Sizes.TALL || size == Sizes.YEARLING) { + z += 0.05F; + } else if (size == Sizes.FOAL) { + x -= 0.1F; + z -= 0.1F; + } + + //matrices.translate(x * left, -0.2, z); + matrices.translate(-z, 0.9, x * left); + } else { + matrices.translate(-0.6, -0.2, 0); + } + } + } + } + + @Override + public void postItemRender(IPony pony, T entity, ItemStack drop, ModelTransformationMode transform, Arm hand, MatrixStack stack, VertexConsumerProvider renderContext) { + if (!MineLittlePony.getInstance().getConfig().tpsmagic.get() || !hasMagic()) { + return; + } + + PonyRenderDispatcher.getInstance().getMagicRenderer().renderItemGlow(pony, entity, drop, transform, hand, getMagicColor(), stack, renderContext); + } } diff --git a/src/main/java/com/minelittlepony/client/render/entity/AbstractPonyRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/AbstractPonyRenderer.java index 31ada979..bae490c9 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/AbstractPonyRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/AbstractPonyRenderer.java @@ -20,14 +20,13 @@ import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.entity.EntityRendererFactory; import net.minecraft.client.render.entity.MobEntityRenderer; import net.minecraft.client.render.entity.feature.FeatureRenderer; -import net.minecraft.client.render.entity.model.EntityModel; -import net.minecraft.client.render.entity.model.PlayerEntityModel; +import net.minecraft.client.render.entity.model.*; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.mob.MobEntity; import net.minecraft.text.Text; import net.minecraft.util.Identifier; -public abstract class AbstractPonyRenderer & IPonyModel> extends MobEntityRenderer implements IPonyRenderContext { +public abstract class AbstractPonyRenderer & IPonyModel & ModelWithArms> extends MobEntityRenderer implements IPonyRenderContext { protected final EquineRenderManager manager = new EquineRenderManager<>(this); @@ -54,7 +53,7 @@ public abstract class AbstractPonyRenderer createHeldItemFeature(EntityRendererFactory.Context context) { - return new GlowingItemFeature<>(this); + return new HeldItemFeature<>(this, context.getHeldItemRenderer()); } @Override @@ -144,7 +143,7 @@ public abstract class AbstractPonyRenderer & IPonyModel> AbstractPonyRenderer proxy(EntityRendererFactory.Context context, ModelKey key, TextureSupplier texture, float scale, + public static & IPonyModel & ModelWithArms> AbstractPonyRenderer proxy(EntityRendererFactory.Context context, ModelKey key, TextureSupplier texture, float scale, List exportedLayers, Consumer modelConsumer) { var renderer = new AbstractPonyRenderer(context, key, texture, scale) { @Override diff --git a/src/main/java/com/minelittlepony/client/render/entity/EnderStallionRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/EnderStallionRenderer.java index b830bd43..51bef6b0 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/EnderStallionRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/EnderStallionRenderer.java @@ -5,7 +5,6 @@ import com.minelittlepony.client.model.entity.EnderStallionModel; import com.minelittlepony.client.render.entity.feature.GlowingEyesFeature; import com.minelittlepony.client.render.entity.feature.HeldItemFeature; import com.minelittlepony.client.render.entity.npc.textures.TextureSupplier; -import com.minelittlepony.client.render.entity.feature.GlowingItemFeature; import com.minelittlepony.client.render.entity.feature.GlowingEyesFeature.IGlowingRenderer; import net.minecraft.block.BlockState; @@ -39,7 +38,7 @@ public class EnderStallionRenderer extends PonyRenderer createHeldItemFeature(EntityRendererFactory.Context context) { - return new GlowingItemFeature(this) { + return new HeldItemFeature(this, context.getHeldItemRenderer()) { @Override protected ItemStack getRightItem(EndermanEntity entity) { BlockState state = entity.getCarriedBlock(); diff --git a/src/main/java/com/minelittlepony/client/render/entity/PlayerPonyRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/PlayerPonyRenderer.java index e90b5bc5..5811aa84 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/PlayerPonyRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/PlayerPonyRenderer.java @@ -7,15 +7,8 @@ import com.minelittlepony.client.SkinsProxy; import com.minelittlepony.client.model.*; import com.minelittlepony.client.render.DebugBoundingBoxRenderer; import com.minelittlepony.client.render.IPonyRenderContext; +import com.minelittlepony.client.render.entity.feature.*; import com.minelittlepony.client.render.EquineRenderManager; -import com.minelittlepony.client.render.entity.feature.DJPon3Feature; -import com.minelittlepony.client.render.entity.feature.PassengerFeature; -import com.minelittlepony.client.render.entity.feature.GearFeature; -import com.minelittlepony.client.render.entity.feature.GlowingItemFeature; -import com.minelittlepony.client.render.entity.feature.ArmourFeature; -import com.minelittlepony.client.render.entity.feature.CapeFeature; -import com.minelittlepony.client.render.entity.feature.SkullFeature; -import com.minelittlepony.client.render.entity.feature.ElytraFeature; import java.util.List; @@ -57,7 +50,7 @@ public class PlayerPonyRenderer extends PlayerEntityRenderer implements IPonyRen || feature instanceof ShoulderParrotFeatureRenderer; }); addLayer(new ArmourFeature<>(this, context.getModelManager())); - addLayer(new GlowingItemFeature<>(this)); + addLayer(new HeldItemFeature(this, context.getHeldItemRenderer())); addLayer(new DJPon3Feature<>(this)); addLayer(new CapeFeature<>(this)); addLayer(new SkullFeature<>(this, context.getModelLoader())); diff --git a/src/main/java/com/minelittlepony/client/render/entity/WitchRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/WitchRenderer.java index b6a390aa..c78003e1 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/WitchRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/WitchRenderer.java @@ -2,16 +2,10 @@ package com.minelittlepony.client.render.entity; import com.minelittlepony.client.model.ModelType; import com.minelittlepony.client.model.entity.WitchPonyModel; -import com.minelittlepony.client.render.entity.feature.HeldItemFeature; import com.minelittlepony.client.render.entity.npc.textures.TextureSupplier; import net.minecraft.client.render.entity.EntityRendererFactory; -import net.minecraft.client.render.model.json.ModelTransformationMode; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.util.math.RotationAxis; import net.minecraft.entity.mob.WitchEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Arm; import net.minecraft.util.Identifier; public class WitchRenderer extends PonyRenderer { @@ -21,15 +15,4 @@ public class WitchRenderer extends PonyRenderer { public WitchRenderer(EntityRendererFactory.Context context) { super(context, ModelType.WITCH, TextureSupplier.of(WITCH_TEXTURES), BASE_MODEL_SCALE); } - - @Override - protected HeldItemFeature createHeldItemFeature(EntityRendererFactory.Context context) { - return new HeldItemFeature(this) { - @Override - protected void preItemRender(WitchEntity entity, ItemStack drop, ModelTransformationMode transform, Arm hand, MatrixStack stack) { - super.preItemRender(entity, drop, transform, hand, stack); - stack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(10)); - } - }; - } } diff --git a/src/main/java/com/minelittlepony/client/render/entity/feature/GlowingItemFeature.java b/src/main/java/com/minelittlepony/client/render/entity/feature/GlowingItemFeature.java deleted file mode 100644 index 2513afdd..00000000 --- a/src/main/java/com/minelittlepony/client/render/entity/feature/GlowingItemFeature.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.minelittlepony.client.render.entity.feature; - -import com.minelittlepony.api.model.IUnicorn; -import com.minelittlepony.api.pony.meta.Size; -import com.minelittlepony.api.pony.meta.Sizes; -import com.minelittlepony.client.MineLittlePony; -import com.minelittlepony.client.model.IPonyModel; -import com.minelittlepony.client.render.IPonyRenderContext; -import com.minelittlepony.client.render.PonyRenderDispatcher; - -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.entity.model.EntityModel; -import net.minecraft.client.render.model.json.ModelTransformationMode; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Arm; -import net.minecraft.util.Hand; -import net.minecraft.util.UseAction; - -public class GlowingItemFeature & IPonyModel> extends HeldItemFeature { - - public GlowingItemFeature(IPonyRenderContext context) { - super(context); - } - - protected boolean isUnicorn() { - return MineLittlePony.getInstance().getConfig().tpsmagic.get() - && getContextModel() instanceof IUnicorn - && ((IUnicorn)getContextModel()).hasMagic(); - } - - @Override - protected void preItemRender(T entity, ItemStack drop, ModelTransformationMode transform, Arm arm, MatrixStack stack) { - super.preItemRender(entity, drop, transform, arm, stack); - - if (!isUnicorn()) { - return; - } - - float left = arm == Arm.LEFT ? 1 : -1; - - stack.translate(-0.3F - (0.3F * left), 0.375F, 0.6F); - - UseAction action = drop.getUseAction(); - - if ((action == UseAction.SPYGLASS || action == UseAction.BOW) && entity.getItemUseTimeLeft() > 0) { - Arm main = entity.getMainArm(); - if (entity.getActiveHand() == Hand.OFF_HAND) { - main = main.getOpposite(); - } - if (main == arm) { - if (action == UseAction.SPYGLASS) { - Size size = getContextModel().getSize(); - float x = 0.4F; - float z = -0.8F; - - if (size == Sizes.TALL || size == Sizes.YEARLING) { - z += 0.05F; - } else if (size == Sizes.FOAL) { - x -= 0.1F; - z -= 0.1F; - } - - stack.translate(x * left, -0.2, z); - } else { - stack.translate(0, 0.2, -0.6); - } - } - } - } - - @Override - protected void postItemRender(T entity, ItemStack drop, ModelTransformationMode transform, Arm hand, MatrixStack stack, VertexConsumerProvider renderContext) { - if (isUnicorn()) { - PonyRenderDispatcher.getInstance().getMagicRenderer().renderItemGlow(getContext().getEntityPony(entity), entity, drop, transform, hand, ((IUnicorn)getContextModel()).getMagicColor(), stack, renderContext); - } - } -} diff --git a/src/main/java/com/minelittlepony/client/render/entity/feature/HeldItemFeature.java b/src/main/java/com/minelittlepony/client/render/entity/feature/HeldItemFeature.java index 43b2a9db..d4335033 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/feature/HeldItemFeature.java +++ b/src/main/java/com/minelittlepony/client/render/entity/feature/HeldItemFeature.java @@ -2,26 +2,23 @@ package com.minelittlepony.client.render.entity.feature; import com.minelittlepony.api.model.BodyPart; import com.minelittlepony.client.model.IPonyModel; -import com.minelittlepony.client.render.IPonyRenderContext; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.OverlayTexture; import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.entity.feature.FeatureRendererContext; +import net.minecraft.client.render.entity.feature.HeldItemFeatureRenderer; import net.minecraft.client.render.entity.model.EntityModel; import net.minecraft.client.render.entity.model.ModelWithArms; +import net.minecraft.client.render.item.HeldItemRenderer; import net.minecraft.client.render.model.json.ModelTransformationMode; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.LivingEntity; import net.minecraft.item.ItemStack; import net.minecraft.util.Arm; -import net.minecraft.util.Hand; -import net.minecraft.util.UseAction; -import net.minecraft.util.math.RotationAxis; -public class HeldItemFeature & IPonyModel> extends AbstractPonyFeature { +public class HeldItemFeature & IPonyModel & ModelWithArms> extends HeldItemFeatureRenderer { - public HeldItemFeature(IPonyRenderContext livingPony) { - super(livingPony); + public HeldItemFeature(FeatureRendererContext context, HeldItemRenderer renderer) { + super(context, renderer); } protected ItemStack getLeftItem(T entity) { @@ -35,7 +32,6 @@ public class HeldItemFeature & return main ? entity.getMainHandStack() : entity.getOffHandStack(); } - @Override public void render(MatrixStack stack, VertexConsumerProvider renderContext, int lightUv, T entity, float limbDistance, float limbAngle, float tickDelta, float age, float headYaw, float headPitch) { @@ -49,70 +45,12 @@ public class HeldItemFeature & model.transform(BodyPart.LEGS, stack); - renderHeldItem(entity, right, ModelTransformationMode.THIRD_PERSON_RIGHT_HAND, Arm.RIGHT, stack, renderContext, lightUv); - renderHeldItem(entity, left, ModelTransformationMode.THIRD_PERSON_LEFT_HAND, Arm.LEFT, stack, renderContext, lightUv); - + model.getAttributes().heldStack = right; + renderItem(entity, right, ModelTransformationMode.THIRD_PERSON_RIGHT_HAND, Arm.RIGHT, stack, renderContext, lightUv); + model.getAttributes().heldStack = left; + renderItem(entity, left, ModelTransformationMode.THIRD_PERSON_LEFT_HAND, Arm.LEFT, stack, renderContext, lightUv); + model.getAttributes().heldStack = ItemStack.EMPTY; stack.pop(); } } - - private void renderHeldItem(T entity, ItemStack drop, ModelTransformationMode transform, Arm arm, MatrixStack stack, VertexConsumerProvider renderContext, int lightUv) { - if (!drop.isEmpty()) { - stack.push(); - renderArm(arm, stack); - - if (getContextModel().getAttributes().isCrouching) { - stack.translate(0, 0.2F, 0); - } - - preItemRender(entity, drop, transform, arm, stack); - MinecraftClient.getInstance().getItemRenderer().renderItem(entity, drop, transform, arm == Arm.LEFT, stack, renderContext, entity.world, lightUv, OverlayTexture.DEFAULT_UV, 0); - postItemRender(entity, drop, transform, arm, stack, renderContext); - - stack.pop(); - } - } - - protected void preItemRender(T entity, ItemStack drop, ModelTransformationMode transform, Arm arm, MatrixStack stack) { - float left = arm == Arm.LEFT ? 1 : -1; - - UseAction action = drop.getUseAction(); - - if (action == UseAction.SPYGLASS && entity.getItemUseTimeLeft() > 0) { - Arm main = entity.getMainArm(); - if (entity.getActiveHand() == Hand.OFF_HAND) { - main = main.getOpposite(); - } - if (main == arm) { - stack.translate(left * -0.05F, 0.5F, 0.7F); - stack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-60)); - stack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-90)); - stack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(left * 180)); - stack.translate(left * -0.2F, 0.125F, -1); - - return; - } - } - - if (entity.hasVehicle()) { - stack.translate(left / 10, -0.2F, -0.5F); - } - - stack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(-90)); - stack.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(left * 180)); - stack.translate(left * -0.2F, 0.125F, -1); - } - - protected void postItemRender(T entity, ItemStack drop, ModelTransformationMode transform, Arm hand, MatrixStack stack, VertexConsumerProvider renderContext) { - } - - /** - * Renders the main arm - */ - protected void renderArm(Arm arm, MatrixStack stack) { - M model = getContextModel(); - if (model instanceof ModelWithArms) { - ((ModelWithArms)model).setArmAngle(arm, stack); - } - } } diff --git a/src/main/java/com/minelittlepony/client/render/entity/feature/IllagerHeldItemFeature.java b/src/main/java/com/minelittlepony/client/render/entity/feature/IllagerHeldItemFeature.java index f39ce115..1ef001fd 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/feature/IllagerHeldItemFeature.java +++ b/src/main/java/com/minelittlepony/client/render/entity/feature/IllagerHeldItemFeature.java @@ -1,17 +1,17 @@ package com.minelittlepony.client.render.entity.feature; import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.entity.feature.FeatureRendererContext; +import net.minecraft.client.render.item.HeldItemRenderer; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.mob.IllagerEntity; -import net.minecraft.util.Arm; import com.minelittlepony.client.model.entity.race.AlicornModel; -import com.minelittlepony.client.render.IPonyRenderContext; public class IllagerHeldItemFeature> extends HeldItemFeature { - public IllagerHeldItemFeature(IPonyRenderContext livingPony) { - super(livingPony); + public IllagerHeldItemFeature(FeatureRendererContext livingPony, HeldItemRenderer renderer) { + super(livingPony, renderer); } @Override @@ -21,11 +21,6 @@ public class IllagerHeldItemFeature extends PonyRenderer> createHeldItemFeature(EntityRendererFactory.Context context) { - return new IllagerHeldItemFeature<>(this); + return new IllagerHeldItemFeature<>(this, context.getHeldItemRenderer()); } public static IllagerPonyRenderer vindicator(EntityRendererFactory.Context context) { diff --git a/src/main/java/com/minelittlepony/client/render/entity/npc/PillagerRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/npc/PillagerRenderer.java index 0116b8f6..34ee6b72 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/npc/PillagerRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/npc/PillagerRenderer.java @@ -21,6 +21,6 @@ public class PillagerRenderer extends PonyRenderer> createHeldItemFeature(EntityRendererFactory.Context context) { - return new IllagerHeldItemFeature<>(this); + return new IllagerHeldItemFeature<>(this, context.getHeldItemRenderer()); } }