diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/PlayerPoser.java b/src/main/java/com/minelittlepony/unicopia/client/render/PlayerPoser.java index e063a53f..2f68ecbc 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/PlayerPoser.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/PlayerPoser.java @@ -4,6 +4,7 @@ import java.util.Optional; import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.USounds; +import com.minelittlepony.unicopia.UTags; import com.minelittlepony.unicopia.client.minelittlepony.MineLPDelegate; import com.minelittlepony.unicopia.command.CommandArgumentEnum; import com.minelittlepony.unicopia.entity.player.Pony; @@ -20,6 +21,7 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.sound.SoundEvent; import net.minecraft.util.Arm; +import net.minecraft.util.Hand; import net.minecraft.util.StringIdentifiable; import net.minecraft.util.math.*; @@ -40,9 +42,34 @@ public class PlayerPoser { boolean liftRightArm = mainArm == Arm.RIGHT || !ponyRace.isEquine(); ItemStack glasses = GlassesItem.getForEntity(player); - ModelPart head = model.getHead(); + if (context == Context.THIRD_PERSON && !player.isSneaking()) { + Hand leftHand = mainArm == Arm.LEFT ? Hand.MAIN_HAND : Hand.OFF_HAND; + Hand rightHand = mainArm == Arm.LEFT ? Hand.OFF_HAND : Hand.MAIN_HAND; + + float pitchChange = -0.5F; + float yawChange = 0.8F; + + if (player.getStackInHand(rightHand).isIn(UTags.POLEARMS) && (!ponyRace.isEquine() || model.rightArm.pitch != 0)) { + model.rightArm.pitch += pitchChange; + model.rightArm.yaw += yawChange; + if (player.handSwingTicks > 0 && rightHand == Hand.MAIN_HAND) { + model.rightArm.yaw -= 0.5F; + model.rightArm.pitch += 1.5F; + } + } + + if (player.getStackInHand(leftHand).isIn(UTags.POLEARMS) && (!ponyRace.isEquine() || model.leftArm.pitch != 0)) { + model.leftArm.pitch += pitchChange; + model.leftArm.yaw -= yawChange; + if (player.handSwingTicks > 0 && leftHand == Hand.MAIN_HAND) { + model.leftArm.yaw -= 0.5F; + model.leftArm.pitch += 1.5F; + } + } + } + if (glasses.hasCustomName() && "Cool Shades".equals(glasses.getName().getString())) { final float bop = AnimationUtil.beat(player.age, HEAD_NOD_DURATION, HEAD_NOD_GAP) * 3F; head.pitch += bop / 10F; diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/PolearmRenderer.java b/src/main/java/com/minelittlepony/unicopia/client/render/PolearmRenderer.java index eea59a74..6d94f06b 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/PolearmRenderer.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/PolearmRenderer.java @@ -4,7 +4,6 @@ import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry; import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry; import net.fabricmc.fabric.api.client.rendering.v1.BuiltinItemRendererRegistry.DynamicItemRenderer; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.item.ClampedModelPredicateProvider; import net.minecraft.client.item.ModelPredicateProviderRegistry; import net.minecraft.client.model.*; import net.minecraft.client.render.VertexConsumerProvider; @@ -18,9 +17,10 @@ import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.LivingEntity; import net.minecraft.item.*; import net.minecraft.util.Identifier; +import net.minecraft.util.math.RotationAxis; import net.minecraft.registry.Registries; -public class PolearmRenderer implements DynamicItemRenderer, ClampedModelPredicateProvider { +public class PolearmRenderer implements DynamicItemRenderer { private static final PolearmRenderer INSTANCE = new PolearmRenderer(); private static final Identifier THROWING = new Identifier("throwing"); @@ -29,7 +29,9 @@ public class PolearmRenderer implements DynamicItemRenderer, ClampedModelPredica public static void register(Item item) { BuiltinItemRendererRegistry.INSTANCE.register(item, INSTANCE); - ModelPredicateProviderRegistry.register(item, THROWING, INSTANCE); + ModelPredicateProviderRegistry.register(item, THROWING, (ItemStack stack, ClientWorld world, LivingEntity entity, int seed) -> { + return entity != null && entity.isUsingItem() && entity.getActiveItem() == stack ? 1 : 0; + }); ModelLoadingRegistry.INSTANCE.registerModelProvider((renderer, out) -> out.accept(getModelId(item))); } @@ -65,16 +67,20 @@ public class PolearmRenderer implements DynamicItemRenderer, ClampedModelPredica matrices.push(); } else { matrices.push(); - matrices.scale(1, -1, -1); + if (mode == ModelTransformationMode.THIRD_PERSON_LEFT_HAND || mode == ModelTransformationMode.THIRD_PERSON_RIGHT_HAND) { + int swap = mode == ModelTransformationMode.THIRD_PERSON_LEFT_HAND ? -1 : 1; + matrices.scale(1.5F, -1.5F, -1.5F); + float offsetX = swap * 0.05F; + matrices.translate(offsetX, 0, 0.05F); + matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(-30 * swap), offsetX, 0.5F, offsetX); + matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(-30 * swap), offsetX, 0.5F, offsetX); + } else { + matrices.scale(1, -1, -1); + } Identifier id = Registries.ITEM.getId(stack.getItem()); Identifier texture = new Identifier(id.getNamespace(), "textures/entity/polearm/" + id.getPath() + ".png"); model.render(matrices, ItemRenderer.getDirectItemGlintConsumer(vertexConsumers, model.getLayer(texture), false, stack.hasGlint()), light, overlay, 1, 1, 1, 1); matrices.pop(); } } - - @Override - public float unclampedCall(ItemStack stack, ClientWorld world, LivingEntity entity, int seed) { - return entity != null && entity.isUsingItem() && entity.getActiveItem() == stack ? 1 : 0; - } }