Skip to content

Commit

Permalink
Bypass blocked item inventory transactions while moving on 2b (#304)
Browse files Browse the repository at this point in the history
* Bypass blocked item inventory transactions while moving on 2b

* Remove unused imports

* Fix player state
  • Loading branch information
Avanatiker authored May 1, 2022
1 parent 943473b commit 611c0ee
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import com.lambda.mixin.world.MixinBlockSoulSand
import com.lambda.mixin.world.MixinBlockWeb
import net.minecraft.init.Blocks
import net.minecraft.item.*
import net.minecraft.network.play.client.CPacketClickWindow
import net.minecraft.network.play.client.CPacketEntityAction
import net.minecraft.network.play.client.CPacketPlayer
import net.minecraft.network.play.client.CPacketPlayerDigging
import net.minecraft.network.play.client.CPacketPlayerDigging.Action
Expand All @@ -28,6 +30,7 @@ object NoSlowDown : Module(
) {
private val ncpStrict by setting("NCP Strict", true)
private val sneak by setting("Sneak", false)
private val itemMovement by setting("Item Movement", false)
val soulSand by setting("Soul Sand", true)
val cobweb by setting("Cobweb", true)
private val slime by setting("Slime", true)
Expand All @@ -37,6 +40,7 @@ object NoSlowDown : Module(
private val potion by setting("Potions", true, { !allItems })
private val shield by setting("Shield", true, { !allItems })

private var savedClickWindow = CPacketClickWindow()
/*
* InputUpdateEvent is called just before the player is slowed down @see EntityPlayerSP.onLivingUpdate)
* We'll abuse this fact, and multiply moveStrafe and moveForward by 5 to nullify the *0.2f hardcoded by Mojang.
Expand All @@ -51,6 +55,29 @@ object NoSlowDown : Module(
}
}

safeListener<PacketEvent.Send> {
if (itemMovement
&& player.onGround
&& it.packet is CPacketClickWindow
&& it.packet != savedClickWindow
) {
savedClickWindow = it.packet

it.cancel()

if (player.isSprinting) {
player.connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SPRINTING))
}

player.connection.sendPacket(CPacketPlayer.Position(player.posX, player.posY + 0.0626, player.posZ, false))
player.connection.sendPacket(it.packet)

if (player.isSprinting) {
player.connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SPRINTING))
}
}
}

/**
* @author ionar2
* Used with explicit permission and MIT license permission
Expand Down

0 comments on commit 611c0ee

Please sign in to comment.