SwordBlock module

SwordBlock: Minecraft 26.3 cheat module, full source for every implementation (1 client: LiquidBounce (Kotlin)).

1 implementationCOMBAT

Clients with this module

Full module source: 1 implementation

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

LiquidBounce (Kotlin)COMBATsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/ModuleSwordBlock.ktKotlin · 134 lines · 5.2 KB

Enables 1.8 sword blocking on servers using ViaVersion

SettingsOnlyVisualFakeOnPressingHideShieldSlotApplyToThirdPersonViewAlwaysHideShield
ModuleSwordBlock.ktKotlin · Minecraft 26.2 · 134 lines · 5.2 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
package net.ccbluex.liquidbounce.features.module.modules.combat
20
21
import net.ccbluex.liquidbounce.event.events.PacketEvent
22
import net.ccbluex.liquidbounce.event.sequenceHandler
23
import net.ccbluex.liquidbounce.event.waitTicks
24
import net.ccbluex.liquidbounce.features.module.ClientModule
25
import net.ccbluex.liquidbounce.features.module.ModuleCategories
26
import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.features.KillAuraAutoBlock
27
import net.ccbluex.liquidbounce.utils.client.isBlocksAttacksExisting
28
import net.ccbluex.liquidbounce.utils.entity.isInHand
29
import net.ccbluex.liquidbounce.utils.entity.usingItemOrNull
30
import net.ccbluex.liquidbounce.utils.input.InputTracker.isPressedOnAny
31
import net.ccbluex.liquidbounce.utils.item.isSword
32
import net.minecraft.network.protocol.game.ServerboundUseItemPacket
33
import net.minecraft.world.InteractionHand
34
import net.minecraft.world.entity.LivingEntity
35
import net.minecraft.world.item.ItemStack
36
import net.minecraft.world.item.ShieldItem
37
38
/**
39
 * This module allows the user to block with swords. This makes sense to be used on servers with ViaVersion.
40
 */
41
object ModuleSwordBlock : ClientModule("SwordBlock", ModuleCategories.COMBAT, aliases = listOf("OldBlocking")) {
42
43
    val onlyVisual by boolean("OnlyVisual", false)
44
    val fakeOnPressing by boolean("FakeOnPressing", false).doNotIncludeAlways()
45
    val hideShieldSlot by boolean("HideShieldSlot", false).doNotIncludeAlways()
46
    val applyToThirdPersonView by boolean("ApplyToThirdPersonView", true).doNotIncludeAlways()
47
    private val alwaysHideShield by boolean("AlwaysHideShield", false).doNotIncludeAlways()
48
49
    private val LivingEntity.shouldApplySwordBlockAnimation: Boolean
50
        get() {
51
            if (this === player &&
52
                (KillAuraAutoBlock.blockVisual || fakeOnPressing && mc.options.keyUse.isPressedOnAny)) {
53
                return true
54
            }
55
56
            val usingItem = this.usingItemOrNull ?: return false
57
            return isInHand(usingItem, InteractionHand.OFF_HAND) && usingItem.item is ShieldItem ||
58
                isInHand(usingItem, InteractionHand.MAIN_HAND) && !isBlocksAttacksExisting
59
        }
60
61
    /**
62
     * Determines if the sword block animation should be applied no matter if we
63
     * are actually blocking.
64
     */
65
    @JvmStatic
66
    @JvmOverloads
67
    fun shouldAnimateSwordBlock(entity: LivingEntity, mainHandItem: ItemStack = entity.mainHandItem): Boolean {
68
        return running
69
            && entity.shouldApplySwordBlockAnimation
70
            && mainHandItem.isSword
71
    }
72
73
    @JvmOverloads
74
    fun shouldHideOffhand(
75
        offHandStack: ItemStack = player.offhandItem,
76
        mainHandStack: ItemStack = player.mainHandItem
77
    ): Boolean {
78
        if (!running && !KillAuraAutoBlock.blockVisual) {
79
            return false
80
        }
81
82
        if (offHandStack.item !is ShieldItem) {
83
            return false
84
        }
85
86
        return mainHandStack.isSword || alwaysHideShield
87
    }
88
89
    @Suppress("UNUSED")
90
    private val packetHandler = sequenceHandler<PacketEvent> { event ->
91
        if (onlyVisual) {
92
            return@sequenceHandler
93
        }
94
95
        // If we are already on the old combat protocol or anything blockable protocol,
96
        // we don't need to do anything
97
        if (isBlocksAttacksExisting) {
98
            return@sequenceHandler
99
        }
100
101
        val packet = event.packet
102
103
        if (packet is ServerboundUseItemPacket) {
104
            val hand = packet.hand
105
            val itemInHand = player.getItemInHand(hand) // or activeItem
106
107
            if (hand == InteractionHand.MAIN_HAND && itemInHand.isSword) {
108
                val offHandItem = player.offhandItem
109
                if (offHandItem.item !is ShieldItem) {
110
                    // Until "now" we should get a shield from the server
111
                    waitTicks(1)
112
                    interaction.startPrediction(world) { sequence ->
113
                        // This time we use a new sequence
114
                        ServerboundUseItemPacket(
115
                            InteractionHand.OFF_HAND, sequence,
116
                            player.yRot, player.xRot
117
                        )
118
                    }
119
                } else {
120
                    event.cancelEvent()
121
                    // We use the old sequence
122
                    network.send(
123
                        ServerboundUseItemPacket(
124
                            InteractionHand.OFF_HAND, packet.sequence,
125
                            player.yRot, player.xRot
126
                        )
127
                    )
128
                }
129
            }
130
        }
131
    }
132
133
}
134