Skip to content
This repository has been archived by the owner on Aug 14, 2024. It is now read-only.

Commit

Permalink
f9bd47c
Browse files Browse the repository at this point in the history
  • Loading branch information
ManInMyVan committed Jun 30, 2024
1 parent 059a21d commit e20b98b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import net.ccbluex.liquidbounce.utils.ServerUtils
import net.ccbluex.liquidbounce.utils.TimerBalanceUtils
import net.ccbluex.liquidbounce.utils.TimerBalanceUtils.balance
import net.ccbluex.liquidbounce.utils.extensions.ping
import net.ccbluex.liquidbounce.utils.inventory.InventoryUtils.serverSlot
import net.ccbluex.liquidbounce.utils.render.ColorUtils
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawRoundedRect2
import net.ccbluex.liquidbounce.utils.render.shader.shaders.RainbowFontShader
Expand Down Expand Up @@ -142,6 +143,8 @@ class Text(x: Double = 10.0, y: Double = 10.0, scale: Float = 1F, side: Side = S
"sneak", "sneaking" -> return (thePlayer.isSneaking || mc.gameSettings.keyBindSneak.isKeyDown)
"sprint", "sprinting" -> return (thePlayer.serverSprintState || thePlayer.isSprinting || mc.gameSettings.keyBindSprint.isKeyDown)
"inventory", "inv" -> return mc.currentScreen is GuiInventory || mc.currentScreen is GuiContainer
"serverslot" -> return serverSlot
"clientslot" -> return thePlayer.inventory?.currentItem
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,20 +223,39 @@ object InventoryUtils : MinecraftInstance(), Listenable {

@EventTarget
fun onWorld(event: WorldEvent) {
if (_serverSlot > 0 || _serverOpenInventory || serverOpenContainer) {
LOGGER.info("previous slot: $_serverSlot")
val player = mc.thePlayer ?: return

// Prevents desync
_serverOpenInventory = false
_serverSlot = 0
serverOpenContainer = false
val prevServerSlot = _serverSlot
val playerSlot = player.inventory.currentItem
val startTime = System.currentTimeMillis()

// Prevent desync in minemen server
serverSlot = _serverSlot
mc.playerController?.currentPlayerItem = serverSlot
if (playerSlot == -1)
return

LOGGER.info("reset slot: $serverSlot")
// TODO: Make better alternative..
if (prevServerSlot != playerSlot) {
LOGGER.info("Previous Slot: $prevServerSlot | Previous Client Slot: ${player.inventory.currentItem}")

// Sync server slot to client-side slot
serverSlot = playerSlot
mc.playerController.updateController()
}

if (prevServerSlot != _serverSlot) {

// Update previous slot to match server-side slot
_serverSlot = serverSlot
mc.playerController.updateController()

// Not really needed but ok :)
val elapsedTime = System.currentTimeMillis() - startTime

LOGGER.info("Slot Synced (${elapsedTime}ms)")
}

// Reset flags to prevent de-sync
_serverOpenInventory = false
serverOpenContainer = false
}

override fun handleEvents() = true
Expand Down

0 comments on commit e20b98b

Please sign in to comment.