1+ package simpleclient .mixin .feature .old_animations ;
2+
3+ import com .mojang .blaze3d .platform .GlStateManager ;
4+ import net .minecraft .client .MinecraftClient ;
5+ import net .minecraft .client .network .AbstractClientPlayerEntity ;
6+ import net .minecraft .client .render .item .HeldItemRenderer ;
7+ import net .minecraft .entity .effect .StatusEffect ;
8+ import net .minecraft .entity .player .ClientPlayerEntity ;
9+ import net .minecraft .item .ItemStack ;
10+ import net .minecraft .item .Items ;
11+ import net .minecraft .util .hit .BlockHitResult ;
12+ import net .minecraft .util .math .MathHelper ;
13+ import org .spongepowered .asm .mixin .Final ;
14+ import org .spongepowered .asm .mixin .Mixin ;
15+ import org .spongepowered .asm .mixin .Shadow ;
16+ import org .spongepowered .asm .mixin .Unique ;
17+ import org .spongepowered .asm .mixin .injection .At ;
18+ import org .spongepowered .asm .mixin .injection .Constant ;
19+ import org .spongepowered .asm .mixin .injection .Inject ;
20+ import org .spongepowered .asm .mixin .injection .ModifyConstant ;
21+ import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
22+ import simpleclient .feature .OldAnimations ;
23+
24+ @ Mixin (HeldItemRenderer .class )
25+ public class HeldItemRendererMixin {
26+ @ Shadow private float equipProgress ;
27+ @ Shadow @ Final private MinecraftClient client ;
28+ @ Shadow private ItemStack mainHand ;
29+
30+ @ Unique
31+ private float swingProgress ;
32+
33+ @ Inject (method = "renderArmHoldingItem" , at = @ At ("HEAD" ))
34+ private void renderArmHoldingItem1 (float partialTicks , CallbackInfo ci ) {
35+ if (OldAnimations .ENABLED ) swingProgress = client .player .getHandSwingProgress (partialTicks );
36+ }
37+
38+ @ Inject (method = "applyEquipAndSwingOffset" , at = @ At (value = "HEAD" ))
39+ private void applyEquipAndSwingOffset1 (CallbackInfo ci ) {
40+ if (OldAnimations .ENABLED ) {
41+ if (client .options .attackKey .isPressed () && client .options .useKey .isPressed () && client .result .type == BlockHitResult .Type .BLOCK ) {
42+ ClientPlayerEntity player = client .player ;
43+ int swingAnimationEnd = player .hasStatusEffect (StatusEffect .HASTE ) ? (6 - (1 +
44+ player .getEffectInstance (StatusEffect .HASTE ).getAmplifier ())) : (player .hasStatusEffect (StatusEffect .MINING_FATIGUE ) ? (6 + (1 +
45+ player .getEffectInstance (StatusEffect .MINING_FATIGUE ).getAmplifier ()) * 2 ) : 6 );
46+ if (!player .handSwinging || player .handSwingTicks >= swingAnimationEnd / 2 || player .handSwingTicks < 0 ) {
47+ player .handSwingTicks = -1 ;
48+ player .handSwinging = true ;
49+ }
50+ }
51+ }
52+ }
53+
54+ // Fishing Rod
55+ @ Inject (method = "renderArmHoldingItem" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/item/ItemStack;getItem()Lnet/minecraft/item/Item;" ))
56+ public void renderArmHoldingItem2 (float partialTicks , CallbackInfo ci ) {
57+ if (OldAnimations .ENABLED && mainHand .getItem () == Items .FISHING_ROD ) {
58+ GlStateManager .translate (0.08F , -0.027F , -0.33F );
59+ GlStateManager .scale (0.93F , 1.0F , 1.0F );
60+ }
61+ }
62+
63+ // Eating, Drinking
64+ @ Inject (at = @ At (value = "HEAD" ), method = "applyEatOrDrinkTransformation" , cancellable = true )
65+ private void applyEatOrDrinkTransformation (AbstractClientPlayerEntity abstractClientPlayerEntity , float partialTicks , CallbackInfo ci ) {
66+ if (OldAnimations .ENABLED ) {
67+ ci .cancel ();
68+ float useAmount = (float ) abstractClientPlayerEntity .getItemUseTicks () - partialTicks + 1.0F ;
69+ float f1 = 1.0F - useAmount / (float ) mainHand .getMaxUseTime ();
70+ float f2 = 1.0F - f1 ;
71+ f2 = f2 * f2 * f2 ;
72+ f2 = f2 * f2 * f2 ;
73+ f2 = f2 * f2 * f2 ;
74+ float f3 = 1.0F - f2 ;
75+ GlStateManager .translate (0.0F , MathHelper .abs (MathHelper .cos (useAmount / 4.0F * 3.1415927F ) * 0.1F ) * (float ) ((double ) f1 > 0.2D ? 1 : 0 ), 0.0F );
76+ GlStateManager .translate (f3 * 0.6F , -f3 * 0.5F , 0.0F );
77+ GlStateManager .rotate (f3 * 90.0F , 0.0F , 1.0F , 0.0F );
78+ GlStateManager .rotate (f3 * 10.0F , 1.0F , 0.0F , 0.0F );
79+ GlStateManager .rotate (f3 * 30.0F , 0.0F , 0.0F , 1.0F );
80+ }
81+ }
82+
83+ // Blocking
84+ @ Inject (at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/render/item/HeldItemRenderer;applySwordBlockTransformation()V" , shift = At .Shift .AFTER ), method = "renderArmHoldingItem" )
85+ private void applySwordBlockTransformation (CallbackInfo ci ) {
86+ if (OldAnimations .ENABLED ) {
87+ GlStateManager .scale (0.83F , 0.88F , 0.85F );
88+ GlStateManager .translate (-0.3F , 0.1F , 0.0F );
89+ }
90+ }
91+
92+ // Bow
93+ @ Inject (at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/render/item/HeldItemRenderer;applyBowTransformation(FLnet/minecraft/client/network/AbstractClientPlayerEntity;)V" , shift = At .Shift .AFTER ), method = "renderArmHoldingItem" )
94+ private void transformBow (float f , CallbackInfo ci ) {
95+ if (OldAnimations .ENABLED ) GlStateManager .translate (0.0F , 0.1F , -0.15F );
96+ }
97+
98+ @ ModifyConstant (method = "renderArmHoldingItem" , constant = @ Constant (floatValue = 0.0F ))
99+ private float enableBlockHits (float constant ) {
100+ return OldAnimations .ENABLED ? swingProgress : constant ;
101+ }
102+ }
0 commit comments