Animations module

Animations: Minecraft 26.3 cheat module, full source for every implementation (2 clients: MelaHack (ThunderHack fork), LiquidBounce (Kotlin)).

2 implementationsRENDER

Full module source: 2 implementations

Every implementation below is the complete module file, verbatim. Expand a client to read its code.

MelaHack (ThunderHack fork)RENDERsrc/main/java/thunder/hack/features/modules/render/Animations.javaJava · 435 lines · 23.1 KB

Nice hand animations.

SettingsOnlyAuraDisableSwapMainDisableSwapOffModeSlowAnimationSlowValue
Animations.javaJava · Minecraft 26.2 · 435 lines · 23.1 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.render;
2
3
import com.mojang.blaze3d.vertex.PoseStack;
4
import com.mojang.math.Axis;
5
import meteordevelopment.orbit.EventHandler;
6
import net.minecraft.client.player.AbstractClientPlayer;
7
import net.minecraft.client.renderer.SubmitNodeCollector;
8
import net.minecraft.client.renderer.item.ItemStackRenderState;
9
import net.minecraft.client.renderer.texture.OverlayTexture;
10
import net.minecraft.network.protocol.game.ServerboundSwingPacket;
11
import net.minecraft.util.Mth;
12
import net.minecraft.world.InteractionHand;
13
import net.minecraft.world.entity.HumanoidArm;
14
import net.minecraft.world.entity.LivingEntity;
15
import net.minecraft.world.item.CrossbowItem;
16
import net.minecraft.world.item.ItemDisplayContext;
17
import net.minecraft.world.item.ItemStack;
18
import net.minecraft.world.item.Items;
19
import org.jetbrains.annotations.NotNull;
20
import thunder.hack.ThunderHack;
21
import thunder.hack.core.manager.client.ModuleManager;
22
import thunder.hack.events.impl.EventHeldItemRenderer;
23
import thunder.hack.events.impl.PacketEvent;
24
import thunder.hack.injection.accesors.IHeldItemRenderer;
25
import thunder.hack.features.modules.Module;
26
import thunder.hack.features.modules.combat.Aura;
27
import thunder.hack.setting.Setting;
28
29
public class Animations extends Module {
30
    public Animations() {
31
        super("Animations", Category.RENDER);
32
    }
33
34
    private final Setting<Boolean> onlyaura = new Setting<>("OnlyAura", false);
35
    public Setting<Boolean> oldAnimationsM = new Setting<>("DisableSwapMain", true);
36
    public Setting<Boolean> oldAnimationsOff = new Setting<>("DisableSwapOff", true);
37
    private final Setting<Mode> mode = new Setting<Mode>("Mode", Mode.Default);
38
    public static Setting<Boolean> slowAnimation = new Setting<>("SlowAnimation", true);
39
    public static Setting<Integer> slowAnimationVal = new Setting<>("SlowValue", 12, 1, 50);
40
41
    public boolean flip;
42
43
    private enum Mode {
44
        Normal, Default, One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Eleven, Twelve, Thirteen, Fourteen
45
    }
46
47
    public boolean shouldAnimate() {
48
        return isEnabled()
49
                && (!onlyaura.getValue() || ModuleManager.aura.isEnabled() && Aura.target != null)
50
                && mode.getValue() != Mode.Normal;
51
    }
52
53
    public boolean shouldChangeAnimationDuration() {
54
        return isEnabled()
55
                && (!onlyaura.getValue() || ModuleManager.aura.isEnabled() && Aura.target != null);
56
    }
57
58
    @Override
59
    public void onUpdate() {
60
        if (fullNullCheck()) return;
61
        if (oldAnimationsM.getValue() && ((IHeldItemRenderer) mc.getEntityRenderDispatcher().getItemInHandRenderer()).getEquippedProgressMainHand() <= 1f) {
62
            ((IHeldItemRenderer) mc.getEntityRenderDispatcher().getItemInHandRenderer()).setEquippedProgressMainHand(1f);
63
            ((IHeldItemRenderer) mc.getEntityRenderDispatcher().getItemInHandRenderer()).setItemStackMainHand(mc.player.getMainHandItem());
64
        }
65
66
        if (oldAnimationsOff.getValue() && ((IHeldItemRenderer) mc.getEntityRenderDispatcher().getItemInHandRenderer()).getEquippedProgressOffHand() <= 1f) {
67
            ((IHeldItemRenderer) mc.getEntityRenderDispatcher().getItemInHandRenderer()).setEquippedProgressOffHand(1f);
68
            ((IHeldItemRenderer) mc.getEntityRenderDispatcher().getItemInHandRenderer()).setItemStackOffHand(mc.player.getOffhandItem());
69
        }
70
    }
71
72
    @EventHandler
73
    public void onPacketSend(PacketEvent.Send e) {
74
        if (e.getPacket() instanceof ServerboundSwingPacket)
75
            flip = !flip;
76
    }
77
78
    private void renderSwordAnimation(PoseStack matrices, float f, float swingProgress, float equipProgress, HumanoidArm arm) {
79
        if (arm == HumanoidArm.LEFT && (mode.getValue() == Mode.Eleven || mode.getValue() == Mode.Ten || mode.getValue() == Mode.Nine || mode.getValue() == Mode.Three || mode.getValue() == Mode.Thirteen || mode.getValue() == Mode.Fourteen)) {
80
            applyEquipOffset(matrices, arm, equipProgress);
81
            matrices.translate(-ModuleManager.viewModel.positionMainX.getValue(), ModuleManager.viewModel.positionMainY.getValue(), ModuleManager.viewModel.positionMainZ.getValue());
82
            applySwingOffset(matrices, arm, swingProgress);
83
            matrices.translate(ModuleManager.viewModel.positionMainX.getValue(), -ModuleManager.viewModel.positionMainY.getValue(), -ModuleManager.viewModel.positionMainZ.getValue());
84
            return;
85
        }
86
87
88
        switch (mode.getValue()) {
89
            case Default -> {
90
                applyEquipOffset(matrices, arm, equipProgress);
91
                translateToViewModelOff(matrices);
92
                applySwingOffset(matrices, arm, swingProgress);
93
                translateBacklOff(matrices);
94
            }
95
            case One -> {
96
                float n = -0.4F * Mth.sin(Mth.sqrt(swingProgress) * 3.1415927F);
97
                applyEquipOffset(matrices, arm, n);
98
                int i = arm == HumanoidArm.RIGHT ? 1 : -1;
99
                translateToViewModel(matrices);
100
                float f1 = Mth.sin(swingProgress * swingProgress * 3.1415927F);
101
                matrices.mulPose(Axis.YP.rotationDegrees((float) i * (45.0F + f1 * -20.0F)));
102
                float g = Mth.sin(Mth.sqrt(swingProgress) * 3.1415927F);
103
                matrices.mulPose(Axis.ZP.rotationDegrees((float) i * g * -20.0F));
104
                matrices.mulPose(Axis.XP.rotationDegrees(g * 0.0F));
105
                matrices.mulPose(Axis.YP.rotationDegrees((float) i * -45.0F));
106
                translateBack(matrices);
107
            }
108
            case Two ->
109
                    applyEquipOffset(matrices, arm, 0.2F * Mth.sin(Mth.sqrt(swingProgress) * 6.2831855F));
110
            case Three -> {
111
                float n = -0.4F * Mth.sin(Mth.sqrt(swingProgress) * 3.1415927F);
112
                float g = Mth.sin(Mth.sqrt(swingProgress) * 3.1415927F);
113
                applyEquipOffset(matrices, arm, n);
114
                int i = arm == HumanoidArm.RIGHT ? 1 : -1;
115
                translateToViewModel(matrices);
116
                matrices.mulPose(Axis.YP.rotationDegrees((float) i * (45.0F + f * -20.0F)));
117
                matrices.mulPose(Axis.ZP.rotationDegrees((float) i * g * -70.0F));
118
                matrices.mulPose(Axis.XP.rotationDegrees(-70f));
119
                matrices.mulPose(Axis.YP.rotationDegrees((float) i * -45.0F));
120
                translateBack(matrices);
121
            }
122
            case Four -> {
123
                applyEquipOffset(matrices, arm, 0);
124
                translateToViewModel(matrices);
125
                matrices.mulPose(Axis.XP.rotationDegrees(swingProgress > 0 ? -Mth.sin(swingProgress * 13f) * 37f : 0));
126
                translateBack(matrices);
127
            }
128
            case Five -> {
129
                applyEquipOffset(matrices, arm, 0);
130
                int i = arm == HumanoidArm.RIGHT ? 1 : -1;
131
                float g = Mth.sin(Mth.sqrt(swingProgress) * 3.1415927F);
132
                translateToViewModel(matrices);
133
                matrices.mulPose(Axis.ZP.rotationDegrees((float) i * g * -20.0F));
134
                translateBack(matrices);
135
            }
136
            case Six -> {
137
                applyEquipOffset(matrices, arm, equipProgress);
138
                translateToViewModel(matrices);
139
                matrices.mulPose(Axis.XP.rotationDegrees(swingProgress * (flip ? 360.0F : -360)));
140
                translateBack(matrices);
141
            }
142
            case Eight -> {
143
                applyEquipOffset(matrices, arm, equipProgress);
144
                translateToViewModel(matrices);
145
                matrices.mulPose(Axis.XP.rotationDegrees(swingProgress * -360));
146
                translateBack(matrices);
147
            }
148
            case Seven -> {
149
                applyEquipOffset(matrices, arm, equipProgress);
150
                float a = -Mth.sin(swingProgress * 3f) / 2f + 1f;
151
                matrices.scale(a, a, a);
152
            }
153
            case Nine -> {
154
                float g = Mth.sin(Mth.sqrt(swingProgress) * 3.1415927F);
155
                applyEquipOffset(matrices, arm, 0);
156
                translateToViewModel(matrices);
157
                matrices.mulPose(Axis.XP.rotationDegrees(50f));
158
                matrices.mulPose(Axis.YP.rotationDegrees(-30f * (1f - g) - 30f));
159
                matrices.mulPose(Axis.ZP.rotationDegrees(110f));
160
                translateBack(matrices);
161
            }
162
            case Ten -> {
163
                float g = Mth.sin(Mth.sqrt(swingProgress) * 3.1415927F);
164
                matrices.translate(0, 0, 0);
165
                applyEquipOffset(matrices, arm, 0);
166
                translateToViewModel(matrices);
167
                matrices.mulPose(Axis.XP.rotationDegrees(50f));
168
                matrices.mulPose(Axis.YP.rotationDegrees(-60f * g - 50));
169
                matrices.mulPose(Axis.ZP.rotationDegrees(110f));
170
                translateBack(matrices);
171
            }
172
            case Eleven -> {
173
                float g = Mth.sin(Mth.sqrt(swingProgress) * 3.1415927F);
174
                applyEquipOffset(matrices, arm, 0);
175
                translateToViewModel(matrices);
176
                matrices.mulPose(Axis.XP.rotationDegrees(50f));
177
                matrices.mulPose(Axis.YP.rotationDegrees(-60f));
178
                matrices.mulPose(Axis.ZP.rotationDegrees(110f + 20f * g));
179
                translateBack(matrices);
180
            }
181
            case Twelve -> {
182
                float g = Mth.sin(Mth.sqrt(swingProgress) * 3.1415927F);
183
                applyEquipOffset(matrices, arm, 0);
184
                matrices.translate(0, 0, -g / 4f);
185
                translateToViewModel(matrices);
186
                matrices.mulPose(Axis.XP.rotationDegrees(-120f));
187
                translateBack(matrices);
188
            }
189
            case Thirteen -> {
190
                float g = Mth.sin(Mth.sqrt(swingProgress) * 3.1415927F);
191
                applyEquipOffset(matrices, arm, 0);
192
                translateToViewModel(matrices);
193
                matrices.mulPose(Axis.XP.rotationDegrees(-Mth.sin(swingProgress * 3f) * 60f));
194
                matrices.mulPose(Axis.ZP.rotationDegrees(-60f * g));
195
                translateBack(matrices);
196
            }
197
            case Fourteen -> {
198
                if (swingProgress > 0) {
199
                    float g = Mth.sin(Mth.sqrt(swingProgress) * (float) Math.PI);
200
                    matrices.translate(0.56F, equipProgress * -0.2f - 0.5F, -0.7F);
201
202
                    translateToViewModel(matrices);
203
                    matrices.mulPose(Axis.YP.rotationDegrees(45));
204
                    matrices.mulPose(Axis.XP.rotationDegrees(g * -85.0F));
205
206
                    if (ModuleManager.viewModel.isEnabled())
207
                        matrices.translate(-0.1F * ModuleManager.viewModel.scaleMain.getValue(), 0.28F * ModuleManager.viewModel.scaleMain.getValue(), 0.2F * ModuleManager.viewModel.scaleMain.getValue());
208
                    else
209
                        matrices.translate(-0.1F, 0.28F, 0.2F);
210
211
                    matrices.mulPose(Axis.XP.rotationDegrees(-85.0F));
212
                    translateBack(matrices);
213
                } else {
214
                    float n = -0.4f * Mth.sin(Mth.sqrt(swingProgress) * (float) Math.PI);
215
                    float m = 0.2f * Mth.sin(Mth.sqrt(swingProgress) * ((float) Math.PI * 2));
216
                    float f1 = -0.2f * Mth.sin(swingProgress * (float) Math.PI);
217
                    matrices.translate(n, m, f1);
218
                    applyEquipOffset(matrices, arm, equipProgress);
219
                    applySwingOffset(matrices, arm, swingProgress);
220
                }
221
            }
222
        }
223
    }
224
225
226
    public void renderFirstPersonItemCustom(AbstractClientPlayer player, float tickDelta, float pitch, InteractionHand hand, float swingProgress, ItemStack item, float equipProgress, PoseStack matrices, SubmitNodeCollector vertexConsumers, int light) {
227
        if (!player.isScoping()) {
228
            boolean bl = hand == InteractionHand.MAIN_HAND;
229
            HumanoidArm arm = bl ? player.getMainArm() : player.getMainArm().getOpposite();
230
            matrices.pushPose();
231
232
            boolean bl2;
233
            float f = 0;
234
            float g;
235
            float h;
236
            float j;
237
            if (item.is(Items.CROSSBOW)) {
238
                bl2 = CrossbowItem.isCharged(item);
239
                boolean bl3 = arm == HumanoidArm.RIGHT;
240
                int i = bl3 ? 1 : -1;
241
                if (player.isUsingItem() && player.getUseItemRemainingTicks() > 0 && player.getUsedItemHand() == hand) {
242
                    applyEquipOffset(matrices, arm, equipProgress);
243
                    matrices.translate((float) i * -0.4785682F, -0.094387F, 0.05731531F);
244
                    matrices.mulPose(Axis.XP.rotationDegrees(-11.935F));
245
                    matrices.mulPose(Axis.YP.rotationDegrees((float) i * 65.3F));
246
                    matrices.mulPose(Axis.ZP.rotationDegrees((float) i * -9.785F));
247
                    f = (float) item.getUseDuration(mc.player) - ((float) mc.player.getUseItemRemainingTicks() - tickDelta + 1.0F);
248
                    g = f / (float) CrossbowItem.getChargeDuration(item, mc.player);
249
                    if (g > 1.0F) {
250
                        g = 1.0F;
251
                    }
252
253
                    if (g > 0.1F) {
254
                        h = Mth.sin((f - 0.1F) * 1.3F);
255
                        j = g - 0.1F;
256
                        float k = h * j;
257
                        matrices.translate(k * 0.0F, k * 0.004F, k * 0.0F);
258
                    }
259
260
                    matrices.translate(g * 0.0F, g * 0.0F, g * 0.04F);
261
                    matrices.scale(1.0F, 1.0F, 1.0F + g * 0.2F);
262
                    matrices.mulPose(Axis.YN.rotationDegrees((float) i * 45.0F));
263
                } else {
264
                    f = -0.4F * Mth.sin(Mth.sqrt(swingProgress) * 3.1415927F);
265
                    g = 0.2F * Mth.sin(Mth.sqrt(swingProgress) * 6.2831855F);
266
                    h = -0.2F * Mth.sin(swingProgress * 3.1415927F);
267
                    matrices.translate((float) i * f, g, h);
268
                    applyEquipOffset(matrices, arm, equipProgress);
269
                    applySwingOffset(matrices, arm, swingProgress);
270
                    if (bl2 && swingProgress < 0.001F && bl) {
271
                        matrices.translate((float) i * -0.641864F, 0.0F, 0.0F);
272
                        matrices.mulPose(Axis.YP.rotationDegrees((float) i * 10.0F));
273
                    }
274
                }
275
276
                EventHeldItemRenderer event = new EventHeldItemRenderer(hand, item, equipProgress, matrices);
277
                ThunderHack.EVENT_BUS.post(event);
278
                renderItem(player, item, bl3 ? ItemDisplayContext.FIRST_PERSON_RIGHT_HAND : ItemDisplayContext.FIRST_PERSON_LEFT_HAND, !bl3, matrices, vertexConsumers, light);
279
            } else {
280
                bl2 = arm == HumanoidArm.RIGHT;
281
                int l;
282
                float m = 0;
283
                if (player.isUsingItem() && player.getUseItemRemainingTicks() > 0 && player.getUsedItemHand() == hand) {
284
                    l = bl2 ? 1 : -1;
285
                    switch (item.getUseAnimation()) {
286
                        case NONE, BLOCK -> applyEquipOffset(matrices, arm, equipProgress);
287
                        case EAT, DRINK -> {
288
                            applyEatOrDrinkTransformationCustom(matrices, tickDelta, arm, item);
289
                            applyEquipOffset(matrices, arm, equipProgress);
290
                        }
291
                        case BOW -> {
292
                            applyEquipOffset(matrices, arm, equipProgress);
293
                            matrices.translate((float) l * -0.2785682F, 0.18344387F, 0.15731531F);
294
                            matrices.mulPose(Axis.XP.rotationDegrees(-13.935F));
295
                            matrices.mulPose(Axis.YP.rotationDegrees((float) l * 35.3F));
296
                            matrices.mulPose(Axis.ZP.rotationDegrees((float) l * -9.785F));
297
                            m = (float) item.getUseDuration(mc.player) - ((float) mc.player.getUseItemRemainingTicks() - tickDelta + 1.0F);
298
                            f = m / 20.0F;
299
                            f = (f * f + f * 2.0F) / 3.0F;
300
                            if (f > 1.0F) {
301
                                f = 1.0F;
302
                            }
303
                            if (f > 0.1F) {
304
                                g = Mth.sin((m - 0.1F) * 1.3F);
305
                                h = f - 0.1F;
306
                                j = g * h;
307
                                matrices.translate(j * 0.0F, j * 0.004F, j * 0.0F);
308
                            }
309
                            matrices.translate(f * 0.0F, f * 0.0F, f * 0.04F);
310
                            matrices.scale(1.0F, 1.0F, 1.0F + f * 0.2F);
311
                            matrices.mulPose(Axis.YN.rotationDegrees((float) l * 45.0F));
312
                        }
313
                        case SPEAR -> {
314
                            applyEquipOffset(matrices, arm, equipProgress);
315
                            matrices.translate((float) l * -0.5F, 0.7F, 0.1F);
316
                            matrices.mulPose(Axis.XP.rotationDegrees(-55.0F));
317
                            matrices.mulPose(Axis.YP.rotationDegrees((float) l * 35.3F));
318
                            matrices.mulPose(Axis.ZP.rotationDegrees((float) l * -9.785F));
319
                            m = (float) item.getUseDuration(mc.player) - ((float) mc.player.getUseItemRemainingTicks() - tickDelta + 1.0F);
320
                            f = m / 10.0F;
321
                            if (f > 1.0F) {
322
                                f = 1.0F;
323
                            }
324
                            if (f > 0.1F) {
325
                                g = Mth.sin((m - 0.1F) * 1.3F);
326
                                h = f - 0.1F;
327
                                j = g * h;
328
                                matrices.translate(j * 0.0F, j * 0.004F, j * 0.0F);
329
                            }
330
                            matrices.translate(0.0F, 0.0F, f * 0.2F);
331
                            matrices.scale(1.0F, 1.0F, 1.0F + f * 0.2F);
332
                            matrices.mulPose(Axis.YN.rotationDegrees((float) l * 45.0F));
333
                        }
334
                        case BRUSH -> applyBrushTransformation(matrices, tickDelta, arm, item, equipProgress);
335
                    }
336
                } else if (player.isAutoSpinAttack()) {
337
                    applyEquipOffset(matrices, arm, equipProgress);
338
                    l = bl2 ? 1 : -1;
339
                    matrices.translate((float) l * -0.4F, 0.8F, 0.3F);
340
                    matrices.mulPose(Axis.YP.rotationDegrees((float) l * 65.0F));
341
                    matrices.mulPose(Axis.ZP.rotationDegrees((float) l * -85.0F));
342
                } else {
343
                    renderSwordAnimation(matrices, f, swingProgress, equipProgress, arm);
344
                }
345
                EventHeldItemRenderer event = new EventHeldItemRenderer(hand, item, equipProgress, matrices);
346
                ThunderHack.EVENT_BUS.post(event);
347
                renderItem(player, item, bl2 ? ItemDisplayContext.FIRST_PERSON_RIGHT_HAND : ItemDisplayContext.FIRST_PERSON_LEFT_HAND, !bl2, matrices, vertexConsumers, light);
348
            }
349
            matrices.popPose();
350
        }
351
    }
352
353
    private void applyBrushTransformation(PoseStack matrices, float tickDelta, HumanoidArm arm, @NotNull ItemStack stack, float equipProgress) {
354
        applyEquipOffset(matrices, arm, equipProgress);
355
        float f = (float) mc.player.getUseItemRemainingTicks() - tickDelta + 1.0F;
356
        float g = 1.0F - f / (float) stack.getUseDuration(mc.player);
357
        float m = -15.0F + 75.0F * Mth.cos(g * 45.0F * 3.1415927F);
358
359
        if (arm != HumanoidArm.RIGHT) {
360
            matrices.translate(0.1, 0.83, 0.35);
361
            matrices.mulPose(Axis.XP.rotationDegrees(-80.0F));
362
            matrices.mulPose(Axis.YP.rotationDegrees(-90.0F));
363
            matrices.mulPose(Axis.XP.rotationDegrees(m));
364
            matrices.translate(-0.3, 0.22, 0.35);
365
        } else {
366
            matrices.translate(-0.25, 0.22, 0.35);
367
            matrices.mulPose(Axis.XP.rotationDegrees(-80.0F));
368
            matrices.mulPose(Axis.YP.rotationDegrees(90.0F));
369
            matrices.mulPose(Axis.ZP.rotationDegrees(0.0F));
370
            matrices.mulPose(Axis.XP.rotationDegrees(m));
371
        }
372
    }
373
374
    private void applyEquipOffset(@NotNull PoseStack matrices, HumanoidArm arm, float equipProgress) {
375
        int i = arm == HumanoidArm.RIGHT ? 1 : -1;
376
        matrices.translate((float) i * 0.56F, -0.52F + equipProgress * -0.6F, -0.72F);
377
    }
378
379
    private void applySwingOffset(@NotNull PoseStack matrices, HumanoidArm arm, float swingProgress) {
380
        int i = arm == HumanoidArm.RIGHT ? 1 : -1;
381
        float f = Mth.sin(swingProgress * swingProgress * 3.1415927F);
382
        matrices.mulPose(Axis.YP.rotationDegrees((float) i * (45.0F + f * -20.0F)));
383
        float g = Mth.sin(Mth.sqrt(swingProgress) * 3.1415927F);
384
        matrices.mulPose(Axis.ZP.rotationDegrees((float) i * g * -20.0F));
385
        matrices.mulPose(Axis.XP.rotationDegrees(g * -80.0F));
386
        matrices.mulPose(Axis.YP.rotationDegrees((float) i * -45.0F));
387
    }
388
389
    public void renderItem(LivingEntity entity, ItemStack stack, ItemDisplayContext renderMode, boolean leftHanded, PoseStack matrices, SubmitNodeCollector collector, int light) {
390
        if (stack.isEmpty()) {
391
            return;
392
        }
393
        ItemStackRenderState state = new ItemStackRenderState();
394
        mc.getItemModelResolver().updateForLiving(state, stack, renderMode, entity);
395
        state.submit(matrices, collector, light, OverlayTexture.NO_OVERLAY, entity.getId() + renderMode.ordinal());
396
    }
397
398
    private void applyEatOrDrinkTransformationCustom(PoseStack matrices, float tickDelta, HumanoidArm arm, @NotNull ItemStack stack) {
399
        float f = (float) mc.player.getUseItemRemainingTicks() - tickDelta + 1.0F;
400
        float g = f / (float) stack.getUseDuration(mc.player);
401
        float h;
402
        if (g < 0.8F) {
403
            h = Mth.abs(Mth.cos(f / 4.0F * 3.1415927F) * 0.005F);
404
            matrices.translate(0.0F, h, 0.0F);
405
        }
406
        h = 1.0F - (float) Math.pow(g, 27.0);
407
        int i = arm == HumanoidArm.RIGHT ? 1 : -1;
408
409
        matrices.translate(h * 0.6F * (float) i * ModuleManager.viewModel.eatX.getValue(), h * -0.5F * ModuleManager.viewModel.eatY.getValue(), h * 0.0F);
410
        matrices.mulPose(Axis.YP.rotationDegrees((float) i * h * 90.0F));
411
        matrices.mulPose(Axis.XP.rotationDegrees(h * 10.0F));
412
        matrices.mulPose(Axis.ZP.rotationDegrees((float) i * h * 30.0F));
413
    }
414
415
    private void translateToViewModel(PoseStack matrices) {
416
        if (ModuleManager.viewModel.isEnabled())
417
            matrices.translate(ModuleManager.viewModel.positionMainX.getValue(), ModuleManager.viewModel.positionMainY.getValue(), ModuleManager.viewModel.positionMainZ.getValue());
418
    }
419
420
    private void translateToViewModelOff(PoseStack matrices) {
421
        if (ModuleManager.viewModel.isEnabled())
422
            matrices.translate(-ModuleManager.viewModel.positionMainX.getValue(), ModuleManager.viewModel.positionMainY.getValue(), ModuleManager.viewModel.positionMainZ.getValue());
423
    }
424
425
    private void translateBack(PoseStack matrices) {
426
        if (ModuleManager.viewModel.isEnabled())
427
            matrices.translate(-ModuleManager.viewModel.positionMainX.getValue(), -ModuleManager.viewModel.positionMainY.getValue(), -ModuleManager.viewModel.positionMainZ.getValue());
428
    }
429
430
    private void translateBacklOff(PoseStack matrices) {
431
        if (ModuleManager.viewModel.isEnabled())
432
            matrices.translate(ModuleManager.viewModel.positionMainX.getValue(), -ModuleManager.viewModel.positionMainY.getValue(), -ModuleManager.viewModel.positionMainZ.getValue());
433
    }
434
}
435
LiquidBounce (Kotlin)RENDERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/animations/ModuleAnimations.ktKotlin · 323 lines · 11.5 KB

Allows you to modify many of game's animations.

SettingsItemScaleXYPositiveRotationXPositiveRotationYPositiveRotationZSwingDurationIgnoreAirWalkerSwingScale
ModuleAnimations.ktKotlin · Minecraft 26.2 · 323 lines · 11.5 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
3
 *
4
 * Copyright (c) 2015 - 2026 CCBlueX
5
 *
6
 * LiquidBounce is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * LiquidBounce is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
package net.ccbluex.liquidbounce.features.module.modules.render.animations
21
22
import com.mojang.blaze3d.vertex.PoseStack
23
import com.mojang.math.Axis
24
import net.ccbluex.liquidbounce.config.types.group.Mode
25
import net.ccbluex.liquidbounce.config.types.group.ModeValueGroup
26
import net.ccbluex.liquidbounce.config.types.group.ToggleableValueGroup
27
import net.ccbluex.liquidbounce.config.types.list.Tagged
28
import net.ccbluex.liquidbounce.event.events.PlayerStrideEvent
29
import net.ccbluex.liquidbounce.event.handler
30
import net.ccbluex.liquidbounce.features.module.ClientModule
31
import net.ccbluex.liquidbounce.features.module.ModuleCategories
32
import net.ccbluex.liquidbounce.utils.math.toRadians
33
import net.minecraft.util.Mth
34
import net.minecraft.world.entity.HumanoidArm
35
import org.joml.Quaternionf
36
37
/**
38
 * Animations module
39
 *
40
 * This module affects item animations. It allows the user to customize the animation.
41
 * If you are looking forward to contribute to this module, please name your animation with a reasonable name.
42
 * Do not name them after clients or yourself.
43
 * Please credit from where you got the animation from and make sure they are willing to contribute.
44
 * If they are not willing to contribute, please do not add the animation to this module.
45
 */
46
@Suppress("MagicNumber")
47
object ModuleAnimations : ClientModule("Animations", ModuleCategories.RENDER, aliases = listOf("ViewModel")) {
48
49
    init {
50
        tree(MainHand)
51
        tree(OffHand)
52
        tree(EquipOffset)
53
        tree(SwingAnimations)
54
    }
55
56
    object MainHand : ToggleableValueGroup(this, "MainHand", false) {
57
        val mainHandItemScale by float("ItemScale", 0f, -5f..5f)
58
        val mainHandX by float("X", 0f, -5f..5f)
59
        val mainHandY by float("Y", 0f, -5f..5f)
60
        val mainHandPositiveX by float("PositiveRotationX", 0f, -50f..50f)
61
        val mainHandPositiveY by float("PositiveRotationY", 0f, -50f..50f)
62
        val mainHandPositiveZ by float("PositiveRotationZ", 0f, -50f..50f)
63
    }
64
65
    object OffHand : ToggleableValueGroup(this, "OffHand", false) {
66
        val offHandItemScale by float("ItemScale", 0f, -5f..5f)
67
        val offHandX by float("X", 0f, -1f..1f)
68
        val offHandY by float("Y", 0f, -1f..1f)
69
        val OffHandPositiveX by float("PositiveRotationX", 0f, -50f..50f)
70
        val OffHandPositiveY by float("PositiveRotationY", 0f, -50f..50f)
71
        val OffHandPositiveZ by float("PositiveRotationZ", 0f, -50f..50f)
72
    }
73
74
    val swingDuration by int("SwingDuration", 6, 1..20)
75
76
    /**
77
     * A choice that allows the user to choose the animation that will be used during the blocking
78
     * of a sword.
79
     * This choice is only used when the [ModuleSwordBlock] module is enabled.
80
     */
81
82
    val swingAnimation = SwingAnimations
83
    val blockAnimationChoice = choices(
84
        "BlockingAnimation", OneSevenAnimation, arrayOf(
85
            OneSevenAnimation,
86
            PushdownAnimation,
87
            SigmaAnimation,
88
            ExhibitionAnimation,
89
            AvatarAnimation,
90
            DortwareAnimation
91
        )
92
    )
93
94
    object EquipOffset : ToggleableValueGroup(this, "EquipOffset", true) {
95
        private val ignore by multiEnumChoice("Ignore",
96
            Ignores.BLOCKING,
97
            Ignores.PLACE
98
        )
99
100
        val ignoreBlocking get() = Ignores.BLOCKING in ignore
101
        val ignorePlace get() = Ignores.PLACE in ignore
102
        val ignoreAmount get() = Ignores.AMOUNT in ignore
103
104
        private enum class Ignores(
105
            override val tag: String
106
        ) : Tagged {
107
            BLOCKING("Blocking"),
108
            PLACE("Place"),
109
            AMOUNT("Amount")
110
        }
111
    }
112
113
    /**
114
     * if true, the walk animation will also be applied in the air.
115
     */
116
    private val airWalker by boolean("AirWalker", false)
117
118
    @Suppress("unused")
119
    val strideHandler = handler<PlayerStrideEvent> { event ->
120
        if (airWalker) {
121
            event.strideForce = 0.1.coerceAtMost(player.deltaMovement.horizontalDistance()).toFloat()
122
        }
123
    }
124
125
    /**
126
     * A choice that aims to transform the held item transformation during the swing progress.
127
     */
128
129
130
    abstract class AnimationMode(name: String) : Mode(name) {
131
132
        override val parent: ModeValueGroup<*>
133
            get() = blockAnimationChoice
134
135
        protected fun applySwingOffset(matrices: PoseStack, arm: HumanoidArm, swingProgress: Float) {
136
            val armSide = if (arm == HumanoidArm.RIGHT) 1 else -1
137
            val f = Mth.sin(swingProgress * swingProgress * Math.PI)
138
            matrices.mulPose(Axis.YP.rotationDegrees(armSide.toFloat() * (45.0f + f * -20.0f)))
139
            val g = Mth.sin(Mth.sqrt(swingProgress) * Math.PI)
140
            matrices.mulPose(Axis.ZP.rotationDegrees(armSide.toFloat() * g * -20.0f))
141
            matrices.mulPose(Axis.XP.rotationDegrees(g * -80.0f))
142
            matrices.mulPose(Axis.YP.rotationDegrees(armSide.toFloat() * -45.0f))
143
        }
144
145
        abstract fun transform(matrices: PoseStack, arm: HumanoidArm, equipProgress: Float, swingProgress: Float)
146
147
    }
148
149
    /**
150
     * This animation is based on the 1.7 animation. It is the closest to the original animation
151
     * if not altered by the user.
152
     *
153
     * This animation is used in the ViaFabricPlus project.
154
     * https://github.com/ViaVersion/ViaFabricPlus/blob/9eb2adf6265cf0ac9d2a17921791642f2b0cdd2c/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/item/MixinHeldItemRenderer.java#L50-L60
155
     */
156
    object OneSevenAnimation : AnimationMode("1.7") {
157
158
        private val translateY by float("Y", 0.1f, 0.05f..0.3f)
159
        private val swingProgressScale by float("SwingScale", 0.9f, 0.1f..1.0f)
160
161
        override fun transform(matrices: PoseStack, arm: HumanoidArm, equipProgress: Float, swingProgress: Float) {
162
            matrices.translate(if (arm == HumanoidArm.RIGHT) -0.1f else 0.1f, translateY, 0.0f)
163
            applySwingOffset(matrices, arm, swingProgress * swingProgressScale)
164
        }
165
166
    }
167
168
    /**
169
     * Based on the [applySwingOffset] but with a different transformation
170
     * during swing progress to make it look like the [PushdownAnimation] from LiquidBounce Legacy.
171
     *
172
     * This animation is not the same as the original, but it is similar.
173
     */
174
    object PushdownAnimation : AnimationMode("Pushdown") {
175
176
        override fun transform(matrices: PoseStack, arm: HumanoidArm, equipProgress: Float, swingProgress: Float) {
177
            matrices.translate(if (arm == HumanoidArm.RIGHT) -0.1f else 0.1f, 0.1f, 0.0f)
178
179
            val g = Mth.sin(Mth.sqrt(swingProgress) * Math.PI)
180
            matrices.mulPose(
181
                Axis.ZP.rotationDegrees(
182
                    (if (arm == HumanoidArm.RIGHT) 1 else -1) * g * 10.0f
183
                )
184
            )
185
            matrices.mulPose(Axis.XP.rotationDegrees(g * -35.0f))
186
        }
187
188
    }
189
190
    object SigmaAnimation : AnimationMode("Sigma") {
191
192
        private val translateY by float("Y", 0.1f, 0.05f..0.3f)
193
194
        override fun transform(matrices: PoseStack, arm: HumanoidArm, equipProgress: Float, swingProgress: Float) {
195
196
            val sine = Mth.sin(Mth.sqrt(swingProgress) * Math.PI)
197
            val sideM = if (arm == HumanoidArm.RIGHT) 1.0f else -1.0f
198
199
            val rot = Quaternionf().rotationAxis(
200
                (-sine * 27.5f * sideM).toRadians(),
201
                -8.0f * sideM,
202
                0.0f,
203
                9.0f
204
            ).rotateAxis(
205
                (-sine * 45.0f * sideM).toRadians(),
206
                1.0f * sideM,
207
                sine / 2.0f,
208
                0.0f
209
            )
210
            matrices.mulPose(rot)
211
212
            matrices.translate(0.0f, translateY, 0.0f)
213
            applySwingOffset(matrices, arm, 0f)
214
        }
215
    }
216
217
    object ExhibitionAnimation : AnimationMode("Exhibition") {
218
219
        private val translateY by float("Y", 0.1f, 0.05f..0.3f)
220
221
        override fun transform(matrices: PoseStack, arm: HumanoidArm, equipProgress: Float, swingProgress: Float) {
222
223
            val sine = Mth.sin(Mth.sqrt(swingProgress) * Math.PI)
224
            val sideM = if (arm == HumanoidArm.RIGHT) 1.0f else -1.0f
225
226
            matrices.translate(0.0, -0.1, 0.0)
227
228
            applySwingOffset(matrices, arm, 0f)
229
230
            matrices.translate(0.1F, 0.4F, -0.1F)
231
232
            val rot = Quaternionf().rotationAxis(
233
                (-sine * 30.0F * sideM).toRadians(),
234
                sine.div(2F),
235
                0.0F,
236
                9.0F
237
            ).rotateAxis(
238
                (-sine * 50.0F * sideM).toRadians(),
239
                0.8F * sideM,
240
                sine.div(2F),
241
                0F
242
            )
243
            matrices.mulPose(rot)
244
245
            matrices.translate(0.0f, translateY - 0.2f, 0.0f)
246
247
        }
248
249
    }
250
251
    object AvatarAnimation : AnimationMode("Avatar") {
252
253
        private val translateY by float("Y", 0.1f, 0.05f..0.3f)
254
255
        override fun transform(matrices: PoseStack, arm: HumanoidArm, equipProgress: Float, swingProgress: Float) {
256
257
            val sine = Mth.sin(Mth.sqrt(swingProgress) * Math.PI)
258
            val sine1 = Mth.sin(swingProgress * swingProgress * Math.PI)
259
            val sideM = if (arm == HumanoidArm.RIGHT) 1.0f else -1.0f
260
261
            matrices.translate(0.2F * sideM, translateY, 0F)
262
263
            val rot = Quaternionf().rotationAxis(
264
                (0.0F * sideM).toRadians(),
265
                0.0F,
266
                1.0F,
267
                0.0F
268
            ).rotateY(
269
                (sine1 * -20.0F * sideM).toRadians()
270
            ).rotateZ(
271
                (sine * -20.0F * sideM).toRadians()
272
            ).rotateAxis(
273
                (sine * -40.0F * sideM).toRadians(),
274
                1.0F * sideM,
275
                0.0F,
276
                0.0F
277
            )
278
            matrices.mulPose(rot)
279
280
            applySwingOffset(matrices, arm, 0f)
281
        }
282
    }
283
284
    object DortwareAnimation : AnimationMode("Dortware") {
285
286
        private val translateY by float("Y", 0.1f, 0.05f..0.3f)
287
288
        override fun transform(matrices: PoseStack, arm: HumanoidArm, equipProgress: Float, swingProgress: Float) {
289
290
            val sine = Mth.sin(Mth.sqrt(swingProgress) * Math.PI)
291
            val sqrtSwing = Mth.sqrt(swingProgress)
292
            val altSine = Mth.sin(sqrtSwing * Math.PI - 3)
293
294
            val rot = Quaternionf().rotationAxis(
295
                (-sine * 10).toRadians(),
296
                0.0f,
297
                15.0f,
298
                200.0f
299
            ).rotateAxis(
300
                (-sine * 10f).toRadians(),
301
                300.0f,
302
                sine.div(2f),
303
                1.0f
304
            )
305
            matrices.mulPose(rot)
306
307
            matrices.translate(3.4, 0.3, -0.4)
308
            matrices.translate(-2.10f, -0.2f, 0.1f)
309
310
            val rot1 = Quaternionf().rotationAxis(
311
                (altSine * 13.0f).toRadians(),
312
                -10.0f,
313
                -1.4f,
314
                -10.0f
315
            )
316
            matrices.mulPose(rot1)
317
318
            matrices.translate(if(arm == HumanoidArm.RIGHT) -1f else -2f, translateY, 0f)
319
320
        }
321
    }
322
}
323