| 1 | package net.minecraft.client.renderer.entity.layers;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.vertex.PoseStack;
|
| 4 | import com.mojang.math.Axis;
|
| 5 | import net.fabricmc.api.EnvType;
|
| 6 | import net.fabricmc.api.Environment;
|
| 7 | import net.minecraft.client.model.ArmedModel;
|
| 8 | import net.minecraft.client.model.EntityModel;
|
| 9 | import net.minecraft.client.model.effects.SpearAnimations;
|
| 10 | import net.minecraft.client.renderer.SubmitNodeCollector;
|
| 11 | import net.minecraft.client.renderer.entity.RenderLayerParent;
|
| 12 | import net.minecraft.client.renderer.entity.state.ArmedEntityRenderState;
|
| 13 | import net.minecraft.client.renderer.item.ItemStackRenderState;
|
| 14 | import net.minecraft.client.renderer.texture.OverlayTexture;
|
| 15 | import net.minecraft.world.entity.EntityTypes;
|
| 16 | import net.minecraft.world.entity.HumanoidArm;
|
| 17 | import net.minecraft.world.item.ItemStack;
|
| 18 | import net.minecraft.world.item.SwingAnimationType;
|
| 19 |
|
| 20 | @Environment(EnvType.CLIENT)
|
| 21 | public class ItemInHandLayer<S extends ArmedEntityRenderState, M extends EntityModel<S> & ArmedModel<S>> extends RenderLayer<S, M> {
|
| 22 | public ItemInHandLayer(final RenderLayerParent<S, M> renderer) {
|
| 23 | super(renderer);
|
| 24 | }
|
| 25 |
|
| 26 | public void submit(
|
| 27 | final PoseStack poseStack, final SubmitNodeCollector submitNodeCollector, final int lightCoords, final S state, final float yRot, final float xRot
|
| 28 | ) {
|
| 29 | this.submitArmWithItem(state, state.rightHandItemState, state.rightHandItemStack, HumanoidArm.RIGHT, poseStack, submitNodeCollector, lightCoords);
|
| 30 | this.submitArmWithItem(state, state.leftHandItemState, state.leftHandItemStack, HumanoidArm.LEFT, poseStack, submitNodeCollector, lightCoords);
|
| 31 | }
|
| 32 |
|
| 33 | protected void submitArmWithItem(
|
| 34 | final S state,
|
| 35 | final ItemStackRenderState item,
|
| 36 | final ItemStack itemStack,
|
| 37 | final HumanoidArm arm,
|
| 38 | final PoseStack poseStack,
|
| 39 | final SubmitNodeCollector submitNodeCollector,
|
| 40 | final int lightCoords
|
| 41 | ) {
|
| 42 | if (!item.isEmpty()) {
|
| 43 | poseStack.pushPose();
|
| 44 | this.getParentModel().translateToHand(state, arm, poseStack);
|
| 45 | poseStack.rotateDegrees(Axis.XP, -90.0F);
|
| 46 | poseStack.rotateDegrees(Axis.YP, 180.0F);
|
| 47 | boolean isLeftHand = arm == HumanoidArm.LEFT;
|
| 48 | float offsetX = this.useBabyOffset(state) ? 0.0F : 1.0F;
|
| 49 | float offsetY = this.useBabyOffset(state) ? 1.0F : 2.0F;
|
| 50 | float offsetZ = this.useBabyOffset(state) ? -4.5F : -10.0F;
|
| 51 | poseStack.translate((isLeftHand ? -1 : 1) * offsetX / 16.0F, offsetY / 16.0F, offsetZ / 16.0F);
|
| 52 | if (state.currentSwing != null && state.currentSwing.hand().asArm(state.mainArm) == arm && state.currentSwing.animation().type() == SwingAnimationType.STAB) {
|
| 53 | SpearAnimations.thirdPersonAttackItem(state, poseStack);
|
| 54 | }
|
| 55 |
|
| 56 | float ticksUsingItem = state.ticksUsingItem(arm);
|
| 57 | if (ticksUsingItem != 0.0F) {
|
| 58 | (arm == HumanoidArm.RIGHT ? state.rightArmPose : state.leftArmPose).animateUseItem(state, poseStack, ticksUsingItem, arm, itemStack);
|
| 59 | }
|
| 60 |
|
| 61 | item.submit(poseStack, submitNodeCollector, lightCoords, OverlayTexture.NO_OVERLAY, state.outlineColor);
|
| 62 | poseStack.popPose();
|
| 63 | }
|
| 64 | }
|
| 65 |
|
| 66 | private boolean useBabyOffset(final S state) {
|
| 67 | return state.isBaby && state.entityType != EntityTypes.ARMOR_STAND;
|
| 68 | }
|
| 69 | }
|
| 70 |
|