Files
NeoForge/patches/net/minecraft/client/renderer/ItemInHandRenderer.java.patch
T

100 lines
7.1 KiB
Diff

--- a/net/minecraft/client/renderer/ItemInHandRenderer.java
+++ b/net/minecraft/client/renderer/ItemInHandRenderer.java
@@ -157,11 +_,11 @@
Identifier skinTexture = this.minecraft.player.getSkin().body().texturePath();
if (arm == HumanoidArm.RIGHT) {
avatarRenderer.renderRightHand(
- poseStack, submitNodeCollector, lightCoords, skinTexture, this.minecraft.player.isModelPartShown(PlayerModelPart.RIGHT_SLEEVE)
+ poseStack, submitNodeCollector, lightCoords, skinTexture, this.minecraft.player.isModelPartShown(PlayerModelPart.RIGHT_SLEEVE), this.minecraft.player
);
} else {
avatarRenderer.renderLeftHand(
- poseStack, submitNodeCollector, lightCoords, skinTexture, this.minecraft.player.isModelPartShown(PlayerModelPart.LEFT_SLEEVE)
+ poseStack, submitNodeCollector, lightCoords, skinTexture, this.minecraft.player.isModelPartShown(PlayerModelPart.LEFT_SLEEVE), this.minecraft.player
);
}
@@ -231,7 +_,7 @@
poseStack.translate(-0.5F, -0.5F, 0.0F);
poseStack.scale(0.0078125F, 0.0078125F, 0.0078125F);
MapId id = itemStack.get(DataComponents.MAP_ID);
- MapItemSavedData data = MapItem.getSavedData(id, this.minecraft.level);
+ MapItemSavedData data = MapItem.getSavedData(itemStack, this.minecraft.level);
RenderType renderType = data == null ? MAP_BACKGROUND : MAP_BACKGROUND_CHECKERBOARD;
submitNodeCollector.submitCustomGeometry(poseStack, renderType, (pose, buffer) -> {
buffer.addVertex(pose, -7.0F, 135.0F, 0.0F).setColor(-1).setUv(0.0F, 1.0F).setLight(lightCoords);
@@ -270,9 +_,9 @@
AvatarRenderer<AbstractClientPlayer> avatarRenderer = this.entityRenderDispatcher.getPlayerRenderer(player);
Identifier skinTexture = player.getSkin().body().texturePath();
if (isRightArm) {
- avatarRenderer.renderRightHand(poseStack, submitNodeCollector, lightCoords, skinTexture, player.isModelPartShown(PlayerModelPart.RIGHT_SLEEVE));
+ avatarRenderer.renderRightHand(poseStack, submitNodeCollector, lightCoords, skinTexture, player.isModelPartShown(PlayerModelPart.RIGHT_SLEEVE), player);
} else {
- avatarRenderer.renderLeftHand(poseStack, submitNodeCollector, lightCoords, skinTexture, player.isModelPartShown(PlayerModelPart.LEFT_SLEEVE));
+ avatarRenderer.renderLeftHand(poseStack, submitNodeCollector, lightCoords, skinTexture, player.isModelPartShown(PlayerModelPart.LEFT_SLEEVE), player);
}
}
@@ -345,6 +_,7 @@
float mainHandAttack = attackHand == InteractionHand.MAIN_HAND ? attackValue : 0.0F;
float mainhandInverseArmHeight = this.itemModelResolver.swapAnimationScale(this.mainHandItem)
* (1.0F - Mth.lerp(frameInterp, this.oMainHandHeight, this.mainHandHeight));
+ if(!net.neoforged.neoforge.client.ClientHooks.renderSpecificFirstPersonHand(InteractionHand.MAIN_HAND, poseStack, submitNodeCollector, lightCoords, frameInterp, xRot, mainHandAttack, mainhandInverseArmHeight, this.mainHandItem))
this.submitArmWithItem(
player,
frameInterp,
@@ -363,6 +_,7 @@
float offHandAttack = attackHand == InteractionHand.OFF_HAND ? attackValue : 0.0F;
float offhandInverseArmHeight = this.itemModelResolver.swapAnimationScale(this.offHandItem)
* (1.0F - Mth.lerp(frameInterp, this.oOffHandHeight, this.offHandHeight));
+ if(!net.neoforged.neoforge.client.ClientHooks.renderSpecificFirstPersonHand(InteractionHand.OFF_HAND, poseStack, submitNodeCollector, lightCoords, frameInterp, xRot, offHandAttack, offhandInverseArmHeight, this.offHandItem))
this.submitArmWithItem(
player,
frameInterp,
@@ -431,13 +_,13 @@
if (isMainHand && !player.isInvisible()) {
this.renderPlayerArm(poseStack, submitNodeCollector, lightCoords, inverseArmHeight, attack, arm);
}
- } else if (itemStack.has(DataComponents.MAP_ID)) {
+ } else if (itemStack.getItem() instanceof MapItem) {
if (isMainHand && this.offHandItem.isEmpty()) {
this.renderTwoHandedMap(poseStack, submitNodeCollector, lightCoords, xRot, inverseArmHeight, attack);
} else {
this.renderOneHandedMap(poseStack, submitNodeCollector, lightCoords, inverseArmHeight, arm, attack, itemStack);
}
- } else if (itemStack.is(Items.CROSSBOW)) {
+ } else if (itemStack.getItem() instanceof CrossbowItem) {
this.applyItemArmTransform(poseStack, arm, inverseArmHeight);
boolean charged = CrossbowItem.isCharged(itemStack);
boolean isRightArm = arm == HumanoidArm.RIGHT;
@@ -482,6 +_,8 @@
} else {
boolean isRightArm = arm == HumanoidArm.RIGHT;
int invert = isRightArm ? 1 : -1;
+ // Neo: Allow items to define custom arm animation
+ if (!net.neoforged.neoforge.client.extensions.common.IClientItemExtensions.of(itemStack).applyForgeHandTransform(poseStack, minecraft.player, arm, itemStack, frameInterp, inverseArmHeight, attack))
if (player.isUsingItem() && player.getUseItemRemainingTicks() > 0 && player.getUsedItemHand() == hand) {
ItemUseAnimation useAnimation = itemStack.getUseAnimation();
if (!useAnimation.hasCustomArmTransform()) {
@@ -629,9 +_,18 @@
this.mainHandHeight = Mth.clamp(this.mainHandHeight - 0.4F, 0.0F, 1.0F);
this.offHandHeight = Mth.clamp(this.offHandHeight - 0.4F, 0.0F, 1.0F);
} else {
+ // Neo: allow suppressing re-equip animation when only the stack's data changes
+ boolean swapAnimMain = net.neoforged.neoforge.client.ClientHooks.shouldCauseReequipAnimation(this.mainHandItem, nextMainHand, player.getInventory().getSelectedSlot());
+ boolean swapAnimOff = net.neoforged.neoforge.client.ClientHooks.shouldCauseReequipAnimation(this.offHandItem, nextOffHand, -1);
+
+ if (!swapAnimMain && this.mainHandItem != nextMainHand)
+ this.mainHandItem = nextMainHand;
+ if (!swapAnimOff && this.offHandItem != nextOffHand)
+ this.offHandItem = nextOffHand;
+
float attackAnim = player.getItemSwapScale(1.0F);
- float mainHandTargetHeight = this.mainHandItem != nextMainHand ? 0.0F : attackAnim * attackAnim * attackAnim;
- float offHandTargetHeight = this.offHandItem != nextOffHand ? 0.0F : 1.0F;
+ float mainHandTargetHeight = swapAnimMain ? 0.0F : attackAnim * attackAnim * attackAnim;
+ float offHandTargetHeight = swapAnimOff ? 0.0F : 1.0F;
this.mainHandHeight = this.mainHandHeight + Mth.clamp(mainHandTargetHeight - this.mainHandHeight, -0.4F, 0.4F);
this.offHandHeight = this.offHandHeight + Mth.clamp(offHandTargetHeight - this.offHandHeight, -0.4F, 0.4F);
}