1+ package simpleclient .mixin .feature .legacypvp ;
2+
3+ import com .mojang .blaze3d .vertex .PoseStack ;
4+ import com .mojang .math .Axis ;
5+ import net .minecraft .client .Minecraft ;
6+ import net .minecraft .client .gui .Gui ;
7+ import net .minecraft .client .gui .GuiGraphics ;
8+ import net .minecraft .client .player .AbstractClientPlayer ;
9+ import net .minecraft .client .player .LocalPlayer ;
10+ import net .minecraft .client .renderer .ItemInHandRenderer ;
11+ import net .minecraft .client .renderer .MultiBufferSource ;
12+ import net .minecraft .client .renderer .block .model .ItemTransforms ;
13+ import net .minecraft .util .Mth ;
14+ import net .minecraft .world .InteractionHand ;
15+ import net .minecraft .world .entity .HumanoidArm ;
16+ import net .minecraft .world .item .CrossbowItem ;
17+ import net .minecraft .world .item .ItemDisplayContext ;
18+ import net .minecraft .world .item .ItemStack ;
19+ import net .minecraft .world .item .Items ;
20+ import org .spongepowered .asm .mixin .Final ;
21+ import org .spongepowered .asm .mixin .Mixin ;
22+ import org .spongepowered .asm .mixin .Shadow ;
23+ import org .spongepowered .asm .mixin .Unique ;
24+ import org .spongepowered .asm .mixin .injection .At ;
25+ import org .spongepowered .asm .mixin .injection .Inject ;
26+ import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
27+ import simpleclient .feature .LegacyPvP ;
28+
29+ @ Mixin (ItemInHandRenderer .class )
30+ public abstract class ItemInHandRendererMixin {
31+ @ Shadow @ Final private Minecraft minecraft ;
32+
33+ @ Shadow protected abstract void applyItemArmTransform (PoseStack poseStack , HumanoidArm humanoidArm , float f );
34+
35+ @ Shadow protected abstract void applyItemArmAttackTransform (PoseStack poseStack , HumanoidArm humanoidArm , float f );
36+
37+ @ Shadow protected abstract void applyEatTransform (PoseStack poseStack , float f , HumanoidArm humanoidArm , ItemStack itemStack );
38+
39+ /*@Inject(at = @At("HEAD"), method = "itemUsed", cancellable = true)
40+ public void itemUsed(InteractionHand interactionHand, CallbackInfo ci) {
41+ if (LegacyPvP.ENABLED) ci.cancel();
42+ }*/
43+
44+ @ Inject (at = @ At (value = "HEAD" ), method = "renderArmWithItem" , cancellable = true )
45+ public void renderArmWithItem (AbstractClientPlayer player , float partialTicks , float pitch , InteractionHand hand , float equipProgress , ItemStack itemStack , float swingProgress , PoseStack poseStack , MultiBufferSource multiBufferSource , int packedLight , CallbackInfo ci ) {
46+ if (LegacyPvP .ENABLED && LegacyPvP .BLOCKING && player .getUsedItemHand () == hand ) {
47+ ItemInHandRenderer itemRenderer = minecraft .gameRenderer .itemInHandRenderer ;
48+ poseStack .pushPose ();
49+ boolean mainHand = hand == InteractionHand .MAIN_HAND ;
50+ HumanoidArm arm = mainHand ? player .getMainArm () : player .getMainArm ().getOpposite ();
51+ boolean rightArm = arm == HumanoidArm .RIGHT ;
52+ applyItemArmTransform (poseStack , arm , equipProgress );
53+ applyItemArmAttackTransform (poseStack , arm , swingProgress );
54+ transformBlockFirstPerson (poseStack , arm );
55+ itemRenderer .renderItem (
56+ player ,
57+ itemStack ,
58+ rightArm ? ItemDisplayContext .FIRST_PERSON_RIGHT_HAND : ItemDisplayContext .FIRST_PERSON_LEFT_HAND ,
59+ !rightArm ,
60+ poseStack ,
61+ multiBufferSource ,
62+ packedLight
63+ );
64+ poseStack .popPose ();
65+ ci .cancel ();
66+ }
67+ }
68+
69+ @ Unique
70+ private void transformBlockFirstPerson (PoseStack poseStack , HumanoidArm hand ) {
71+ int signum = hand == HumanoidArm .RIGHT ? 1 : -1 ;
72+ poseStack .translate (signum * -0.14142136F , 0.08F , 0.14142136F );
73+ poseStack .mulPose (Axis .XP .rotationDegrees (-102.25F ));
74+ poseStack .mulPose (Axis .YP .rotationDegrees (signum * 13.365F ));
75+ poseStack .mulPose (Axis .ZP .rotationDegrees (signum * 78.05F ));
76+ }
77+
78+ @ Inject (at = @ At (value = "HEAD" ), method = "renderArmWithItem" , cancellable = true )
79+ public void renderArmWithItem2 (AbstractClientPlayer player , float partialTicks , float pitch , InteractionHand hand , float equipProgress , ItemStack itemStack , float swingProgress , PoseStack poseStack , MultiBufferSource multiBufferSource , int packedLight , CallbackInfo ci ) {
80+ if (LegacyPvP .ENABLED && LegacyPvP .BLOCKING && player .getUseItemRemainingTicks () > 0 && player .getUsedItemHand () == hand ) {
81+ if (itemStack .isEmpty () || itemStack .is (Items .FILLED_MAP )) return ;
82+ ci .cancel ();
83+ boolean mainHand = hand == InteractionHand .MAIN_HAND ;
84+ HumanoidArm arm = mainHand ? player .getMainArm () : player .getMainArm ().getOpposite ();
85+ boolean rightArm = arm == HumanoidArm .RIGHT ;
86+ poseStack .pushPose ();
87+ switch (itemStack .getUseAnimation ()) {
88+ case NONE , BLOCK -> {
89+ applyItemArmTransform (poseStack , arm , equipProgress );
90+ applyItemArmAttackTransform (poseStack , arm , swingProgress );
91+ }
92+ case EAT , DRINK -> {
93+ applyEatTransform (poseStack , partialTicks , arm , itemStack );
94+ applyItemArmTransform (poseStack , arm , equipProgress );
95+ applyItemArmAttackTransform (poseStack , arm , swingProgress );
96+ }
97+ case BOW -> {
98+ applyItemArmTransform (poseStack , arm , equipProgress );
99+ applyItemArmAttackTransform (poseStack , arm , swingProgress );
100+ applyBowTransform (poseStack , partialTicks , arm , itemStack , minecraft );
101+ }
102+ case SPEAR -> {
103+ applyItemArmTransform (poseStack , arm , equipProgress );
104+ applyItemArmAttackTransform (poseStack , arm , swingProgress );
105+ applyTridentTransform (poseStack , partialTicks , arm , itemStack , minecraft );
106+ }
107+ case CROSSBOW -> {
108+ applyItemArmTransform (poseStack , arm , equipProgress );
109+ applyItemArmAttackTransform (poseStack , arm , swingProgress );
110+ applyCrossbowTransform (poseStack , partialTicks , arm , itemStack , minecraft );
111+ }
112+ }
113+ minecraft .gameRenderer .itemInHandRenderer .renderItem (
114+ player ,
115+ itemStack ,
116+ rightArm ? ItemDisplayContext .FIRST_PERSON_RIGHT_HAND : ItemDisplayContext .FIRST_PERSON_LEFT_HAND ,
117+ !rightArm ,
118+ poseStack ,
119+ multiBufferSource ,
120+ packedLight
121+ );
122+ poseStack .popPose ();
123+ }
124+ }
125+
126+ @ Unique
127+ private void applyBowTransform (PoseStack poseStack , float partialTicks , HumanoidArm arm , ItemStack itemStack , Minecraft minecraft ) {
128+ int signum = arm == HumanoidArm .RIGHT ? 1 : -1 ;
129+ poseStack .translate (signum * -0.2785682F , 0.18344387F , 0.15731531F );
130+ poseStack .mulPose (Axis .XP .rotationDegrees (-13.935F ));
131+ poseStack .mulPose (Axis .YP .rotationDegrees (signum * 35.3F ));
132+ poseStack .mulPose (Axis .ZP .rotationDegrees (signum * -9.785F ));
133+ float f8 = itemStack .getUseDuration () - (minecraft .player != null ? minecraft .player .getUseItemRemainingTicks () : 0.0F ) - partialTicks + 1.0F ;
134+ float f12 = f8 / 20.0F ;
135+ f12 = (f12 * f12 + f12 * 2.0F ) / 3.0F ;
136+ if (f12 > 1.0F ) f12 = 1.0F ;
137+ if (f12 > 0.1F ) {
138+ float f15 = Mth .sin ((f8 - 0.1F ) * 1.3F );
139+ float f18 = f12 - 0.1F ;
140+ float f20 = f15 * f18 ;
141+ poseStack .translate (f20 * 0.0F , f20 * 0.004F , f20 * 0.0F );
142+ }
143+ poseStack .translate (f12 * 0.0F , f12 * 0.0F , f12 * 0.04F );
144+ poseStack .scale (1.0F , 1.0F , 1.0F + f12 * 0.2F );
145+ poseStack .mulPose (Axis .YN .rotationDegrees (signum * 45.0F ));
146+ }
147+
148+ @ Unique
149+ private void applyTridentTransform (PoseStack poseStack , float partialTicks , HumanoidArm arm , ItemStack itemStack , Minecraft minecraft ) {
150+ int signum = arm == HumanoidArm .RIGHT ? 1 : -1 ;
151+ poseStack .translate (signum * -0.5F , 0.7F , 0.1F );
152+ poseStack .mulPose (Axis .XP .rotationDegrees (-55.0F ));
153+ poseStack .mulPose (Axis .YP .rotationDegrees (signum * 35.3F ));
154+ poseStack .mulPose (Axis .ZP .rotationDegrees (signum * -9.785F ));
155+ float f7 = itemStack .getUseDuration () - (minecraft .player != null ? minecraft .player .getUseItemRemainingTicks () : 0.0F ) - partialTicks + 1.0F ;
156+ float f11 = f7 / 10.0F ;
157+ if (f11 > 1.0F ) f11 = 1.0F ;
158+ if (f11 > 0.1F ) {
159+ float f14 = Mth .sin ((f7 - 0.1F ) * 1.3F );
160+ float f17 = f11 - 0.1F ;
161+ float f19 = f14 * f17 ;
162+ poseStack .translate (f19 * 0.0F , f19 * 0.004F , f19 * 0.0F );
163+ }
164+ poseStack .translate (0.0D , 0.0D , f11 * 0.2F );
165+ poseStack .scale (1.0F , 1.0F , 1.0F + f11 * 0.2F );
166+ poseStack .mulPose (Axis .YN .rotationDegrees (signum * 45.0F ));
167+ }
168+
169+ @ Unique
170+ private void applyCrossbowTransform (PoseStack poseStack , float partialTicks , HumanoidArm arm , ItemStack itemStack , Minecraft minecraft ) {
171+ int signum = arm == HumanoidArm .RIGHT ? 1 : -1 ;
172+ poseStack .translate (signum * -0.4785682F , -0.094387F , 0.05731531F );
173+ poseStack .mulPose (Axis .XP .rotationDegrees (-11.935F ));
174+ poseStack .mulPose (Axis .YP .rotationDegrees (signum * 65.3F ));
175+ poseStack .mulPose (Axis .ZP .rotationDegrees (signum * -9.785F ));
176+ float f9 = itemStack .getUseDuration () - minecraft .player .getUseItemRemainingTicks () - partialTicks + 1.0F ;
177+ float f13 = f9 / CrossbowItem .getChargeDuration (itemStack );
178+ if (f13 > 1.0F ) f13 = 1.0F ;
179+ if (f13 > 0.1F ) {
180+ float f16 = Mth .sin ((f9 - 0.1F ) * 1.3F );
181+ float f3 = f13 - 0.1F ;
182+ float f4 = f16 * f3 ;
183+ poseStack .translate (f4 * 0.0F , f4 * 0.004F , f4 * 0.0F );
184+ }
185+ poseStack .translate (f13 * 0.0F , f13 * 0.0F , f13 * 0.04F );
186+ poseStack .scale (1.0F , 1.0F , 1.0F + f13 * 0.2F );
187+ poseStack .mulPose (Axis .YN .rotationDegrees (signum * 45.0F ));
188+ }
189+ }
0 commit comments