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