Skip to content

Commit a17514e

Browse files
committed
added basic swing mode implementation, needs to also change/disable the drop down animation
1 parent f3af721 commit a17514e

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

common/src/main/java/com/lambda/mixin/entity/ClientPlayerEntityMixin.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
import com.lambda.event.events.TickEvent;
77
import com.lambda.interaction.PlayerPacketManager;
88
import com.lambda.interaction.RotationManager;
9+
import com.lambda.module.modules.render.ViewModel;
910
import net.minecraft.client.input.Input;
11+
import net.minecraft.client.network.AbstractClientPlayerEntity;
1012
import net.minecraft.client.network.ClientPlayerEntity;
1113
import net.minecraft.entity.MovementType;
14+
import net.minecraft.util.Hand;
1215
import net.minecraft.util.math.Vec3d;
1316
import org.spongepowered.asm.mixin.Mixin;
1417
import org.spongepowered.asm.mixin.Shadow;
@@ -91,4 +94,16 @@ float fixHeldItemYaw(ClientPlayerEntity instance) {
9194
float fixHeldItemPitch(ClientPlayerEntity instance) {
9295
return Objects.requireNonNullElse(RotationManager.getHandPitch(), instance.getPitch());
9396
}
97+
98+
@Redirect(method = "swingHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"))
99+
private void adjustSwing(AbstractClientPlayerEntity instance, Hand hand) {
100+
ViewModel viewModel = ViewModel.INSTANCE;
101+
102+
if (!viewModel.isEnabled()) {
103+
instance.swingHand(hand);
104+
return;
105+
}
106+
107+
viewModel.adjustSwing(hand, instance);
108+
}
94109
}

common/src/main/java/com/lambda/mixin/render/HeldItemRendererMixin.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@
1616
public class HeldItemRendererMixin {
1717
@Inject(method = "renderFirstPersonItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderArmHoldingItem(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IFFLnet/minecraft/util/Arm;)V"))
1818
private void onRenderArmHoldingItem(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack itemStack, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) {
19-
if (ViewModel.INSTANCE.isEnabled()) ViewModel.INSTANCE.transform(itemStack, hand, matrices);
19+
if (!ViewModel.INSTANCE.isEnabled()) return;
20+
21+
ViewModel.INSTANCE.transform(itemStack, hand, matrices);
2022
}
2123

2224
@Inject(method = "renderFirstPersonItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V"))
2325
private void onRenderFirstPersonItem(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack itemStack, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) {
24-
if (ViewModel.INSTANCE.isEnabled()) ViewModel.INSTANCE.transform(itemStack, hand, matrices);
26+
if (!ViewModel.INSTANCE.isEnabled()) return;
27+
28+
ViewModel.INSTANCE.transform(itemStack, hand, matrices);
2529
}
2630
}

common/src/main/kotlin/com/lambda/module/modules/render/ViewModel.kt

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.lambda.module.modules.render
33
import com.lambda.Lambda.mc
44
import com.lambda.module.Module
55
import com.lambda.module.tag.ModuleTag
6+
import net.minecraft.client.network.AbstractClientPlayerEntity
67
import net.minecraft.client.util.math.MatrixStack
78
import net.minecraft.item.ItemStack
89
import net.minecraft.util.Arm
@@ -21,7 +22,7 @@ object ViewModel : Module(
2122
//ToDo: implement the rest of the settings and maybe add a couple more
2223

2324
private val ignoreHand by setting("Ignore Hand", false, "Prevents adjusting the players hand", visibility = { page == Page.General })
24-
val swingMode by setting("Swing Mode", SwingMode.MainHand, "Changes which hands swing", visibility = { page == Page.General })
25+
private val swingMode by setting("Swing Mode", SwingMode.Standard, "Changes which hands swing", visibility = { page == Page.General })
2526
val swingSpeed by setting("Swing Speed", 6, 0..20, 1, "Adjusts how fast the player swings", visibility = { page == Page.General })
2627
val swingProgress by setting("Swing Progress", 0.0f, 0.0f..1.0f, 0.025f, "Renders as if the player was this progress through the swing animation", visibility = { page == Page.General })
2728
val oldSwingAnimation by setting("Old Swing Animation", false, "Adjusts the swing animation to what it looked like in 1.8", visibility = { page == Page.General })
@@ -76,7 +77,7 @@ object ViewModel : Module(
7677
}
7778

7879
enum class SwingMode {
79-
MainHand, OffHand, Both, None
80+
Standard, Opposites, MainHand, OffHand, None
8081
}
8182

8283
fun transform(itemStack: ItemStack, hand: Hand, matrices: MatrixStack) {
@@ -208,4 +209,27 @@ object ViewModel : Module(
208209
}
209210
}
210211
}
212+
213+
fun adjustSwing(hand: Hand, player: AbstractClientPlayerEntity) {
214+
when (swingMode) {
215+
SwingMode.Standard -> swingHand(hand, player)
216+
SwingMode.Opposites -> {
217+
if (hand == Hand.MAIN_HAND)
218+
swingHand(Hand.OFF_HAND, player)
219+
else
220+
swingHand(Hand.MAIN_HAND, player)
221+
}
222+
SwingMode.MainHand -> swingHand(Hand.MAIN_HAND, player)
223+
SwingMode.OffHand -> swingHand(Hand.OFF_HAND, player)
224+
SwingMode.None -> {}
225+
}
226+
}
227+
228+
private fun swingHand(hand: Hand, player: AbstractClientPlayerEntity) {
229+
if ((!player.handSwinging || player.handSwingTicks >= player.handSwingDuration / 2) || player.handSwingTicks < 0) {
230+
player.handSwingTicks = -1
231+
player.handSwinging = true
232+
player.preferredHand = hand
233+
}
234+
}
211235
}

common/src/main/resources/lambda.accesswidener

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ accessible method net/minecraft/entity/Entity movementInputToVelocity (Lnet/mine
1919
accessible method net/minecraft/entity/passive/AbstractHorseEntity setHorseFlag (IZ)V
2020
accessible method net/minecraft/entity/passive/AbstractHorseEntity updateSaddle ()V
2121
accessible field net/minecraft/entity/LivingEntity lastAttackedTicks I
22+
accessible method net/minecraft/entity/LivingEntity getHandSwingDuration ()I
2223

2324
# Camera
2425
accessible method net/minecraft/client/render/Camera setPos (DDD)V

0 commit comments

Comments
 (0)