Skip to content

Commit eb8901d

Browse files
committed
item interact based fake fly when the elytra is in hotbar to avoid reaching inventory packet limit
1 parent 3911050 commit eb8901d

3 files changed

Lines changed: 45 additions & 15 deletions

File tree

src/main/kotlin/com/lambda/interaction/managers/inventory/InventoryManager.kt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import com.lambda.context.SafeContext
2222
import com.lambda.event.events.PacketEvent
2323
import com.lambda.event.events.TickEvent
2424
import com.lambda.event.listener.SafeListener.Companion.listen
25-
import com.lambda.interaction.managers.Manager
2625
import com.lambda.interaction.handlers.packet.PacketLimitHandler.canSendPackets
2726
import com.lambda.interaction.handlers.packet.PacketLimitHandler.sentPackets
2827
import com.lambda.interaction.handlers.packet.PacketType
28+
import com.lambda.interaction.managers.Manager
2929
import com.lambda.interaction.managers.inventory.InventoryManager.actions
3030
import com.lambda.interaction.managers.inventory.InventoryManager.activeRequest
3131
import com.lambda.interaction.managers.inventory.InventoryManager.alteredSlots
@@ -163,15 +163,18 @@ object InventoryManager : Manager<InventoryRequest>(
163163
* incoming [InventoryS2CPacket] and [ScreenHandlerSlotUpdateS2CPacket] packets to decide whether to
164164
* block certain updates.
165165
*/
166-
private fun SafeContext.indexInventoryChanges() {
167-
if (player.currentScreenHandler.syncId != screenHandler?.syncId) return
168-
val changes = screenHandler?.slots
169-
?.filter { !it.stack.equal(slots[it.id]) }
170-
?.map { InventoryChange(it.id, slots[it.id], it.stack.copy()) }
171-
?: emptyList()
172-
if (player.currentScreenHandler.syncId == 0) alteredPlayerSlots.addAll(changes)
173-
else alteredSlots.addAll(changes)
174-
slots = getStacks(player.currentScreenHandler.slots)
166+
context(safeContext: SafeContext)
167+
fun indexInventoryChanges() {
168+
with(safeContext) {
169+
if (player.currentScreenHandler.syncId != screenHandler?.syncId) return
170+
val changes = screenHandler?.slots
171+
?.filter { !it.stack.equal(slots[it.id]) }
172+
?.map { InventoryChange(it.id, slots[it.id], it.stack.copy()) }
173+
?: emptyList()
174+
if (player.currentScreenHandler.syncId == 0) alteredPlayerSlots.addAll(changes)
175+
else alteredSlots.addAll(changes)
176+
slots = getStacks(player.currentScreenHandler.slots)
177+
}
175178
}
176179

177180
private fun getStacks(slots: Collection<Slot>) = slots.map { it.stack.copy() }

src/main/kotlin/com/lambda/module/modules/movement/elytrafly/ElytraFly.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.lambda.module.modules.movement.elytrafly
1919

20+
import com.lambda.config.ConfigEditor.editSetting
2021
import com.lambda.config.ConfigEditor.forEachSetting
2122
import com.lambda.config.ConfigEditor.hideAllExcept
2223
import com.lambda.config.Tab
@@ -26,6 +27,7 @@ import com.lambda.config.withEdits
2627
import com.lambda.event.events.ClientEvent
2728
import com.lambda.event.events.MovementEvent
2829
import com.lambda.event.events.PacketEvent
30+
import com.lambda.event.events.TickEvent
2931
import com.lambda.event.listener.SafeListener.Companion.listen
3032
import com.lambda.module.Module
3133
import com.lambda.module.modules.movement.elytrafly.modes.BounceElytraFly
@@ -72,6 +74,7 @@ object ElytraFly : Module(
7274
init {
7375
setDefaultAutomationConfig()
7476
.withEdits {
77+
hotbarConfig::tickStageMask.editSetting { defaultValue(TickEvent.ALL_STAGES.toMutableList()) }
7578
hideAllExcept(::inventoryConfig, ::rotationConfig)
7679
}
7780

src/main/kotlin/com/lambda/module/modules/movement/elytrafly/ElytraFlyMode.kt

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ import com.lambda.config.ConfigBlock
2121
import com.lambda.context.Automated
2222
import com.lambda.context.SafeContext
2323
import com.lambda.event.Muteable
24+
import com.lambda.event.events.PacketEvent
2425
import com.lambda.event.events.TickEvent
2526
import com.lambda.event.listener.SafeListener.Companion.listen
2627
import com.lambda.interaction.handlers.GlideHandler.ELYTRA_SELECTION
28+
import com.lambda.interaction.managers.hotbar.HotbarRequest
29+
import com.lambda.interaction.managers.inventory.InventoryManager
2730
import com.lambda.interaction.managers.inventory.InventoryRequest
2831
import com.lambda.interaction.managers.inventory.InventoryRequest.Companion.inventoryRequest
2932
import com.lambda.module.modules.movement.elytrafly.ElytraFly.FlyMode
@@ -36,7 +39,10 @@ import net.minecraft.entity.Entity
3639
import net.minecraft.entity.EquipmentSlot
3740
import net.minecraft.item.Items
3841
import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket
42+
import net.minecraft.network.packet.s2c.play.InventoryS2CPacket
43+
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket
3944
import net.minecraft.screen.slot.Slot
45+
import net.minecraft.util.Hand
4046

4147
abstract class ElytraFlyMode(
4248
val flyMode: FlyMode
@@ -54,6 +60,11 @@ abstract class ElytraFlyMode(
5460
listen<TickEvent.Pre>({ 100 }) {
5561
fakeGliding = fakeFly && fakeGliding && player.canGlide()
5662
}
63+
64+
listen<PacketEvent.Receive.Pre>({ 100 }) { event ->
65+
if (event.packet !is InventoryS2CPacket && event.packet !is ScreenHandlerSlotUpdateS2CPacket) return@listen
66+
if (fakeGliding) event.cancel()
67+
}
5768
}
5869

5970
protected fun onEnable(callback: SafeContext.() -> Unit) { onEnableListeners.add(callback) }
@@ -82,21 +93,34 @@ abstract class ElytraFlyMode(
8293
}
8394
val elytraInHotbar = elytraSlot.index in 0..8
8495

85-
val chestSlot = player.armorSlots[1]
96+
val chestSlot = player.armorSlots.getOrNull(1) ?: return false
8697

98+
if (elytraInHotbar) {
99+
val hotbarRequest = HotbarRequest(
100+
elytraSlot.index,
101+
ElytraFly,
102+
keepTicks = 0,
103+
nowOrNothing = true
104+
).submit()
105+
if (!hotbarRequest.done) return false
106+
}
87107
fun InventoryRequest.InvRequestBuilder.swapChest() {
88-
if (elytraInHotbar) swap(chestSlot.id, elytraSlot.index)
89-
else {
108+
if (elytraInHotbar) {
109+
interaction.interactItem(player, Hand.MAIN_HAND)
110+
InventoryManager.indexInventoryChanges()
111+
} else {
90112
moveSlot(elytraSlot.id, chestSlot.id)
91113
if (!chestSlot.stack.isEmpty) pickup(elytraSlot.id)
92114
}
93115
}
94116

95-
return inventoryRequest {
117+
val inventoryRequest = inventoryRequest {
96118
swapChest()
97119
action { startFly() }
98120
swapChest()
99-
}.submit(false).done
121+
}.submit(false)
122+
123+
return inventoryRequest.done
100124
}
101125

102126
fun SafeContext.findElytra(): Slot? =

0 commit comments

Comments
 (0)