From 0d79c25006f271f0e4cedf92aafd2b9f19757bf5 Mon Sep 17 00:00:00 2001 From: Edouard127 <46357922+Edouard127@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:19:26 -0500 Subject: [PATCH 1/5] ref: events --- .../ClientPlayInteractionManagerMixin.java | 28 ++----- .../mixin/entity/ClientPlayerEntityMixin.java | 4 +- .../com/lambda/mixin/entity/EntityMixin.java | 4 +- .../com/lambda/mixin/input/KeyboardMixin.java | 18 ++++- .../com/lambda/mixin/input/MouseMixin.java | 65 ++++++++++++++++ .../mixin/world/ClientChunkManagerMixin.java | 6 +- .../com/lambda/event/events/AttackEvent.kt | 28 ------- .../com/lambda/event/events/ClientEvent.kt | 26 +++++-- .../lambda/event/events/ConnectionEvent.kt | 67 ++++++++-------- .../com/lambda/event/events/EntityEvent.kt | 34 -------- .../com/lambda/event/events/KeyPressEvent.kt | 44 ----------- .../com/lambda/event/events/KeyboardEvent.kt | 52 +++++++++++++ ...nteractionEvent.kt => LocalPlayerEvent.kt} | 77 ++++++++++++------- .../com/lambda/event/events/MouseEvent.kt | 58 ++++++++++++++ .../com/lambda/event/events/MovementEvent.kt | 28 +++---- .../lambda/event/events/PlayerPacketEvent.kt | 12 +-- .../com/lambda/event/events/RenderEvent.kt | 12 +-- .../com/lambda/event/events/RotationEvent.kt | 12 +-- .../lambda/event/events/ScreenHandlerEvent.kt | 8 +- .../com/lambda/event/events/TickEvent.kt | 20 ++--- .../com/lambda/event/events/WorldEvent.kt | 50 +++++++----- .../kotlin/com/lambda/gui/api/LambdaGui.kt | 4 +- .../gui/api/component/WindowComponent.kt | 2 + .../gui/impl/clickgui/buttons/ModuleButton.kt | 3 +- .../interaction/material/ContainerManager.kt | 4 +- .../main/kotlin/com/lambda/module/Module.kt | 4 +- .../lambda/module/modules/client/ClickGui.kt | 4 +- .../lambda/module/modules/combat/Criticals.kt | 4 +- .../lambda/module/modules/player/FastBreak.kt | 2 +- .../lambda/module/modules/player/Freecam.kt | 2 +- .../module/modules/player/InventoryTweaks.kt | 4 +- .../module/modules/player/PacketMine.kt | 6 +- .../lambda/module/modules/player/Replay.kt | 4 +- .../lambda/module/modules/render/Particles.kt | 4 +- .../main/kotlin/com/lambda/util/KeyCode.kt | 7 ++ .../src/main/kotlin/com/lambda/util/Mouse.kt | 40 ++++++++-- .../main/resources/lambda.mixins.common.json | 5 +- 37 files changed, 449 insertions(+), 303 deletions(-) create mode 100644 common/src/main/java/com/lambda/mixin/input/MouseMixin.java delete mode 100644 common/src/main/kotlin/com/lambda/event/events/AttackEvent.kt delete mode 100644 common/src/main/kotlin/com/lambda/event/events/EntityEvent.kt delete mode 100644 common/src/main/kotlin/com/lambda/event/events/KeyPressEvent.kt create mode 100644 common/src/main/kotlin/com/lambda/event/events/KeyboardEvent.kt rename common/src/main/kotlin/com/lambda/event/events/{InteractionEvent.kt => LocalPlayerEvent.kt} (50%) create mode 100644 common/src/main/kotlin/com/lambda/event/events/MouseEvent.kt diff --git a/common/src/main/java/com/lambda/mixin/entity/ClientPlayInteractionManagerMixin.java b/common/src/main/java/com/lambda/mixin/entity/ClientPlayInteractionManagerMixin.java index 85ce86173..775428d34 100644 --- a/common/src/main/java/com/lambda/mixin/entity/ClientPlayInteractionManagerMixin.java +++ b/common/src/main/java/com/lambda/mixin/entity/ClientPlayInteractionManagerMixin.java @@ -18,8 +18,7 @@ package com.lambda.mixin.entity; import com.lambda.event.EventFlow; -import com.lambda.event.events.AttackEvent; -import com.lambda.event.events.InteractionEvent; +import com.lambda.event.events.LocalPlayerEvent; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.ClientPlayerInteractionManager; @@ -51,46 +50,31 @@ public class ClientPlayInteractionManagerMixin { @Inject(method = "interactBlock", at = @At("HEAD")) public void interactBlockHead(final ClientPlayerEntity player, final Hand hand, final BlockHitResult hitResult, final CallbackInfoReturnable cir) { if (client.world == null) return; - EventFlow.post(new InteractionEvent.Block(client.world, hitResult)); + EventFlow.post(new LocalPlayerEvent.BlockInteract(client.world, hitResult)); } @Inject(method = "clickSlot", at = @At("HEAD"), cancellable = true) public void clickSlotHead(int syncId, int slotId, int button, SlotActionType actionType, PlayerEntity player, CallbackInfo ci) { if (syncId != player.currentScreenHandler.syncId) return; - var click = new InteractionEvent.SlotClick(syncId, slotId, button, actionType, player.currentScreenHandler); + var click = new LocalPlayerEvent.SlotClick(syncId, slotId, button, actionType, player.currentScreenHandler); if (EventFlow.post(click).isCanceled()) ci.cancel(); } @Inject(method = "attackEntity", at = @At("HEAD"), cancellable = true) void onAttackPre(PlayerEntity player, Entity target, CallbackInfo ci) { - if (EventFlow.post(new AttackEvent.Pre(target)).isCanceled()) ci.cancel(); - } - - @Inject(method = "attackEntity", at = @At("TAIL")) - void onAttackPost(PlayerEntity player, Entity target, CallbackInfo ci) { - EventFlow.post(new AttackEvent.Post(target)); + if (EventFlow.post(new LocalPlayerEvent.EntityAttack(target)).isCanceled()) ci.cancel(); } @Inject(method = "attackBlock", at = @At("HEAD"), cancellable = true) public void onAttackBlock(BlockPos pos, Direction side, CallbackInfoReturnable cir) { - if (EventFlow.post(new InteractionEvent.BlockAttack.Pre(pos, side)).isCanceled()) cir.cancel(); - } - - @Inject(method = "attackBlock", at = @At("TAIL")) - public void onAttackBlockPost(BlockPos pos, Direction side, CallbackInfoReturnable cir) { - EventFlow.post(new InteractionEvent.BlockAttack.Post(pos, side)); + if (EventFlow.post(new LocalPlayerEvent.BlockAttack(pos, side)).isCanceled()) cir.cancel(); } @Inject(method = "updateBlockBreakingProgress", at = @At("HEAD"), cancellable = true) private void updateBlockBreakingProgressPre(BlockPos pos, Direction side, CallbackInfoReturnable cir) { - var event = EventFlow.post(new InteractionEvent.BreakingProgress.Pre(pos, side, currentBreakingProgress)); + var event = EventFlow.post(new LocalPlayerEvent.BreakingProgress(pos, side, currentBreakingProgress)); if (event.isCanceled()) cir.cancel(); currentBreakingProgress = event.getProgress(); } - - @Inject(method = "updateBlockBreakingProgress", at = @At("TAIL")) - private void updateBlockBreakingProgressPost(BlockPos pos, Direction side, CallbackInfoReturnable cir) { - EventFlow.post(new InteractionEvent.BreakingProgress.Post(pos, side, currentBreakingProgress)); - } } diff --git a/common/src/main/java/com/lambda/mixin/entity/ClientPlayerEntityMixin.java b/common/src/main/java/com/lambda/mixin/entity/ClientPlayerEntityMixin.java index ed64cc93c..b73f07f49 100644 --- a/common/src/main/java/com/lambda/mixin/entity/ClientPlayerEntityMixin.java +++ b/common/src/main/java/com/lambda/mixin/entity/ClientPlayerEntityMixin.java @@ -19,7 +19,7 @@ import com.lambda.Lambda; import com.lambda.event.EventFlow; -import com.lambda.event.events.EntityEvent; +import com.lambda.event.events.LocalPlayerEvent; import com.lambda.event.events.MovementEvent; import com.lambda.event.events.TickEvent; import com.lambda.interaction.PlayerPacketManager; @@ -125,6 +125,6 @@ float fixHeldItemPitch(ClientPlayerEntity instance) { @Inject(method = "swingHand", at = @At("HEAD"), cancellable = true) void onSwingHandPre(Hand hand, CallbackInfo ci) { - if (EventFlow.post(new EntityEvent.SwingHand(hand)).isCanceled()) ci.cancel(); + if (EventFlow.post(new LocalPlayerEvent.SwingHand(hand)).isCanceled()) ci.cancel(); } } diff --git a/common/src/main/java/com/lambda/mixin/entity/EntityMixin.java b/common/src/main/java/com/lambda/mixin/entity/EntityMixin.java index 51f8e0330..6d4fc5776 100644 --- a/common/src/main/java/com/lambda/mixin/entity/EntityMixin.java +++ b/common/src/main/java/com/lambda/mixin/entity/EntityMixin.java @@ -19,7 +19,7 @@ import com.lambda.Lambda; import com.lambda.event.EventFlow; -import com.lambda.event.events.EntityEvent; +import com.lambda.event.events.LocalPlayerEvent; import com.lambda.event.events.WorldEvent; import com.lambda.interaction.RotationManager; import com.lambda.util.math.Vec2d; @@ -87,7 +87,7 @@ float fixDirectionPitch2(Entity entity) { @Inject(method = "changeLookDirection", at = @At("HEAD"), cancellable = true) private void changeLookDirection(double cursorDeltaX, double cursorDeltaY, CallbackInfo ci) { - if (EventFlow.post(new EntityEvent.ChangeLookDirection(cursorDeltaX, cursorDeltaY)).isCanceled()) ci.cancel(); + if (EventFlow.post(new LocalPlayerEvent.ChangeLookDirection(cursorDeltaX, cursorDeltaY)).isCanceled()) ci.cancel(); } @Inject(method = "onTrackedDataSet(Lnet/minecraft/entity/data/TrackedData;)V", at = @At("TAIL")) diff --git a/common/src/main/java/com/lambda/mixin/input/KeyboardMixin.java b/common/src/main/java/com/lambda/mixin/input/KeyboardMixin.java index 1e9cd8bb9..a21d745ee 100644 --- a/common/src/main/java/com/lambda/mixin/input/KeyboardMixin.java +++ b/common/src/main/java/com/lambda/mixin/input/KeyboardMixin.java @@ -18,7 +18,7 @@ package com.lambda.mixin.input; import com.lambda.event.EventFlow; -import com.lambda.event.events.KeyPressEvent; +import com.lambda.event.events.KeyboardEvent; import net.minecraft.client.Keyboard; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -28,9 +28,19 @@ @Mixin(Keyboard.class) public class KeyboardMixin { @Inject(method = "onKey", at = @At("HEAD")) - void onKey(long window, int key, int scancode, int action, int modifiers, CallbackInfo ci) { + private void onKey(long window, int key, int scancode, int action, int modifiers, CallbackInfo ci) { if (key <= 0) return; - if (action != 1) return; - EventFlow.post(new KeyPressEvent(key, scancode, action, modifiers)); + if (action != 1) return; // TODO: Post events on both press and release ? + + EventFlow.post(new KeyboardEvent.Press(key, scancode, action, modifiers)); + } + + @Inject(method = "onChar", at = @At("HEAD")) + private void onChar(long window, int codePoint, int modifiers, CallbackInfo ci) { + char[] chars = Character.toChars(codePoint); + + for (char c : chars) { + EventFlow.post(new KeyboardEvent.Char(c)); + } } } diff --git a/common/src/main/java/com/lambda/mixin/input/MouseMixin.java b/common/src/main/java/com/lambda/mixin/input/MouseMixin.java new file mode 100644 index 000000000..41c65501a --- /dev/null +++ b/common/src/main/java/com/lambda/mixin/input/MouseMixin.java @@ -0,0 +1,65 @@ +/* + * Copyright 2024 Lambda + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.lambda.mixin.input; + +import com.lambda.event.EventFlow; +import com.lambda.event.events.MouseEvent; +import net.minecraft.client.Mouse; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Mouse.class) +public class MouseMixin { + @Shadow private double x; + + @Shadow private double y; + + @Inject(method = "onMouseButton(JIII)V", at = @At("HEAD"), cancellable = true) + private void onMouseButton(long window, int button, int action, int mods, CallbackInfo ci) { + com.lambda.util.Mouse.Button btn = com.lambda.util.Mouse.Button.Companion.fromMouseCode(button); + com.lambda.util.Mouse.Action act = com.lambda.util.Mouse.Action.Companion.fromActionCode(action); + com.lambda.util.math.Vec2d position = new com.lambda.util.math.Vec2d(x, y); + + if (EventFlow.post(new MouseEvent.Click(btn, act, mods, position)).isCanceled()) { + ci.cancel(); + } + } + + @Inject(method = "onMouseScroll(JDD)V", at = @At("HEAD"), cancellable = true) + private void onMouseScroll(long window, double horizontal, double vertical, CallbackInfo ci) { + com.lambda.util.math.Vec2d delta = new com.lambda.util.math.Vec2d(horizontal, vertical); + + if (EventFlow.post(new MouseEvent.Scroll(delta)).isCanceled()) { + ci.cancel(); + } + } + + @Inject(method = "onCursorPos(JDD)V", at = @At("HEAD"), cancellable = true) + private void onCursorPos(long window, double x, double y, CallbackInfo ci) { + if (x + y == this.x + this.y) return; + + com.lambda.util.math.Vec2d position = new com.lambda.util.math.Vec2d(x, y); + + if (EventFlow.post(new MouseEvent.Move(position)).isCanceled()) { + ci.cancel(); + } + } +} diff --git a/common/src/main/java/com/lambda/mixin/world/ClientChunkManagerMixin.java b/common/src/main/java/com/lambda/mixin/world/ClientChunkManagerMixin.java index aabf839bf..fcce869d0 100644 --- a/common/src/main/java/com/lambda/mixin/world/ClientChunkManagerMixin.java +++ b/common/src/main/java/com/lambda/mixin/world/ClientChunkManagerMixin.java @@ -52,7 +52,7 @@ private void onChunkLoad( Consumer consumer, CallbackInfoReturnable info ) { - EventFlow.post(new WorldEvent.ChunkEvent.Load(this.world, info.getReturnValue())); + EventFlow.post(new WorldEvent.ChunkEvent.Load(info.getReturnValue())); } @Inject(method = "loadChunkFromPacket", at = @At(value = "NEW", target = "net/minecraft/world/chunk/WorldChunk", shift = At.Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILHARD) @@ -68,13 +68,13 @@ private void onChunkUnload( ChunkPos chunkPos ) { if (chunk != null) { - EventFlow.post(new WorldEvent.ChunkEvent.Unload(this.world, chunk)); + EventFlow.post(new WorldEvent.ChunkEvent.Unload(chunk)); } } @Inject(method = "unload", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/world/ClientChunkManager$ClientChunkMap;compareAndSet(ILnet/minecraft/world/chunk/WorldChunk;Lnet/minecraft/world/chunk/WorldChunk;)Lnet/minecraft/world/chunk/WorldChunk;"), locals = LocalCapture.CAPTURE_FAILHARD) private void onChunkUnload(ChunkPos pos, CallbackInfo ci, int i, WorldChunk chunk) { - EventFlow.post(new WorldEvent.ChunkEvent.Unload(this.world, chunk)); + EventFlow.post(new WorldEvent.ChunkEvent.Unload(chunk)); } // @Inject( diff --git a/common/src/main/kotlin/com/lambda/event/events/AttackEvent.kt b/common/src/main/kotlin/com/lambda/event/events/AttackEvent.kt deleted file mode 100644 index 2d6e23a7b..000000000 --- a/common/src/main/kotlin/com/lambda/event/events/AttackEvent.kt +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2024 Lambda - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lambda.event.events - -import com.lambda.event.Event -import com.lambda.event.callback.Cancellable -import com.lambda.event.callback.ICancellable -import net.minecraft.entity.Entity - -abstract class AttackEvent(val entity: Entity) : Event { - class Pre(entity: Entity) : AttackEvent(entity), ICancellable by Cancellable() - class Post(entity: Entity) : AttackEvent(entity) -} diff --git a/common/src/main/kotlin/com/lambda/event/events/ClientEvent.kt b/common/src/main/kotlin/com/lambda/event/events/ClientEvent.kt index df1ac28fc..1468ff092 100644 --- a/common/src/main/kotlin/com/lambda/event/events/ClientEvent.kt +++ b/common/src/main/kotlin/com/lambda/event/events/ClientEvent.kt @@ -22,10 +22,26 @@ import com.lambda.event.callback.Cancellable import com.lambda.event.callback.ICancellable import net.minecraft.client.sound.SoundInstance +sealed class ClientEvent { + /** + * Triggered upon client initialization + */ + class Startup : Event -abstract class ClientEvent : Event { - class Shutdown : ClientEvent() - class Startup : ClientEvent() - class Timer(var speed: Double) : ClientEvent() - class Sound(val sound: SoundInstance) : ClientEvent(), ICancellable by Cancellable() + /** + * Triggered upon client shutdown + */ + class Shutdown : Event + + /** + * Triggered upon game logic tick + * + * @property speed The speed of the timer. + */ + data class Timer(var speed: Double) : Event + + /** + * Triggered before playing a sound + */ + data class Sound(val sound: SoundInstance) : ICancellable by Cancellable() } diff --git a/common/src/main/kotlin/com/lambda/event/events/ConnectionEvent.kt b/common/src/main/kotlin/com/lambda/event/events/ConnectionEvent.kt index 748a281c5..c27fc242a 100644 --- a/common/src/main/kotlin/com/lambda/event/events/ConnectionEvent.kt +++ b/common/src/main/kotlin/com/lambda/event/events/ConnectionEvent.kt @@ -27,54 +27,52 @@ import net.minecraft.text.Text import java.security.PublicKey import javax.crypto.SecretKey -/** - * Sealed class representing connection events. - */ -sealed class ConnectionEvent : Event { - /** - * Sealed class representing various stages of connection establishment. - */ +sealed class ConnectionEvent { sealed class Connect { /** - * Event representing a pre-connection attempt. - * @property address The address of the connection attempt. - * @property port The port of the connection attempt. - * @property listener The packet listener associated with the connection. - * @property intent The connection intent. + * Event representing a pre-connection attempt + * + * @property address The address of the connection attempt + * @property port The port of the connection attempt + * @property listener The packet listener associated with the connection + * @property intent The connection intent */ - class Pre( + data class Pre( val address: String, val port: Int, val listener: PacketListener, val intent: ConnectionIntent, - ) : ConnectionEvent(), ICancellable by Cancellable() + ) : ICancellable by Cancellable() /** - * Event representing a handshake during connection. - * @property protocolVersion The protocol version of the connection. - * @property address The address of the connection attempt. - * @property port The port of the connection attempt. - * @property intent The connection intent. + * Event representing a handshake during connection + * + * @property protocolVersion The protocol version of the connection + * @property address The address of the connection attempt + * @property port The port of the connection attempt + * @property intent The connection intent + * + * @see Server_List_Ping#Handshake */ - class Handshake( + data class Handshake( val protocolVersion: Int, val address: String, val port: Int, val intent: ConnectionIntent, - ) : ConnectionEvent() + ) : Event - /** - * Sealed class representing login-related connection events. - */ - sealed class Login : ConnectionEvent() { + sealed class Login { /** - * @see Encryption Request + * This event is not received by the client, it is sent from the client + * to the server, this event simply intercepts the outbound packet + * + * @see Protocol#Encryption_Request */ class EncryptionRequest( val serverId: String, val publicKey: PublicKey, val nonce: ByteArray, - ) : ConnectionEvent() + ) : Event /** * Event representing the exchange of cryptographic keys during login @@ -87,26 +85,25 @@ sealed class ConnectionEvent : Event { * This can be done by calling the `destroy()` method on the secret key object * We are not responsible for any incidents that may occur due to improper handling of cryptographic keys * - * @see Encryption Response + * @see Protocol#Encryption_Response */ class EncryptionResponse( val secretKey: SecretKey, val publicKey: PublicKey, val nonce: ByteArray, - ) : ConnectionEvent() + ) : Event } /** - * Event representing post-connection actions. - * @property profile The game profile associated with the connection. + * Triggered upon successful connection process end */ - class Post( + data class Post( val profile: GameProfile, - ) : ConnectionEvent() + ) : Event } /** - * @property reason The reason for disconnection. + * Triggered upon connection failure */ - class Disconnect(val reason: Text) : ConnectionEvent() + data class Disconnect(val reason: Text) : Event } diff --git a/common/src/main/kotlin/com/lambda/event/events/EntityEvent.kt b/common/src/main/kotlin/com/lambda/event/events/EntityEvent.kt deleted file mode 100644 index ea529cd61..000000000 --- a/common/src/main/kotlin/com/lambda/event/events/EntityEvent.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2024 Lambda - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lambda.event.events - -import com.lambda.event.Event -import com.lambda.event.callback.Cancellable -import com.lambda.event.callback.ICancellable -import net.minecraft.util.Hand - -abstract class EntityEvent : Event { - class ChangeLookDirection( - val deltaYaw: Double, - val deltaPitch: Double, - ) : EntityEvent(), ICancellable by Cancellable() - - class SwingHand( - val hand: Hand - ) : EntityEvent(), ICancellable by Cancellable() -} diff --git a/common/src/main/kotlin/com/lambda/event/events/KeyPressEvent.kt b/common/src/main/kotlin/com/lambda/event/events/KeyPressEvent.kt deleted file mode 100644 index 70c7a24b9..000000000 --- a/common/src/main/kotlin/com/lambda/event/events/KeyPressEvent.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2024 Lambda - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lambda.event.events - -import com.lambda.event.EventFlow -import com.lambda.event.callback.Cancellable -import com.lambda.event.callback.ICancellable -import com.lambda.util.KeyCode - -/** - * A class representing a [KeyPressEvent] in the event system ([EventFlow]). - * - * A [KeyPressEvent] is a type of event that is triggered when a key is pressed. - * It implements [ICancellable] interface, which means the event can be cancelled. - * - * @property keyCode The key code of the key that was pressed. - * @property scanCode The scan code of the key that was pressed. - * @property action The action that was performed on the key. - * @property modifiers The modifiers that were active when the key was pressed. - */ -data class KeyPressEvent( - val keyCode: Int, - val scanCode: Int, - val action: Int, - val modifiers: Int, -) : ICancellable by Cancellable() { - val translated: KeyCode - get() = KeyCode.virtualMapUS(keyCode, scanCode) -} diff --git a/common/src/main/kotlin/com/lambda/event/events/KeyboardEvent.kt b/common/src/main/kotlin/com/lambda/event/events/KeyboardEvent.kt new file mode 100644 index 000000000..da53ab03b --- /dev/null +++ b/common/src/main/kotlin/com/lambda/event/events/KeyboardEvent.kt @@ -0,0 +1,52 @@ +/* + * Copyright 2024 Lambda + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.lambda.event.events + +import com.lambda.event.Event +import com.lambda.util.KeyCode + +sealed class KeyboardEvent { + /** + * Represents a key press + * + * @property keyCode The key code of the key that was pressed + * @property scanCode The scan code of the key that was pressed + * @property action The action that was performed on the key (Pressed, Released) + * @property modifiers The modifiers that were active when the key was pressed + * + * @see About Keyboards + */ + data class Press( + val keyCode: Int, + val scanCode: Int, + val action: Int, + val modifiers: Int, + ) : Event { + val translated: KeyCode + get() = KeyCode.virtualMapUS(keyCode, scanCode) + } + + /** + * Represents glfwSetKeyCallback events + * + * Keys and characters do not map 1:1. + * A single key press may produce several characters, and a single + * character may require several keys to produce + */ + data class Char(val char: kotlin.Char) : Event +} diff --git a/common/src/main/kotlin/com/lambda/event/events/InteractionEvent.kt b/common/src/main/kotlin/com/lambda/event/events/LocalPlayerEvent.kt similarity index 50% rename from common/src/main/kotlin/com/lambda/event/events/InteractionEvent.kt rename to common/src/main/kotlin/com/lambda/event/events/LocalPlayerEvent.kt index b6b4c1bad..130486589 100644 --- a/common/src/main/kotlin/com/lambda/event/events/InteractionEvent.kt +++ b/common/src/main/kotlin/com/lambda/event/events/LocalPlayerEvent.kt @@ -21,49 +21,70 @@ import com.lambda.event.Event import com.lambda.event.callback.Cancellable import com.lambda.event.callback.ICancellable import net.minecraft.client.world.ClientWorld +import net.minecraft.entity.Entity import net.minecraft.screen.ScreenHandler import net.minecraft.screen.slot.SlotActionType +import net.minecraft.util.Hand import net.minecraft.util.hit.BlockHitResult import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Direction -sealed class InteractionEvent : Event { - class Block( - val world: ClientWorld, - val blockHitResult: BlockHitResult - ) : InteractionEvent() +sealed class LocalPlayerEvent { + /** + * Represents the local player moving the cursor around + */ + data class ChangeLookDirection( + val deltaYaw: Double, + val deltaPitch: Double, + ) : ICancellable by Cancellable() + + /** + * Represents the local player swinging its hand + */ + data class SwingHand( + val hand: Hand + ) : ICancellable by Cancellable() - sealed class BlockAttack : InteractionEvent() { - class Pre( - val pos: BlockPos, - val side: Direction - ) : BlockAttack(), ICancellable by Cancellable() + /** + * Represents the local player attacking an entity + */ + data class EntityAttack( + val entity: Entity + ) : ICancellable by Cancellable() - class Post( - val pos: BlockPos, - val side: Direction - ) : BlockAttack() - } + /** + * Represents the local player interacting (right-click) with blocks + */ + data class BlockInteract( + val world: ClientWorld, + val blockHitResult: BlockHitResult + ) : Event - sealed class BreakingProgress : InteractionEvent() { - class Pre( - val pos: BlockPos, - val side: Direction, - var progress: Float, - ) : BreakingProgress(), ICancellable by Cancellable() + /** + * Represents the local player attacking a block + */ + data class BlockAttack( + val pos: BlockPos, + val side: Direction + ) : ICancellable by Cancellable() - class Post( - val pos: BlockPos, - val side: Direction, - val progress: Float, - ) : BreakingProgress() - } + /** + * Represents events triggered during a block breaking action + */ + data class BreakingProgress( + val pos: BlockPos, + val side: Direction, + var progress: Float, + ) : ICancellable by Cancellable() + /** + * Represents the local player clicking on a slot in a screen + */ data class SlotClick( val syncId: Int, val slot: Int, val button: Int, val action: SlotActionType, val screenHandler: ScreenHandler, - ) : ScreenHandlerEvent(), ICancellable by Cancellable() + ) : ICancellable by Cancellable() } diff --git a/common/src/main/kotlin/com/lambda/event/events/MouseEvent.kt b/common/src/main/kotlin/com/lambda/event/events/MouseEvent.kt new file mode 100644 index 000000000..cb4d2029a --- /dev/null +++ b/common/src/main/kotlin/com/lambda/event/events/MouseEvent.kt @@ -0,0 +1,58 @@ +/* + * Copyright 2024 Lambda + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.lambda.event.events + +import com.lambda.event.callback.Cancellable +import com.lambda.event.callback.ICancellable +import com.lambda.util.Mouse +import com.lambda.util.math.Vec2d + +sealed class MouseEvent { + /** + * Represents a mouse click event + * + * @property button The button that was clicked + * @property action The action performed (e.g., press or release) + * @property modifiers An integer representing any modifiers (e.g., shift or ctrl) active during the event + * @property position The x and y position of the mouse on the screen + */ + data class Click( + val button: Mouse.Button, + val action: Mouse.Action, + val modifiers: Int, + val position: Vec2d + ) : ICancellable by Cancellable() + + /** + * Represents a mouse scroll event + * + * @property delta The amount of scrolling in the x and y directions + */ + data class Scroll( + val delta: Vec2d + ) : ICancellable by Cancellable() + + /** + * Represents a mouse move event. + * + * @property position The x and y position of the mouse on the screen. + */ + data class Move( + val position: Vec2d + ) : ICancellable by Cancellable() +} diff --git a/common/src/main/kotlin/com/lambda/event/events/MovementEvent.kt b/common/src/main/kotlin/com/lambda/event/events/MovementEvent.kt index 75d825135..c4aaaf57e 100644 --- a/common/src/main/kotlin/com/lambda/event/events/MovementEvent.kt +++ b/common/src/main/kotlin/com/lambda/event/events/MovementEvent.kt @@ -22,28 +22,28 @@ import com.lambda.event.callback.Cancellable import com.lambda.event.callback.ICancellable import net.minecraft.client.input.Input -abstract class MovementEvent : Event { - class Pre : MovementEvent() - class Post : MovementEvent() +sealed class MovementEvent { + class Pre : Event + class Post : Event - abstract class Travel : MovementEvent() { - class Pre : MovementEvent(), ICancellable by Cancellable() - class Post : MovementEvent() + sealed class Travel { + class Pre : ICancellable by Cancellable() + class Post : Event } - class InputUpdate( + data class InputUpdate( val input: Input, var slowDown: Boolean, var slowDownFactor: Float, - ) : MovementEvent() + ) : Event - class Sprint(var sprint: Boolean) : MovementEvent() - class Sneak(var sneak: Boolean) : MovementEvent() + data class Sprint(var sprint: Boolean) : Event + data class Sneak(var sneak: Boolean) : Event - class ClipAtLedge( + data class ClipAtLedge( var clip: Boolean, - ) : MovementEvent() + ) : Event - class Jump(var height: Double) : MovementEvent(), ICancellable by Cancellable() - class SlowDown : Event, ICancellable by Cancellable() + data class Jump(var height: Double) : ICancellable by Cancellable() + class SlowDown : ICancellable by Cancellable() } diff --git a/common/src/main/kotlin/com/lambda/event/events/PlayerPacketEvent.kt b/common/src/main/kotlin/com/lambda/event/events/PlayerPacketEvent.kt index b895f4947..6bccf9eea 100644 --- a/common/src/main/kotlin/com/lambda/event/events/PlayerPacketEvent.kt +++ b/common/src/main/kotlin/com/lambda/event/events/PlayerPacketEvent.kt @@ -24,18 +24,18 @@ import com.lambda.interaction.rotation.Rotation import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket import net.minecraft.util.math.Vec3d -abstract class PlayerPacketEvent : Event { - class Pre( +sealed class PlayerPacketEvent { + data class Pre( var position: Vec3d, var rotation: Rotation, var onGround: Boolean, var isSprinting: Boolean, var isSneaking: Boolean, - ) : PlayerPacketEvent(), ICancellable by Cancellable() + ) : ICancellable by Cancellable() - class Post : PlayerPacketEvent() + class Post : Event - class Send( + data class Send( val packet: PlayerMoveC2SPacket, - ) : PlayerPacketEvent(), ICancellable by Cancellable() + ) : ICancellable by Cancellable() } diff --git a/common/src/main/kotlin/com/lambda/event/events/RenderEvent.kt b/common/src/main/kotlin/com/lambda/event/events/RenderEvent.kt index 81f79af1f..6c895d02d 100644 --- a/common/src/main/kotlin/com/lambda/event/events/RenderEvent.kt +++ b/common/src/main/kotlin/com/lambda/event/events/RenderEvent.kt @@ -25,18 +25,18 @@ import com.lambda.graphics.renderer.esp.global.DynamicESP import com.lambda.graphics.renderer.esp.global.StaticESP import com.lambda.util.math.Vec2d -abstract class RenderEvent : Event { - class World : RenderEvent() +sealed class RenderEvent { + class World : Event - class StaticESP : RenderEvent() { + class StaticESP : Event { val renderer = StaticESP } - class DynamicESP : RenderEvent() { + class DynamicESP : Event { val renderer = DynamicESP } - abstract class GUI(val scale: Double) : RenderEvent() { + sealed class GUI(val scale: Double) : Event { class Scaled(scaleFactor: Double) : GUI(scaleFactor) class HUD(scaleFactor: Double) : GUI(scaleFactor) class Fixed : GUI(1.0) @@ -44,5 +44,5 @@ abstract class RenderEvent : Event { val screenSize = Vec2d(mc.window.framebufferWidth, mc.window.framebufferHeight) / scale } - class UpdateTarget : RenderEvent(), ICancellable by Cancellable() + class UpdateTarget : ICancellable by Cancellable() } diff --git a/common/src/main/kotlin/com/lambda/event/events/RotationEvent.kt b/common/src/main/kotlin/com/lambda/event/events/RotationEvent.kt index fa06a0830..3f9ccce1c 100644 --- a/common/src/main/kotlin/com/lambda/event/events/RotationEvent.kt +++ b/common/src/main/kotlin/com/lambda/event/events/RotationEvent.kt @@ -23,17 +23,17 @@ import com.lambda.event.callback.ICancellable import com.lambda.interaction.rotation.RotationContext import net.minecraft.client.input.Input -abstract class RotationEvent : Event { +sealed class RotationEvent { /** * This event allows listeners to register a rotation request to be executed that tick. * * Only one rotation can "win" each tick * - * CAUTION: The listener with the LOWEST priority will win as it is the last to override the context. + * CAUTION: The listener with the LOWEST priority will win as it is the last to override the context * - * @property context The rotation context that listeners can set. Only one rotation can "win" each tick. + * @property context The rotation context that listeners can set. Only one rotation can "win" each tick */ - class Update(var context: RotationContext?) : RotationEvent(), ICancellable by Cancellable() + class Update(var context: RotationContext?) : ICancellable by Cancellable() /** * This event allows listeners to modify the yaw relative to which the movement input is going to be constructed @@ -41,7 +41,7 @@ abstract class RotationEvent : Event { * @property strafeYaw The angle at which the player will move when pressing W * Changing this value will never force the anti cheat to flag you because RotationManager is designed to modify the key input instead */ - class StrafeInput(var strafeYaw: Double, val input: Input) : RotationEvent() + class StrafeInput(var strafeYaw: Double, val input: Input) : Event - class Post(val context: RotationContext) : RotationEvent() + class Post(val context: RotationContext) : Event } diff --git a/common/src/main/kotlin/com/lambda/event/events/ScreenHandlerEvent.kt b/common/src/main/kotlin/com/lambda/event/events/ScreenHandlerEvent.kt index 0a4da360c..df017b316 100644 --- a/common/src/main/kotlin/com/lambda/event/events/ScreenHandlerEvent.kt +++ b/common/src/main/kotlin/com/lambda/event/events/ScreenHandlerEvent.kt @@ -21,13 +21,13 @@ import com.lambda.event.Event import net.minecraft.item.ItemStack import net.minecraft.screen.ScreenHandler -sealed class ScreenHandlerEvent : Event { - class Open(val screenHandler: ScreenHandler) : ScreenHandlerEvent() - class Close(val screenHandler: ScreenHandler) : ScreenHandlerEvent() +sealed class ScreenHandlerEvent { + class Open(val screenHandler: ScreenHandler) : Event + class Close(val screenHandler: ScreenHandler) : Event data class Update( val revision: Int, val stacks: List, val cursorStack: ItemStack, - ) : ScreenHandlerEvent() + ) : Event } diff --git a/common/src/main/kotlin/com/lambda/event/events/TickEvent.kt b/common/src/main/kotlin/com/lambda/event/events/TickEvent.kt index 323f0db6b..26fcad5d9 100644 --- a/common/src/main/kotlin/com/lambda/event/events/TickEvent.kt +++ b/common/src/main/kotlin/com/lambda/event/events/TickEvent.kt @@ -19,7 +19,7 @@ package com.lambda.event.events import com.lambda.event.Event -abstract class TickEvent : Event { +sealed class TickEvent { /** * Triggered before each iteration of the game loop. * @@ -40,7 +40,7 @@ abstract class TickEvent : Event { * * @see net.minecraft.client.MinecraftClient.tick */ - class Pre : TickEvent() + class Pre : Event /** * Triggered after each iteration of the game loop. @@ -57,13 +57,13 @@ abstract class TickEvent : Event { * 7. **Input Handling**: Handles input events, decrements attack cooldown. * 8. **World Update**: Ticks game and world renderers, world entities (such as [TickEvent.Player]). * 9. **Music and Sound Update**: Ticks music tracker and sound manager. - * 10. **Tutorial and Social Interactions**: Handles tutorial and social interactions, ticks world. + * 10. **Tutorial**: Handles tutorials, ticks world. * 11. **Pending Connection**: Ticks integrated server connection. * 12. **Keyboard Handling**: Polls for debug crash key presses. * * @see net.minecraft.client.MinecraftClient.tick */ - class Post : TickEvent() + class Post : Event /** * Triggered before ([Pre]) and after ([Post]) each render tick. @@ -78,16 +78,16 @@ abstract class TickEvent : Event { * * @see net.minecraft.client.MinecraftClient.render */ - abstract class Render : TickEvent() { + sealed class Render { /** * Triggered before each render tick ([TickEvent.Render]) of the game loop. */ - class Pre : TickEvent() + class Pre : Event /** * Triggered after each render tick ([TickEvent.Render]) of the game loop. */ - class Post : TickEvent() + class Post : Event } /** @@ -102,15 +102,15 @@ abstract class TickEvent : Event { * * @see net.minecraft.client.network.ClientPlayerEntity.tick */ - abstract class Player : TickEvent() { + sealed class Player { /** * Triggered before each player tick ([TickEvent.Player]). */ - class Pre : Player() + class Pre : Event /** * Triggered after each player tick ([TickEvent.Player]). */ - class Post : Player() + class Post : Event } } diff --git a/common/src/main/kotlin/com/lambda/event/events/WorldEvent.kt b/common/src/main/kotlin/com/lambda/event/events/WorldEvent.kt index f628f1e34..e9b275a4f 100644 --- a/common/src/main/kotlin/com/lambda/event/events/WorldEvent.kt +++ b/common/src/main/kotlin/com/lambda/event/events/WorldEvent.kt @@ -28,36 +28,50 @@ import net.minecraft.util.math.BlockPos import net.minecraft.util.shape.VoxelShape import net.minecraft.world.chunk.WorldChunk -abstract class WorldEvent : Event { - abstract class ChunkEvent : WorldEvent() { - abstract val world: ClientWorld - abstract val chunk: WorldChunk - - class Load( - override val world: ClientWorld, - override val chunk: WorldChunk - ) : ChunkEvent() - - class Unload( - override val world: ClientWorld, - override val chunk: WorldChunk - ) : ChunkEvent() +sealed class WorldEvent { + sealed class ChunkEvent : Event { + /** + * Event triggering upon chunk loading + */ + data class Load( + val chunk: WorldChunk + ) : Event + + /** + * Event triggering upon chunk unloading + * Does not trigger when leaving the world + */ + data class Unload( + val chunk: WorldChunk + ) : Event } + /** + * Represents a block update in the world + */ class BlockUpdate( val pos: BlockPos, val state: BlockState, val flags: Int - ) : WorldEvent(), ICancellable by Cancellable() + ) : ICancellable by Cancellable() + /** + * Represents an entity being added to the world + */ class EntitySpawn( val entity: Entity - ) : WorldEvent(), ICancellable by Cancellable() + ) : ICancellable by Cancellable() + /** + * Triggered upon entity data modification + */ class EntityUpdate( val entity: Entity, val data: TrackedData<*>, - ) : WorldEvent(), ICancellable by Cancellable() + ) : ICancellable by Cancellable() - class Collision(val pos: BlockPos, val state: BlockState, var shape: VoxelShape) : WorldEvent() + /** + * Triggered upon player colliding with a block + */ + data class Collision(val pos: BlockPos, val state: BlockState, var shape: VoxelShape) : Event } diff --git a/common/src/main/kotlin/com/lambda/gui/api/LambdaGui.kt b/common/src/main/kotlin/com/lambda/gui/api/LambdaGui.kt index bd1f550ff..e3119d1d5 100644 --- a/common/src/main/kotlin/com/lambda/gui/api/LambdaGui.kt +++ b/common/src/main/kotlin/com/lambda/gui/api/LambdaGui.kt @@ -135,12 +135,12 @@ abstract class LambdaGui( } final override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean { - onEvent(GuiEvent.MouseClick(Mouse.Button(button), Mouse.Action.Click, rescaleMouse(mouseX, mouseY))) + onEvent(GuiEvent.MouseClick(Mouse.Button.fromMouseCode(button), Mouse.Action.Click, rescaleMouse(mouseX, mouseY))) return true } final override fun mouseReleased(mouseX: Double, mouseY: Double, button: Int): Boolean { - onEvent(GuiEvent.MouseClick(Mouse.Button(button), Mouse.Action.Release, rescaleMouse(mouseX, mouseY))) + onEvent(GuiEvent.MouseClick(Mouse.Button.fromMouseCode(button), Mouse.Action.Release, rescaleMouse(mouseX, mouseY))) return true } diff --git a/common/src/main/kotlin/com/lambda/gui/api/component/WindowComponent.kt b/common/src/main/kotlin/com/lambda/gui/api/component/WindowComponent.kt index 6a4762ca6..50592ee32 100644 --- a/common/src/main/kotlin/com/lambda/gui/api/component/WindowComponent.kt +++ b/common/src/main/kotlin/com/lambda/gui/api/component/WindowComponent.kt @@ -166,6 +166,8 @@ abstract class WindowComponent( if (isOpen) contentComponents.onEvent(GuiEvent.Show()) } + + else -> {} } } } diff --git a/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/ModuleButton.kt b/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/ModuleButton.kt index 206cbfec4..33f287476 100644 --- a/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/ModuleButton.kt +++ b/common/src/main/kotlin/com/lambda/gui/impl/clickgui/buttons/ModuleButton.kt @@ -194,7 +194,6 @@ class ModuleButton( when (e.button) { Mouse.Button.Left -> { module.toggle() - } Mouse.Button.Right -> { @@ -209,6 +208,8 @@ class ModuleButton( val sound = if (isOpen) LambdaSound.SETTINGS_OPEN else LambdaSound.SETTINGS_CLOSE playSoundRandomly(sound.event) } + + else -> {} } } diff --git a/common/src/main/kotlin/com/lambda/interaction/material/ContainerManager.kt b/common/src/main/kotlin/com/lambda/interaction/material/ContainerManager.kt index 0bf9a3ca0..5aa2cca77 100644 --- a/common/src/main/kotlin/com/lambda/interaction/material/ContainerManager.kt +++ b/common/src/main/kotlin/com/lambda/interaction/material/ContainerManager.kt @@ -18,7 +18,7 @@ package com.lambda.interaction.material import com.lambda.core.Loadable -import com.lambda.event.events.InteractionEvent +import com.lambda.event.events.LocalPlayerEvent import com.lambda.event.events.ScreenHandlerEvent import com.lambda.event.listener.SafeListener.Companion.listener import com.lambda.interaction.material.StackSelection.Companion.select @@ -51,7 +51,7 @@ object ContainerManager : Loadable { private var lastInteractedBlockEntity: BlockEntity? = null init { - listener { + listener { lastInteractedBlockEntity = it.blockHitResult.blockPos.blockEntity(world) } diff --git a/common/src/main/kotlin/com/lambda/module/Module.kt b/common/src/main/kotlin/com/lambda/module/Module.kt index 263531640..dc9987f37 100644 --- a/common/src/main/kotlin/com/lambda/module/Module.kt +++ b/common/src/main/kotlin/com/lambda/module/Module.kt @@ -26,7 +26,7 @@ import com.lambda.config.settings.comparable.BooleanSetting import com.lambda.config.settings.numeric.DoubleSetting import com.lambda.context.SafeContext import com.lambda.event.Muteable -import com.lambda.event.events.KeyPressEvent +import com.lambda.event.events.KeyboardEvent import com.lambda.event.listener.Listener import com.lambda.event.listener.SafeListener import com.lambda.event.listener.SafeListener.Companion.listener @@ -128,7 +128,7 @@ abstract class Module( val keybind by keybindSetting init { - listener(alwaysListen = true) { event -> + listener(alwaysListen = true) { event -> if (mc.options.commandKey.isPressed) return@listener if (keybind == KeyCode.UNBOUND) return@listener if (event.translated != keybind) return@listener diff --git a/common/src/main/kotlin/com/lambda/module/modules/client/ClickGui.kt b/common/src/main/kotlin/com/lambda/module/modules/client/ClickGui.kt index ef5f2dee1..d515fa71a 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/client/ClickGui.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/client/ClickGui.kt @@ -18,7 +18,7 @@ package com.lambda.module.modules.client import com.lambda.event.events.ClientEvent -import com.lambda.event.events.KeyPressEvent +import com.lambda.event.events.KeyboardEvent import com.lambda.event.listener.SafeListener.Companion.listener import com.lambda.event.listener.UnsafeListener.Companion.unsafeListener import com.lambda.gui.impl.clickgui.LambdaClickGui @@ -62,7 +62,7 @@ object ClickGui : Module( LambdaHudGui.close() } - listener(priority = Int.MAX_VALUE) { event -> + listener(priority = Int.MAX_VALUE) { event -> if (mc.options.commandKey.isPressed) return@listener if (keybind == KeyCode.UNBOUND) return@listener if (event.translated != keybind) return@listener diff --git a/common/src/main/kotlin/com/lambda/module/modules/combat/Criticals.kt b/common/src/main/kotlin/com/lambda/module/modules/combat/Criticals.kt index 1a44270ec..a22c1610d 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/combat/Criticals.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/combat/Criticals.kt @@ -18,7 +18,7 @@ package com.lambda.module.modules.combat import com.lambda.context.SafeContext -import com.lambda.event.events.AttackEvent +import com.lambda.event.events.LocalPlayerEvent import com.lambda.event.listener.SafeListener.Companion.listener import com.lambda.interaction.rotation.Rotation import com.lambda.interaction.rotation.Rotation.Companion.rotationTo @@ -47,7 +47,7 @@ object Criticals : Module( } init { - listener { + listener { when (mode) { Mode.Grim -> { if (player.isOnGround) posPacket(0.00000001, rotation = player.rotation) diff --git a/common/src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt b/common/src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt index 2ec588b57..a7a137827 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt @@ -104,7 +104,7 @@ object FastBreak : Module( interaction.blockBreakingCooldown = interaction.blockBreakingCooldown.coerceAtMost(breakDelay) } - listener { + listener { it.progress += world.getBlockState(it.pos) .calcBlockBreakingDelta(player, world, it.pos) * (1 - breakThreshold) } diff --git a/common/src/main/kotlin/com/lambda/module/modules/player/Freecam.kt b/common/src/main/kotlin/com/lambda/module/modules/player/Freecam.kt index 523e403da..3fdf23715 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/player/Freecam.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/player/Freecam.kt @@ -102,7 +102,7 @@ object Freecam : Module( event.context = RotationContext(rotation, rotationConfig) } - listener { + listener { rotation = rotation.withDelta( it.deltaYaw * SENSITIVITY_FACTOR, it.deltaPitch * SENSITIVITY_FACTOR diff --git a/common/src/main/kotlin/com/lambda/module/modules/player/InventoryTweaks.kt b/common/src/main/kotlin/com/lambda/module/modules/player/InventoryTweaks.kt index 818fb2533..73fe50999 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/player/InventoryTweaks.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/player/InventoryTweaks.kt @@ -18,7 +18,7 @@ package com.lambda.module.modules.player import com.lambda.context.SafeContext -import com.lambda.event.events.InteractionEvent +import com.lambda.event.events.LocalPlayerEvent import com.lambda.event.events.ScreenHandlerEvent import com.lambda.event.listener.SafeListener.Companion.listener import com.lambda.module.Module @@ -50,7 +50,7 @@ object InventoryTweaks : Module( private var lastOpenScreen: ScreenHandler? = null init { - listener { + listener { if (it.action != SlotActionType.PICKUP || it.button != 1) return@listener val stack = it.screenHandler.getSlot(it.slot).stack if (!(instantShulker && stack.item in shulkerBoxes) && !(instantEChest && stack.item == Items.ENDER_CHEST)) return@listener diff --git a/common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt b/common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt index 2f11688f7..5d2c1a592 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt @@ -273,11 +273,11 @@ object PacketMine : Module( private var doubleBreakReturnSlot = 0 init { - listener { + listener { swingingNextAttack = false } - listener { + listener { it.cancel() if (swingOnManual) swingMainHand() @@ -332,7 +332,7 @@ object PacketMine : Module( startBreaking(it.pos) } - listener { + listener { if (!cancelNextSwing) return@listener cancelNextSwing = false diff --git a/common/src/main/kotlin/com/lambda/module/modules/player/Replay.kt b/common/src/main/kotlin/com/lambda/module/modules/player/Replay.kt index 15bcc72e1..0675158cf 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/player/Replay.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/player/Replay.kt @@ -23,7 +23,7 @@ import com.lambda.config.groups.IRotationConfig import com.lambda.context.SafeContext import com.lambda.core.TimerManager import com.lambda.event.EventFlow.lambdaScope -import com.lambda.event.events.KeyPressEvent +import com.lambda.event.events.KeyboardEvent import com.lambda.event.events.MovementEvent import com.lambda.event.events.RotationEvent import com.lambda.event.listener.SafeListener.Companion.listener @@ -111,7 +111,7 @@ object Replay : Module( .create() init { - listener { + listener { if (mc.currentScreen != null && !mc.options.commandKey.isPressed) return@listener when (it.translated) { diff --git a/common/src/main/kotlin/com/lambda/module/modules/render/Particles.kt b/common/src/main/kotlin/com/lambda/module/modules/render/Particles.kt index 69e880f89..eac043bd9 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/render/Particles.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/render/Particles.kt @@ -19,7 +19,7 @@ package com.lambda.module.modules.render import com.lambda.Lambda.mc import com.lambda.context.SafeContext -import com.lambda.event.events.AttackEvent +import com.lambda.event.events.LocalPlayerEvent import com.lambda.event.events.MovementEvent import com.lambda.event.events.RenderEvent import com.lambda.event.events.TickEvent @@ -102,7 +102,7 @@ object Particles : Module( } } - listener { event -> + listener { event -> spawnForEntity(event.entity) } diff --git a/common/src/main/kotlin/com/lambda/util/KeyCode.kt b/common/src/main/kotlin/com/lambda/util/KeyCode.kt index b1bc1e258..91cb1acb0 100644 --- a/common/src/main/kotlin/com/lambda/util/KeyCode.kt +++ b/common/src/main/kotlin/com/lambda/util/KeyCode.kt @@ -155,7 +155,14 @@ enum class KeyCode(val keyCode: Int) { private val keyCodeMap = entries.associateBy { it.keyCode } private val nameMap = entries.associateBy { it.name.lowercase() } + /** + * Returns the KeyCode enum instance from the key code number or [UNBOUND] if invalid + */ fun fromKeyCode(keyCode: Int) = keyCodeMap[keyCode] ?: UNBOUND + + /** + * Returns the KeyCode enum instance from the key code name or [UNBOUND] if invalid + */ fun fromKeyName(name: String) = nameMap[name.lowercase()] ?: UNBOUND /** diff --git a/common/src/main/kotlin/com/lambda/util/Mouse.kt b/common/src/main/kotlin/com/lambda/util/Mouse.kt index a4e97d234..fe7782123 100644 --- a/common/src/main/kotlin/com/lambda/util/Mouse.kt +++ b/common/src/main/kotlin/com/lambda/util/Mouse.kt @@ -18,21 +18,45 @@ package com.lambda.util import org.lwjgl.glfw.GLFW +import kotlin.jvm.Throws class Mouse { - @JvmInline - value class Button(val key: Int) { - companion object { - val Left = Button(GLFW.GLFW_MOUSE_BUTTON_LEFT) - val Right = Button(GLFW.GLFW_MOUSE_BUTTON_RIGHT) - val Middle = Button(GLFW.GLFW_MOUSE_BUTTON_MIDDLE) - } + enum class Button(val key: Int) { + Left(GLFW.GLFW_MOUSE_BUTTON_LEFT), + Right(GLFW.GLFW_MOUSE_BUTTON_RIGHT), + Middle(GLFW.GLFW_MOUSE_BUTTON_MIDDLE); val isMainButton get() = key == GLFW.GLFW_MOUSE_BUTTON_LEFT || key == GLFW.GLFW_MOUSE_BUTTON_RIGHT + + companion object { + private val mouseCodeMap = entries.associateBy { it.key } + private val nameMap = entries.associateBy { it.name.lowercase() } + + @Throws(IllegalArgumentException::class) + fun fromMouseCode(code: Int) = + mouseCodeMap[code] ?: throw IllegalArgumentException("Mouse code $code not found in mouseCodeMap.") + + @Throws(IllegalArgumentException::class) + fun fromMouseName(name: String) = + nameMap[name.lowercase()] ?: throw IllegalArgumentException("Mouse name '$name' not found in nameMap.") + } } enum class Action { Click, - Release + Release; + + companion object { + private val mouseActionMap = entries.associateBy { it.ordinal } + private val nameMap = entries.associateBy { it.name.lowercase() } + + @Throws(IllegalArgumentException::class) + fun fromActionCode(code: Int) = + mouseActionMap[code] ?: throw IllegalArgumentException("Action code $code not found in mouseActionMap.") + + @Throws(IllegalArgumentException::class) + fun fromActionName(name: String) = + nameMap[name.lowercase()] ?: throw IllegalArgumentException("Action name '$name' not found in nameMap.") + } } } diff --git a/common/src/main/resources/lambda.mixins.common.json b/common/src/main/resources/lambda.mixins.common.json index 5c745c805..409f2732b 100644 --- a/common/src/main/resources/lambda.mixins.common.json +++ b/common/src/main/resources/lambda.mixins.common.json @@ -11,10 +11,12 @@ "entity.ClientPlayerEntityMixin", "entity.ClientPlayInteractionManagerMixin", "entity.EntityMixin", + "entity.FireworkRocketEntityMixin", "entity.LivingEntityMixin", "entity.PlayerEntityMixin", "input.KeyBindingMixin", "input.KeyboardMixin", + "input.MouseMixin", "items.BarrierBlockMixin", "items.TridentMixin", "network.ClientConnectionMixin", @@ -43,8 +45,7 @@ "render.WorldRendererMixin", "world.BlockCollisionSpliteratorMixin", "world.ClientChunkManagerMixin", - "world.ClientWorldMixin", - "entity.FireworkRocketEntityMixin" + "world.ClientWorldMixin" ], "injectors": { "defaultRequire": 1 From 048ddf7e3be0a77f8c01eeed4eda4d20a5d39462 Mon Sep 17 00:00:00 2001 From: Edouard127 <46357922+Edouard127@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:30:54 -0500 Subject: [PATCH 2/5] missed one here --- .../com/lambda/event/events/PacketEvent.kt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/common/src/main/kotlin/com/lambda/event/events/PacketEvent.kt b/common/src/main/kotlin/com/lambda/event/events/PacketEvent.kt index 897ae2dcc..f9da804f3 100644 --- a/common/src/main/kotlin/com/lambda/event/events/PacketEvent.kt +++ b/common/src/main/kotlin/com/lambda/event/events/PacketEvent.kt @@ -21,8 +21,6 @@ import com.lambda.event.Event import com.lambda.event.EventFlow import com.lambda.event.callback.Cancellable import com.lambda.event.callback.ICancellable -import com.lambda.event.events.PacketEvent.Receive -import com.lambda.event.events.PacketEvent.Send import com.lambda.util.ClientPacket import com.lambda.util.ServerPacket @@ -41,44 +39,44 @@ import com.lambda.util.ServerPacket * @see Send * @see Receive */ -abstract class PacketEvent : Event { +sealed class PacketEvent { /** * Represents a [PacketEvent] that is triggered when a packet is sent. * It has two subclasses: [Pre] and [Post], which are triggered before and after the packet is sent. */ - sealed class Send : PacketEvent() { + sealed class Send { /** * Represents the event triggered before a packet is sent. * * @param packet the packet that is about to be sent. */ - class Pre(val packet: ClientPacket) : Send(), ICancellable by Cancellable() + data class Pre(val packet: ClientPacket) : ICancellable by Cancellable() /** * Represents the event triggered after a packet is sent. * * @param packet the packet that has been sent. */ - class Post(val packet: ClientPacket) : Send() + data class Post(val packet: ClientPacket) : Event } /** * Represents a [PacketEvent] that is triggered when a packet is received. * It has two subclasses: [Pre] and [Post], which are triggered before and after the packet is received. */ - sealed class Receive : PacketEvent() { + sealed class Receive { /** * Represents the event triggered before a packet is received. * * @param packet the packet that is about to be received. */ - class Pre(val packet: ServerPacket) : Receive(), ICancellable by Cancellable() + data class Pre(val packet: ServerPacket) : ICancellable by Cancellable() /** * Represents the event triggered after a packet is received. * * @param packet the packet that has been received. */ - class Post(val packet: ServerPacket) : Receive() + data class Post(val packet: ServerPacket) : Event } } From d769d3e51193726b18eb4e2ab239ea4f3070b49b Mon Sep 17 00:00:00 2001 From: Edouard127 <46357922+Edouard127@users.noreply.github.com> Date: Tue, 26 Nov 2024 13:17:46 -0500 Subject: [PATCH 3/5] added deprecation notice on old events --- common/src/main/kotlin/com/lambda/gui/api/GuiEvent.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/common/src/main/kotlin/com/lambda/gui/api/GuiEvent.kt b/common/src/main/kotlin/com/lambda/gui/api/GuiEvent.kt index 54e6b5aec..6477a2728 100644 --- a/common/src/main/kotlin/com/lambda/gui/api/GuiEvent.kt +++ b/common/src/main/kotlin/com/lambda/gui/api/GuiEvent.kt @@ -27,9 +27,19 @@ abstract class GuiEvent : Event { class Hide : GuiEvent() class Tick : GuiEvent() class Render : GuiEvent() + + @Deprecated("Deprecated key press event", replaceWith = ReplaceWith("com.lambda.event.events.KeyboardEvent.Press")) class KeyPress(val key: KeyCode) : GuiEvent() + + @Deprecated("Deprecated char event", replaceWith = ReplaceWith("com.lambda.event.events.KeyboardEvent.Char")) class CharTyped(val char: Char) : GuiEvent() + + @Deprecated("Use the new global mouse events", replaceWith = ReplaceWith("com.lambda.event.events.MouseEvent.Click")) class MouseClick(val button: Mouse.Button, val action: Mouse.Action, val mouse: Vec2d) : GuiEvent() + + @Deprecated("Use the new global mouse events", replaceWith = ReplaceWith("com.lambda.event.events.MouseEvent.Move")) class MouseMove(val mouse: Vec2d) : GuiEvent() + + @Deprecated("Use the new global mouse events", replaceWith = ReplaceWith("com.lambda.event.events.MouseEvent.Scroll")) class MouseScroll(val mouse: Vec2d, val delta: Double) : GuiEvent() } From 9f9a7f237e31a6bbfd3a1de465b3e18f27c2ac82 Mon Sep 17 00:00:00 2001 From: Constructor Date: Wed, 27 Nov 2024 03:22:40 +0100 Subject: [PATCH 4/5] Rework event structure, add some missing ones --- .../ClientPlayInteractionManagerMixin.java | 54 +++++--- .../mixin/entity/ClientPlayerEntityMixin.java | 11 +- .../com/lambda/mixin/entity/EntityMixin.java | 4 +- .../mixin/entity/LivingEntityMixin.java | 10 +- .../com/lambda/mixin/input/MouseMixin.java | 13 +- .../kotlin/com/lambda/event/Subscriber.kt | 1 - .../lambda/event/events/LocalPlayerEvent.kt | 90 ------------- .../com/lambda/event/events/MouseEvent.kt | 9 +- .../com/lambda/event/events/MovementEvent.kt | 96 ++++++++++++- .../com/lambda/event/events/PacketEvent.kt | 12 +- .../com/lambda/event/events/PlayerEvent.kt | 126 ++++++++++++++++++ .../com/lambda/event/events/WorldEvent.kt | 6 +- .../interaction/material/ContainerManager.kt | 4 +- .../lambda/module/modules/combat/Criticals.kt | 4 +- .../module/modules/movement/ElytraFly.kt | 2 +- .../lambda/module/modules/movement/Jesus.kt | 2 +- .../lambda/module/modules/movement/NoFall.kt | 2 +- .../lambda/module/modules/movement/Speed.kt | 4 +- .../lambda/module/modules/player/FastBreak.kt | 2 +- .../lambda/module/modules/player/Freecam.kt | 2 +- .../module/modules/player/InventoryTweaks.kt | 4 +- .../module/modules/player/PacketMine.kt | 6 +- .../lambda/module/modules/player/Replay.kt | 2 +- .../lambda/module/modules/render/Particles.kt | 6 +- .../src/main/kotlin/com/lambda/util/Mouse.kt | 7 +- 25 files changed, 314 insertions(+), 165 deletions(-) delete mode 100644 common/src/main/kotlin/com/lambda/event/events/LocalPlayerEvent.kt create mode 100644 common/src/main/kotlin/com/lambda/event/events/PlayerEvent.kt diff --git a/common/src/main/java/com/lambda/mixin/entity/ClientPlayInteractionManagerMixin.java b/common/src/main/java/com/lambda/mixin/entity/ClientPlayInteractionManagerMixin.java index 775428d34..3f863fd52 100644 --- a/common/src/main/java/com/lambda/mixin/entity/ClientPlayInteractionManagerMixin.java +++ b/common/src/main/java/com/lambda/mixin/entity/ClientPlayInteractionManagerMixin.java @@ -18,7 +18,7 @@ package com.lambda.mixin.entity; import com.lambda.event.EventFlow; -import com.lambda.event.events.LocalPlayerEvent; +import com.lambda.event.events.PlayerEvent; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.ClientPlayerInteractionManager; @@ -28,6 +28,7 @@ import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import org.spongepowered.asm.mixin.Final; @@ -43,38 +44,55 @@ public class ClientPlayInteractionManagerMixin { @Shadow public float currentBreakingProgress; - @Final - @Shadow - private MinecraftClient client; - @Inject(method = "interactBlock", at = @At("HEAD")) + @Inject(method = "interactBlock", at = @At("HEAD"), cancellable = true) public void interactBlockHead(final ClientPlayerEntity player, final Hand hand, final BlockHitResult hitResult, final CallbackInfoReturnable cir) { - if (client.world == null) return; - EventFlow.post(new LocalPlayerEvent.BlockInteract(client.world, hitResult)); + if (EventFlow.post(new PlayerEvent.Interact.Block(hand, hitResult)).isCanceled()) { + cir.setReturnValue(ActionResult.FAIL); + } } - @Inject(method = "clickSlot", at = @At("HEAD"), cancellable = true) - public void clickSlotHead(int syncId, int slotId, int button, SlotActionType actionType, PlayerEntity player, CallbackInfo ci) { - if (syncId != player.currentScreenHandler.syncId) return; - var click = new LocalPlayerEvent.SlotClick(syncId, slotId, button, actionType, player.currentScreenHandler); - if (EventFlow.post(click).isCanceled()) ci.cancel(); + @Inject(method = "interactEntityAtLocation", at = @At("HEAD"), cancellable = true) + public void interactEntityAtLocation(PlayerEntity player, Entity entity, EntityHitResult hitResult, Hand hand, CallbackInfoReturnable cir) { + if (EventFlow.post(new PlayerEvent.Interact.Entity(hand, entity, hitResult)).isCanceled()) { + cir.setReturnValue(ActionResult.FAIL); + } + } + + @Inject(method = "interactItem", at = @At("HEAD"), cancellable = true) + public void interactItemHead(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { + if (EventFlow.post(new PlayerEvent.Interact.Item(hand)).isCanceled()) { + cir.setReturnValue(ActionResult.FAIL); + } + } + + @Inject(method = "attackBlock", at = @At("HEAD")) + public void onAttackBlock(BlockPos pos, Direction side, CallbackInfoReturnable cir) { + if (EventFlow.post(new PlayerEvent.Attack.Block(pos, side)).isCanceled()) cir.cancel(); } @Inject(method = "attackEntity", at = @At("HEAD"), cancellable = true) void onAttackPre(PlayerEntity player, Entity target, CallbackInfo ci) { - if (EventFlow.post(new LocalPlayerEvent.EntityAttack(target)).isCanceled()) ci.cancel(); + if (EventFlow.post(new PlayerEvent.Attack.Entity(target)).isCanceled()) ci.cancel(); } - @Inject(method = "attackBlock", at = @At("HEAD"), cancellable = true) - public void onAttackBlock(BlockPos pos, Direction side, CallbackInfoReturnable cir) { - if (EventFlow.post(new LocalPlayerEvent.BlockAttack(pos, side)).isCanceled()) cir.cancel(); + @Inject(method = "clickSlot", at = @At("HEAD"), cancellable = true) + public void clickSlotHead(int syncId, int slotId, int button, SlotActionType actionType, PlayerEntity player, CallbackInfo ci) { + if (syncId != player.currentScreenHandler.syncId) return; + var click = new PlayerEvent.SlotClick(syncId, slotId, button, actionType, player.currentScreenHandler); + if (EventFlow.post(click).isCanceled()) ci.cancel(); } @Inject(method = "updateBlockBreakingProgress", at = @At("HEAD"), cancellable = true) private void updateBlockBreakingProgressPre(BlockPos pos, Direction side, CallbackInfoReturnable cir) { - var event = EventFlow.post(new LocalPlayerEvent.BreakingProgress(pos, side, currentBreakingProgress)); - if (event.isCanceled()) cir.cancel(); + var event = EventFlow.post(new PlayerEvent.Breaking.Update(pos, side, currentBreakingProgress)); + if (event.isCanceled()) cir.setReturnValue(false); currentBreakingProgress = event.getProgress(); } + + @Inject(method = "cancelBlockBreaking", at = @At("HEAD"), cancellable = true) + private void cancelBlockBreakingPre(CallbackInfo ci) { + if (EventFlow.post(new PlayerEvent.Breaking.Cancel(currentBreakingProgress)).isCanceled()) ci.cancel(); + } } diff --git a/common/src/main/java/com/lambda/mixin/entity/ClientPlayerEntityMixin.java b/common/src/main/java/com/lambda/mixin/entity/ClientPlayerEntityMixin.java index b73f07f49..63766b233 100644 --- a/common/src/main/java/com/lambda/mixin/entity/ClientPlayerEntityMixin.java +++ b/common/src/main/java/com/lambda/mixin/entity/ClientPlayerEntityMixin.java @@ -19,7 +19,7 @@ import com.lambda.Lambda; import com.lambda.event.EventFlow; -import com.lambda.event.events.LocalPlayerEvent; +import com.lambda.event.events.PlayerEvent; import com.lambda.event.events.MovementEvent; import com.lambda.event.events.TickEvent; import com.lambda.interaction.PlayerPacketManager; @@ -50,9 +50,6 @@ public abstract class ClientPlayerEntityMixin extends EntityMixin { @Shadow protected abstract void autoJump(float dx, float dz); - @Shadow - public abstract boolean isUsingItem(); - @Inject(method = "move", at = @At("HEAD"), cancellable = true) void onMove(MovementType movementType, Vec3d movement, CallbackInfo ci) { ClientPlayerEntity self = (ClientPlayerEntity) (Object) this; @@ -63,9 +60,9 @@ void onMove(MovementType movementType, Vec3d movement, CallbackInfo ci) { float prevX = (float) self.getX(); float prevZ = (float) self.getZ(); - EventFlow.post(new MovementEvent.Pre()); + EventFlow.post(new MovementEvent.Player.Pre(movementType, movement)); super.move(movementType, self.getVelocity()); - EventFlow.post(new MovementEvent.Post()); + EventFlow.post(new MovementEvent.Player.Post(movementType, movement)); float currX = (float) self.getX(); float currZ = (float) self.getZ(); @@ -125,6 +122,6 @@ float fixHeldItemPitch(ClientPlayerEntity instance) { @Inject(method = "swingHand", at = @At("HEAD"), cancellable = true) void onSwingHandPre(Hand hand, CallbackInfo ci) { - if (EventFlow.post(new LocalPlayerEvent.SwingHand(hand)).isCanceled()) ci.cancel(); + if (EventFlow.post(new PlayerEvent.SwingHand(hand)).isCanceled()) ci.cancel(); } } diff --git a/common/src/main/java/com/lambda/mixin/entity/EntityMixin.java b/common/src/main/java/com/lambda/mixin/entity/EntityMixin.java index 6d4fc5776..1d29945bd 100644 --- a/common/src/main/java/com/lambda/mixin/entity/EntityMixin.java +++ b/common/src/main/java/com/lambda/mixin/entity/EntityMixin.java @@ -19,7 +19,7 @@ import com.lambda.Lambda; import com.lambda.event.EventFlow; -import com.lambda.event.events.LocalPlayerEvent; +import com.lambda.event.events.PlayerEvent; import com.lambda.event.events.WorldEvent; import com.lambda.interaction.RotationManager; import com.lambda.util.math.Vec2d; @@ -87,7 +87,7 @@ float fixDirectionPitch2(Entity entity) { @Inject(method = "changeLookDirection", at = @At("HEAD"), cancellable = true) private void changeLookDirection(double cursorDeltaX, double cursorDeltaY, CallbackInfo ci) { - if (EventFlow.post(new LocalPlayerEvent.ChangeLookDirection(cursorDeltaX, cursorDeltaY)).isCanceled()) ci.cancel(); + if (EventFlow.post(new PlayerEvent.ChangeLookDirection(cursorDeltaX, cursorDeltaY)).isCanceled()) ci.cancel(); } @Inject(method = "onTrackedDataSet(Lnet/minecraft/entity/data/TrackedData;)V", at = @At("TAIL")) diff --git a/common/src/main/java/com/lambda/mixin/entity/LivingEntityMixin.java b/common/src/main/java/com/lambda/mixin/entity/LivingEntityMixin.java index 1e4e52eb4..61e4911dc 100644 --- a/common/src/main/java/com/lambda/mixin/entity/LivingEntityMixin.java +++ b/common/src/main/java/com/lambda/mixin/entity/LivingEntityMixin.java @@ -63,18 +63,12 @@ void onJump(CallbackInfo ci) { @Inject(method = "travel", at = @At("HEAD"), cancellable = true) void onTravelPre(Vec3d movementInput, CallbackInfo ci) { - LivingEntity self = (LivingEntity) (Object) this; - if (self != Lambda.getMc().player) return; - - if (EventFlow.post(new MovementEvent.Travel.Pre()).isCanceled()) ci.cancel(); + if (EventFlow.post(new MovementEvent.Entity.Pre((LivingEntity) (Object) this, movementInput)).isCanceled()) ci.cancel(); } @Inject(method = "travel", at = @At("TAIL")) void onTravelPost(Vec3d movementInput, CallbackInfo ci) { - LivingEntity self = (LivingEntity) (Object) this; - if (self != Lambda.getMc().player) return; - - EventFlow.post(new MovementEvent.Travel.Post()); + EventFlow.post(new MovementEvent.Entity.Post((LivingEntity) (Object) this, movementInput)); } @Redirect(method = "travel", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getPitch()F")) diff --git a/common/src/main/java/com/lambda/mixin/input/MouseMixin.java b/common/src/main/java/com/lambda/mixin/input/MouseMixin.java index 41c65501a..da53d9531 100644 --- a/common/src/main/java/com/lambda/mixin/input/MouseMixin.java +++ b/common/src/main/java/com/lambda/mixin/input/MouseMixin.java @@ -19,7 +19,10 @@ import com.lambda.event.EventFlow; import com.lambda.event.events.MouseEvent; +import com.lambda.util.math.Vec2d; import net.minecraft.client.Mouse; +import com.lambda.util.Mouse.Button; +import com.lambda.util.Mouse.Action; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -34,18 +37,16 @@ public class MouseMixin { @Inject(method = "onMouseButton(JIII)V", at = @At("HEAD"), cancellable = true) private void onMouseButton(long window, int button, int action, int mods, CallbackInfo ci) { - com.lambda.util.Mouse.Button btn = com.lambda.util.Mouse.Button.Companion.fromMouseCode(button); - com.lambda.util.Mouse.Action act = com.lambda.util.Mouse.Action.Companion.fromActionCode(action); - com.lambda.util.math.Vec2d position = new com.lambda.util.math.Vec2d(x, y); + Vec2d position = new Vec2d(x, y); - if (EventFlow.post(new MouseEvent.Click(btn, act, mods, position)).isCanceled()) { + if (EventFlow.post(new MouseEvent.Click(button, action, mods, position)).isCanceled()) { ci.cancel(); } } @Inject(method = "onMouseScroll(JDD)V", at = @At("HEAD"), cancellable = true) private void onMouseScroll(long window, double horizontal, double vertical, CallbackInfo ci) { - com.lambda.util.math.Vec2d delta = new com.lambda.util.math.Vec2d(horizontal, vertical); + Vec2d delta = new Vec2d(horizontal, vertical); if (EventFlow.post(new MouseEvent.Scroll(delta)).isCanceled()) { ci.cancel(); @@ -56,7 +57,7 @@ private void onMouseScroll(long window, double horizontal, double vertical, Call private void onCursorPos(long window, double x, double y, CallbackInfo ci) { if (x + y == this.x + this.y) return; - com.lambda.util.math.Vec2d position = new com.lambda.util.math.Vec2d(x, y); + Vec2d position = new Vec2d(x, y); if (EventFlow.post(new MouseEvent.Move(position)).isCanceled()) { ci.cancel(); diff --git a/common/src/main/kotlin/com/lambda/event/Subscriber.kt b/common/src/main/kotlin/com/lambda/event/Subscriber.kt index 8fc3a462d..3a78dcf4a 100644 --- a/common/src/main/kotlin/com/lambda/event/Subscriber.kt +++ b/common/src/main/kotlin/com/lambda/event/Subscriber.kt @@ -35,7 +35,6 @@ class Subscriber : ConcurrentHashMap, ConcurrentSkipListSet
  • > get() = ConcurrentSkipListSet(Listener.comparator.reversed()) - /** Allows a [Listener] to start receiving a specific type of [Event] */ inline fun subscribe(listener: Listener) = getOrPut(T::class) { defaultListenerSet }.add(listener) diff --git a/common/src/main/kotlin/com/lambda/event/events/LocalPlayerEvent.kt b/common/src/main/kotlin/com/lambda/event/events/LocalPlayerEvent.kt deleted file mode 100644 index 130486589..000000000 --- a/common/src/main/kotlin/com/lambda/event/events/LocalPlayerEvent.kt +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2024 Lambda - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.lambda.event.events - -import com.lambda.event.Event -import com.lambda.event.callback.Cancellable -import com.lambda.event.callback.ICancellable -import net.minecraft.client.world.ClientWorld -import net.minecraft.entity.Entity -import net.minecraft.screen.ScreenHandler -import net.minecraft.screen.slot.SlotActionType -import net.minecraft.util.Hand -import net.minecraft.util.hit.BlockHitResult -import net.minecraft.util.math.BlockPos -import net.minecraft.util.math.Direction - -sealed class LocalPlayerEvent { - /** - * Represents the local player moving the cursor around - */ - data class ChangeLookDirection( - val deltaYaw: Double, - val deltaPitch: Double, - ) : ICancellable by Cancellable() - - /** - * Represents the local player swinging its hand - */ - data class SwingHand( - val hand: Hand - ) : ICancellable by Cancellable() - - /** - * Represents the local player attacking an entity - */ - data class EntityAttack( - val entity: Entity - ) : ICancellable by Cancellable() - - /** - * Represents the local player interacting (right-click) with blocks - */ - data class BlockInteract( - val world: ClientWorld, - val blockHitResult: BlockHitResult - ) : Event - - /** - * Represents the local player attacking a block - */ - data class BlockAttack( - val pos: BlockPos, - val side: Direction - ) : ICancellable by Cancellable() - - /** - * Represents events triggered during a block breaking action - */ - data class BreakingProgress( - val pos: BlockPos, - val side: Direction, - var progress: Float, - ) : ICancellable by Cancellable() - - /** - * Represents the local player clicking on a slot in a screen - */ - data class SlotClick( - val syncId: Int, - val slot: Int, - val button: Int, - val action: SlotActionType, - val screenHandler: ScreenHandler, - ) : ICancellable by Cancellable() -} diff --git a/common/src/main/kotlin/com/lambda/event/events/MouseEvent.kt b/common/src/main/kotlin/com/lambda/event/events/MouseEvent.kt index cb4d2029a..eaf5f2a3a 100644 --- a/common/src/main/kotlin/com/lambda/event/events/MouseEvent.kt +++ b/common/src/main/kotlin/com/lambda/event/events/MouseEvent.kt @@ -36,7 +36,14 @@ sealed class MouseEvent { val action: Mouse.Action, val modifiers: Int, val position: Vec2d - ) : ICancellable by Cancellable() + ) : ICancellable by Cancellable() { + constructor(button: Int, action: Int, modifiers: Int, position: Vec2d) : this( + Mouse.Button.fromMouseCode(button), + Mouse.Action.fromActionCode(action), + modifiers, + position + ) + } /** * Represents a mouse scroll event diff --git a/common/src/main/kotlin/com/lambda/event/events/MovementEvent.kt b/common/src/main/kotlin/com/lambda/event/events/MovementEvent.kt index c4aaaf57e..e288d0736 100644 --- a/common/src/main/kotlin/com/lambda/event/events/MovementEvent.kt +++ b/common/src/main/kotlin/com/lambda/event/events/MovementEvent.kt @@ -21,29 +21,113 @@ import com.lambda.event.Event import com.lambda.event.callback.Cancellable import com.lambda.event.callback.ICancellable import net.minecraft.client.input.Input +import net.minecraft.entity.LivingEntity +import net.minecraft.entity.MovementType +import net.minecraft.util.math.Vec3d sealed class MovementEvent { - class Pre : Event - class Post : Event + /** + * Represents player movement update events. + * This event will even be triggered if the player is not moving. + */ + sealed class Player { + abstract val movementType: MovementType + abstract val movement: Vec3d - sealed class Travel { - class Pre : ICancellable by Cancellable() - class Post : Event + /** + * Event triggered before player movement. + * + * @property movementType The type of movement. + * @property movement The movement vector. + */ + class Pre( + override val movementType: MovementType, + override val movement: Vec3d, + ) : Player(), ICancellable by Cancellable() + + /** + * Event triggered after player movement. + * + * @property movementType The type of movement. + * @property movement The movement vector. + */ + class Post( + override val movementType: MovementType, + override val movement: Vec3d, + ) : Player(), Event + } + + /** + * Represents entity movement update events. + * This event will even be triggered if the entity is not moving. + */ + sealed class Entity { + abstract val entity: LivingEntity + abstract val movementInput: Vec3d + + /** + * Event triggered before entity movement. + * + * @property entity The entity involved in the movement event. + * @property movementInput The movement input vector for the entity. + */ + class Pre( + override val entity: LivingEntity, + override val movementInput: Vec3d, + ) : Entity(), ICancellable by Cancellable() + + /** + * Event triggered after entity movement. + * + * @property entity The entity involved in the movement event. + * @property movementInput The movement input vector for the entity. + */ + class Post( + override val entity: LivingEntity, + override val movementInput: Vec3d, + ) : Entity(), Event } + /** + * Event triggered when the user's input is updated. + * + * @property input The input state of the player. + * @property slowDown Indicates if the player should slow down. + * @property slowDownFactor The factor by which the player should slow down. + */ data class InputUpdate( val input: Input, var slowDown: Boolean, var slowDownFactor: Float, ) : Event + /** + * Event triggered when the player starts or stops sprinting. + * + * @property sprint Indicates if the player is sprinting. Can be modified! + */ data class Sprint(var sprint: Boolean) : Event + + /** + * Event triggered when the player starts or stops sneaking. + * + * @property sneak Indicates if the player is sneaking. Can be modified! + */ data class Sneak(var sneak: Boolean) : Event + /** + * Event triggered when the player reaches a ledge and may clip. + * + * @property clip Indicates if the player should clip at the ledge. Can be modified! + */ data class ClipAtLedge( var clip: Boolean, ) : Event + /** + * Event triggered when the player jumps. + * + * @property height The height of the jump. Can be modified! + */ data class Jump(var height: Double) : ICancellable by Cancellable() - class SlowDown : ICancellable by Cancellable() } diff --git a/common/src/main/kotlin/com/lambda/event/events/PacketEvent.kt b/common/src/main/kotlin/com/lambda/event/events/PacketEvent.kt index f9da804f3..c34af5ee6 100644 --- a/common/src/main/kotlin/com/lambda/event/events/PacketEvent.kt +++ b/common/src/main/kotlin/com/lambda/event/events/PacketEvent.kt @@ -45,19 +45,21 @@ sealed class PacketEvent { * It has two subclasses: [Pre] and [Post], which are triggered before and after the packet is sent. */ sealed class Send { + abstract val packet: ClientPacket + /** * Represents the event triggered before a packet is sent. * * @param packet the packet that is about to be sent. */ - data class Pre(val packet: ClientPacket) : ICancellable by Cancellable() + data class Pre(override val packet: ClientPacket) : Send(), ICancellable by Cancellable() /** * Represents the event triggered after a packet is sent. * * @param packet the packet that has been sent. */ - data class Post(val packet: ClientPacket) : Event + data class Post(override val packet: ClientPacket) : Send(), Event } /** @@ -65,18 +67,20 @@ sealed class PacketEvent { * It has two subclasses: [Pre] and [Post], which are triggered before and after the packet is received. */ sealed class Receive { + abstract val packet: ServerPacket + /** * Represents the event triggered before a packet is received. * * @param packet the packet that is about to be received. */ - data class Pre(val packet: ServerPacket) : ICancellable by Cancellable() + data class Pre(override val packet: ServerPacket) : Receive(), ICancellable by Cancellable() /** * Represents the event triggered after a packet is received. * * @param packet the packet that has been received. */ - data class Post(val packet: ServerPacket) : Event + data class Post(override val packet: ServerPacket) : Receive(), Event } } diff --git a/common/src/main/kotlin/com/lambda/event/events/PlayerEvent.kt b/common/src/main/kotlin/com/lambda/event/events/PlayerEvent.kt new file mode 100644 index 000000000..8564d9f38 --- /dev/null +++ b/common/src/main/kotlin/com/lambda/event/events/PlayerEvent.kt @@ -0,0 +1,126 @@ +/* + * Copyright 2024 Lambda + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.lambda.event.events + +import com.lambda.event.callback.Cancellable +import com.lambda.event.callback.ICancellable +import net.minecraft.screen.ScreenHandler +import net.minecraft.screen.slot.SlotActionType +import net.minecraft.util.Hand +import net.minecraft.util.hit.BlockHitResult +import net.minecraft.util.hit.EntityHitResult +import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.Direction + +sealed class PlayerEvent { + /** + * Represents the player moving the cursor around + */ + data class ChangeLookDirection( + val deltaYaw: Double, + val deltaPitch: Double, + ) : ICancellable by Cancellable() + + /** + * Represents the player swinging its hand + */ + data class SwingHand( + val hand: Hand + ) : ICancellable by Cancellable() + + sealed class Interact { + /** + * Represents the player interacting (right-click) with blocks + * + * @param hand The hand used to interact with the block + * @param blockHitResult Details about the block being interacted with + */ + data class Block( + val hand: Hand, + val blockHitResult: BlockHitResult + ) : ICancellable by Cancellable() + + /** + * Represents the player interacting (right-click) with entities + * + * @param hand The hand used to interact with the entity + * @param entity The entity being interacted with + * @param entityHitResult Details about the entity being interacted with + */ + data class Entity( + val hand: Hand, + val entity: net.minecraft.entity.Entity, + val entityHitResult: EntityHitResult + ) : ICancellable by Cancellable() + + /** + * Represents the player interacting (right-click) with an item in the inventory + * + * @param hand The hand used to interact with the item + */ + data class Item( + val hand: Hand + ) : ICancellable by Cancellable() + } + + sealed class Attack { + /** + * Represents the player attacking a block + */ + data class Block( + val pos: BlockPos, + val side: Direction + ) : ICancellable by Cancellable() + + /** + * Represents the player attacking an entity + */ + data class Entity( + val entity: net.minecraft.entity.Entity + ) : ICancellable by Cancellable() + } + + sealed class Breaking { + /** + * Represents events triggered during a block breaking action + */ + data class Update( + val pos: BlockPos, + val side: Direction, + var progress: Float, + ) : ICancellable by Cancellable() + + /** + * Represents the player canceling a block breaking action + */ + data class Cancel( + var progress: Float, + ) : ICancellable by Cancellable() + } + + /** + * Represents the player clicking on a slot in a screen + */ + data class SlotClick( + val syncId: Int, + val slot: Int, + val button: Int, + val action: SlotActionType, + val screenHandler: ScreenHandler, + ) : ICancellable by Cancellable() +} diff --git a/common/src/main/kotlin/com/lambda/event/events/WorldEvent.kt b/common/src/main/kotlin/com/lambda/event/events/WorldEvent.kt index e9b275a4f..f7be6c13c 100644 --- a/common/src/main/kotlin/com/lambda/event/events/WorldEvent.kt +++ b/common/src/main/kotlin/com/lambda/event/events/WorldEvent.kt @@ -73,5 +73,9 @@ sealed class WorldEvent { /** * Triggered upon player colliding with a block */ - data class Collision(val pos: BlockPos, val state: BlockState, var shape: VoxelShape) : Event + data class Collision( + val pos: BlockPos, + val state: BlockState, + var shape: VoxelShape + ) : Event } diff --git a/common/src/main/kotlin/com/lambda/interaction/material/ContainerManager.kt b/common/src/main/kotlin/com/lambda/interaction/material/ContainerManager.kt index 5aa2cca77..d2b645e7c 100644 --- a/common/src/main/kotlin/com/lambda/interaction/material/ContainerManager.kt +++ b/common/src/main/kotlin/com/lambda/interaction/material/ContainerManager.kt @@ -18,7 +18,7 @@ package com.lambda.interaction.material import com.lambda.core.Loadable -import com.lambda.event.events.LocalPlayerEvent +import com.lambda.event.events.PlayerEvent import com.lambda.event.events.ScreenHandlerEvent import com.lambda.event.listener.SafeListener.Companion.listener import com.lambda.interaction.material.StackSelection.Companion.select @@ -51,7 +51,7 @@ object ContainerManager : Loadable { private var lastInteractedBlockEntity: BlockEntity? = null init { - listener { + listener { lastInteractedBlockEntity = it.blockHitResult.blockPos.blockEntity(world) } diff --git a/common/src/main/kotlin/com/lambda/module/modules/combat/Criticals.kt b/common/src/main/kotlin/com/lambda/module/modules/combat/Criticals.kt index a22c1610d..3c5c52ac3 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/combat/Criticals.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/combat/Criticals.kt @@ -18,7 +18,7 @@ package com.lambda.module.modules.combat import com.lambda.context.SafeContext -import com.lambda.event.events.LocalPlayerEvent +import com.lambda.event.events.PlayerEvent import com.lambda.event.listener.SafeListener.Companion.listener import com.lambda.interaction.rotation.Rotation import com.lambda.interaction.rotation.Rotation.Companion.rotationTo @@ -47,7 +47,7 @@ object Criticals : Module( } init { - listener { + listener { when (mode) { Mode.Grim -> { if (player.isOnGround) posPacket(0.00000001, rotation = player.rotation) diff --git a/common/src/main/kotlin/com/lambda/module/modules/movement/ElytraFly.kt b/common/src/main/kotlin/com/lambda/module/modules/movement/ElytraFly.kt index 7b6c1b624..7f569dba3 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/movement/ElytraFly.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/movement/ElytraFly.kt @@ -45,7 +45,7 @@ object ElytraFly : Module( val doBoost: Boolean get() = isEnabled && rocketBoost init { - listener { + listener { if (playerBoost && player.isFallFlying && !player.isUsingItem) { addSpeed(playerSpeed) } diff --git a/common/src/main/kotlin/com/lambda/module/modules/movement/Jesus.kt b/common/src/main/kotlin/com/lambda/module/modules/movement/Jesus.kt index 482e4ade1..55855284f 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/movement/Jesus.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/movement/Jesus.kt @@ -82,7 +82,7 @@ object Jesus : Module( } } - listener { + listener { if (!shouldWork) return@listener goUp = waterAt(0.0001) diff --git a/common/src/main/kotlin/com/lambda/module/modules/movement/NoFall.kt b/common/src/main/kotlin/com/lambda/module/modules/movement/NoFall.kt index ecc437c17..5564b16f1 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/movement/NoFall.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/movement/NoFall.kt @@ -46,7 +46,7 @@ object NoFall : Module( } init { - listener { + listener { when (mode) { Mode.Grim -> { if (player.fallDistance + player.motionY < 3.0) return@listener diff --git a/common/src/main/kotlin/com/lambda/module/modules/movement/Speed.kt b/common/src/main/kotlin/com/lambda/module/modules/movement/Speed.kt index 0ae32e455..505712202 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/movement/Speed.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/movement/Speed.kt @@ -97,7 +97,7 @@ object Speed : Module( } init { - listener { + listener { if (!shouldWork()) { reset() return@listener @@ -109,7 +109,7 @@ object Speed : Module( } } - listener { + listener { lastDistance = player.moveDelta } diff --git a/common/src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt b/common/src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt index a7a137827..675dad2bf 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt @@ -104,7 +104,7 @@ object FastBreak : Module( interaction.blockBreakingCooldown = interaction.blockBreakingCooldown.coerceAtMost(breakDelay) } - listener { + listener { it.progress += world.getBlockState(it.pos) .calcBlockBreakingDelta(player, world, it.pos) * (1 - breakThreshold) } diff --git a/common/src/main/kotlin/com/lambda/module/modules/player/Freecam.kt b/common/src/main/kotlin/com/lambda/module/modules/player/Freecam.kt index 3fdf23715..0fbf99fcd 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/player/Freecam.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/player/Freecam.kt @@ -102,7 +102,7 @@ object Freecam : Module( event.context = RotationContext(rotation, rotationConfig) } - listener { + listener { rotation = rotation.withDelta( it.deltaYaw * SENSITIVITY_FACTOR, it.deltaPitch * SENSITIVITY_FACTOR diff --git a/common/src/main/kotlin/com/lambda/module/modules/player/InventoryTweaks.kt b/common/src/main/kotlin/com/lambda/module/modules/player/InventoryTweaks.kt index 73fe50999..79289762f 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/player/InventoryTweaks.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/player/InventoryTweaks.kt @@ -18,7 +18,7 @@ package com.lambda.module.modules.player import com.lambda.context.SafeContext -import com.lambda.event.events.LocalPlayerEvent +import com.lambda.event.events.PlayerEvent import com.lambda.event.events.ScreenHandlerEvent import com.lambda.event.listener.SafeListener.Companion.listener import com.lambda.module.Module @@ -50,7 +50,7 @@ object InventoryTweaks : Module( private var lastOpenScreen: ScreenHandler? = null init { - listener { + listener { if (it.action != SlotActionType.PICKUP || it.button != 1) return@listener val stack = it.screenHandler.getSlot(it.slot).stack if (!(instantShulker && stack.item in shulkerBoxes) && !(instantEChest && stack.item == Items.ENDER_CHEST)) return@listener diff --git a/common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt b/common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt index 5d2c1a592..4b9acc6ac 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt @@ -273,11 +273,11 @@ object PacketMine : Module( private var doubleBreakReturnSlot = 0 init { - listener { + listener { swingingNextAttack = false } - listener { + listener { it.cancel() if (swingOnManual) swingMainHand() @@ -332,7 +332,7 @@ object PacketMine : Module( startBreaking(it.pos) } - listener { + listener { if (!cancelNextSwing) return@listener cancelNextSwing = false diff --git a/common/src/main/kotlin/com/lambda/module/modules/player/Replay.kt b/common/src/main/kotlin/com/lambda/module/modules/player/Replay.kt index 0675158cf..6d8c94dff 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/player/Replay.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/player/Replay.kt @@ -190,7 +190,7 @@ object Replay : Module( } } - listener { + listener { when (state) { State.RECORDING -> { buffer?.let { diff --git a/common/src/main/kotlin/com/lambda/module/modules/render/Particles.kt b/common/src/main/kotlin/com/lambda/module/modules/render/Particles.kt index eac043bd9..10c552e38 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/render/Particles.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/render/Particles.kt @@ -19,7 +19,7 @@ package com.lambda.module.modules.render import com.lambda.Lambda.mc import com.lambda.context.SafeContext -import com.lambda.event.events.LocalPlayerEvent +import com.lambda.event.events.PlayerEvent import com.lambda.event.events.MovementEvent import com.lambda.event.events.RenderEvent import com.lambda.event.events.TickEvent @@ -102,11 +102,11 @@ object Particles : Module( } } - listener { event -> + listener { event -> spawnForEntity(event.entity) } - listener { + listener { if (!onMove || player.moveDelta < 0.05) return@listener spawnForEntity(player) } diff --git a/common/src/main/kotlin/com/lambda/util/Mouse.kt b/common/src/main/kotlin/com/lambda/util/Mouse.kt index fe7782123..17f550a51 100644 --- a/common/src/main/kotlin/com/lambda/util/Mouse.kt +++ b/common/src/main/kotlin/com/lambda/util/Mouse.kt @@ -24,7 +24,12 @@ class Mouse { enum class Button(val key: Int) { Left(GLFW.GLFW_MOUSE_BUTTON_LEFT), Right(GLFW.GLFW_MOUSE_BUTTON_RIGHT), - Middle(GLFW.GLFW_MOUSE_BUTTON_MIDDLE); + Middle(GLFW.GLFW_MOUSE_BUTTON_MIDDLE), + Button4(GLFW.GLFW_MOUSE_BUTTON_4), + Button5(GLFW.GLFW_MOUSE_BUTTON_5), + Button6(GLFW.GLFW_MOUSE_BUTTON_6), + Button7(GLFW.GLFW_MOUSE_BUTTON_7), + Button8(GLFW.GLFW_MOUSE_BUTTON_8); val isMainButton get() = key == GLFW.GLFW_MOUSE_BUTTON_LEFT || key == GLFW.GLFW_MOUSE_BUTTON_RIGHT From d2cc286b242044252107c192b9e177074851187b Mon Sep 17 00:00:00 2001 From: Constructor Date: Wed, 27 Nov 2024 03:23:51 +0100 Subject: [PATCH 5/5] Fix usages --- .../com/lambda/interaction/material/ContainerManager.kt | 2 +- .../main/kotlin/com/lambda/module/modules/combat/Criticals.kt | 2 +- .../main/kotlin/com/lambda/module/modules/player/FastBreak.kt | 2 +- .../kotlin/com/lambda/module/modules/player/PacketMine.kt | 4 ++-- .../main/kotlin/com/lambda/module/modules/render/Particles.kt | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/common/src/main/kotlin/com/lambda/interaction/material/ContainerManager.kt b/common/src/main/kotlin/com/lambda/interaction/material/ContainerManager.kt index d2b645e7c..36eee4183 100644 --- a/common/src/main/kotlin/com/lambda/interaction/material/ContainerManager.kt +++ b/common/src/main/kotlin/com/lambda/interaction/material/ContainerManager.kt @@ -51,7 +51,7 @@ object ContainerManager : Loadable { private var lastInteractedBlockEntity: BlockEntity? = null init { - listener { + listener { lastInteractedBlockEntity = it.blockHitResult.blockPos.blockEntity(world) } diff --git a/common/src/main/kotlin/com/lambda/module/modules/combat/Criticals.kt b/common/src/main/kotlin/com/lambda/module/modules/combat/Criticals.kt index 3c5c52ac3..311aafb3d 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/combat/Criticals.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/combat/Criticals.kt @@ -47,7 +47,7 @@ object Criticals : Module( } init { - listener { + listener { when (mode) { Mode.Grim -> { if (player.isOnGround) posPacket(0.00000001, rotation = player.rotation) diff --git a/common/src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt b/common/src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt index 675dad2bf..01b906c1d 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/player/FastBreak.kt @@ -104,7 +104,7 @@ object FastBreak : Module( interaction.blockBreakingCooldown = interaction.blockBreakingCooldown.coerceAtMost(breakDelay) } - listener { + listener { it.progress += world.getBlockState(it.pos) .calcBlockBreakingDelta(player, world, it.pos) * (1 - breakThreshold) } diff --git a/common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt b/common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt index 4b9acc6ac..d7ef60656 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/player/PacketMine.kt @@ -273,11 +273,11 @@ object PacketMine : Module( private var doubleBreakReturnSlot = 0 init { - listener { + listener { swingingNextAttack = false } - listener { + listener { it.cancel() if (swingOnManual) swingMainHand() diff --git a/common/src/main/kotlin/com/lambda/module/modules/render/Particles.kt b/common/src/main/kotlin/com/lambda/module/modules/render/Particles.kt index 10c552e38..e42fd2325 100644 --- a/common/src/main/kotlin/com/lambda/module/modules/render/Particles.kt +++ b/common/src/main/kotlin/com/lambda/module/modules/render/Particles.kt @@ -102,7 +102,7 @@ object Particles : Module( } } - listener { event -> + listener { event -> spawnForEntity(event.entity) }