| 1 | package net.minecraft.client.renderer.entity.state;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.model.HumanoidModel;
|
| 6 | import net.minecraft.client.renderer.item.ItemModelResolver;
|
| 7 | import net.minecraft.client.renderer.item.ItemStackRenderState;
|
| 8 | import net.minecraft.world.entity.HumanoidArm;
|
| 9 | import net.minecraft.world.entity.LivingEntity;
|
| 10 | import net.minecraft.world.entity.LivingEntity.SwingDescription;
|
| 11 | import net.minecraft.world.item.ItemDisplayContext;
|
| 12 | import net.minecraft.world.item.ItemStack;
|
| 13 | import org.jspecify.annotations.Nullable;
|
| 14 |
|
| 15 | @Environment(EnvType.CLIENT)
|
| 16 | public class ArmedEntityRenderState extends LivingEntityRenderState {
|
| 17 | public HumanoidArm mainArm = HumanoidArm.RIGHT;
|
| 18 | public HumanoidModel.ArmPose rightArmPose = HumanoidModel.ArmPose.EMPTY;
|
| 19 | public final ItemStackRenderState rightHandItemState = new ItemStackRenderState();
|
| 20 | public ItemStack rightHandItemStack = ItemStack.EMPTY;
|
| 21 | public HumanoidModel.ArmPose leftArmPose = HumanoidModel.ArmPose.EMPTY;
|
| 22 | public final ItemStackRenderState leftHandItemState = new ItemStackRenderState();
|
| 23 | public ItemStack leftHandItemStack = ItemStack.EMPTY;
|
| 24 | public @Nullable SwingDescription currentSwing;
|
| 25 | public float swingAnimation;
|
| 26 |
|
| 27 | public ItemStackRenderState getMainHandItemState() {
|
| 28 | return this.mainArm == HumanoidArm.RIGHT ? this.rightHandItemState : this.leftHandItemState;
|
| 29 | }
|
| 30 |
|
| 31 | public ItemStack getMainHandItemStack() {
|
| 32 | return this.mainArm == HumanoidArm.RIGHT ? this.rightHandItemStack : this.leftHandItemStack;
|
| 33 | }
|
| 34 |
|
| 35 | public ItemStack getUseItemStackForArm(final HumanoidArm arm) {
|
| 36 | return arm == HumanoidArm.RIGHT ? this.rightHandItemStack : this.leftHandItemStack;
|
| 37 | }
|
| 38 |
|
| 39 | public HumanoidModel.ArmPose getArmPose(final HumanoidArm arm) {
|
| 40 | return switch (arm) {
|
| 41 | case LEFT -> this.leftArmPose;
|
| 42 | case RIGHT -> this.rightArmPose;
|
| 43 | };
|
| 44 | }
|
| 45 |
|
| 46 | public float ticksUsingItem(final HumanoidArm arm) {
|
| 47 | return 0.0F;
|
| 48 | }
|
| 49 |
|
| 50 | public static void extractArmedEntityRenderState(
|
| 51 | final LivingEntity entity, final ArmedEntityRenderState state, final ItemModelResolver itemModelResolver, final float partialTicks
|
| 52 | ) {
|
| 53 | state.mainArm = entity.getMainArm();
|
| 54 | state.currentSwing = entity.getCurrentSwing();
|
| 55 | state.swingAnimation = entity.getSwingAnimation(partialTicks);
|
| 56 | itemModelResolver.updateForLiving(state.rightHandItemState, entity.getItemHeldByArm(HumanoidArm.RIGHT), ItemDisplayContext.THIRD_PERSON_RIGHT_HAND, entity);
|
| 57 | itemModelResolver.updateForLiving(state.leftHandItemState, entity.getItemHeldByArm(HumanoidArm.LEFT), ItemDisplayContext.THIRD_PERSON_LEFT_HAND, entity);
|
| 58 | state.leftHandItemStack = entity.getItemHeldByArm(HumanoidArm.LEFT).copy();
|
| 59 | state.rightHandItemStack = entity.getItemHeldByArm(HumanoidArm.RIGHT).copy();
|
| 60 | }
|
| 61 | }
|
| 62 |
|