From b8ef72e273b84c7e3c38b41d51779bd603a7be3a Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 7 Jan 2022 06:41:42 +0100 Subject: [PATCH 1/3] Add packet command --- .../client/command/commands/PacketCommand.kt | 473 ++++++++++++++++++ 1 file changed, 473 insertions(+) create mode 100644 src/main/kotlin/com/lambda/client/command/commands/PacketCommand.kt diff --git a/src/main/kotlin/com/lambda/client/command/commands/PacketCommand.kt b/src/main/kotlin/com/lambda/client/command/commands/PacketCommand.kt new file mode 100644 index 000000000..a57beb400 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/command/commands/PacketCommand.kt @@ -0,0 +1,473 @@ +package com.lambda.client.command.commands + +import com.lambda.client.command.ClientCommand +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.mixin.extension.id +import com.lambda.client.util.text.MessageSendHelper +import net.minecraft.entity.passive.EntityDonkey +import net.minecraft.inventory.ClickType +import net.minecraft.item.ItemStack +import net.minecraft.network.Packet +import net.minecraft.network.play.client.* +import net.minecraft.util.EnumFacing +import net.minecraft.util.EnumHand +import net.minecraft.util.math.Vec3d +import net.minecraft.util.text.TextComponentString +import net.minecraft.util.text.TextFormatting + +object PacketCommand : ClientCommand( + name = "packet", + description = "Send any packet you want" +) { + init { + literal("Animation") { + enum("hand") { hand -> + executeSafe { + deployPacket( + CPacketAnimation(hand.value), + "${hand.value}" + ) + } + } + } + + literal("ChatMessage") { + string("message") { message -> + executeSafe { + deployPacket( + CPacketChatMessage(message.value), + message.value + ) + } + } + } + + literal("ClickWindow") { + int("windowId") { windowId -> + int("slotId") { slotId -> + int("packedClickData") { packedClickData -> + enum("mode") { mode -> + short("actionNumber") { actionNumber -> + executeSafe { + // ToDo: Dynamic ItemStack + deployPacket( + CPacketClickWindow(windowId.value, + slotId.value, + packedClickData.value, + mode.value, + ItemStack.EMPTY, + actionNumber.value + ), + "${windowId.value} ${slotId.value} ${packedClickData.value} ${mode.value} ${ItemStack.EMPTY} ${actionNumber.value}" + ) + } + } + } + } + } + } + } + + literal("ClientSettings") { + executeSafe { + MessageSendHelper.sendChatMessage("To be implemented") + } + } + + literal("ClientStatus") { + executeSafe { + MessageSendHelper.sendChatMessage("To be implemented") + } + } + + literal("CloseWindow") { + int("windowId") { windowId -> + executeSafe { + deployPacket( + CPacketCloseWindow(windowId.value), + "${windowId.value}" + ) + } + } + } + + literal("ConfirmTeleport") { + int("teleportId") { teleportId -> + executeSafe { + deployPacket( + CPacketConfirmTeleport(teleportId.value), + "${teleportId.value}" + ) + } + } + } + + literal("ConfirmTransaction") { + int("windowId") { windowId -> + short("uid") { uid -> + boolean("accepted") { accepted -> + executeSafe { + deployPacket( + CPacketConfirmTransaction(windowId.value, uid.value, accepted.value), + "${windowId.value} ${uid.value} ${accepted.value}" + ) + } + } + } + } + } + + literal("CreativeInventoryAction") { + int("slotId") { slotId -> + executeSafe { + // ToDo: Dynamic ItemStack + deployPacket( + CPacketCreativeInventoryAction(slotId.value, ItemStack.EMPTY), + "${slotId.value} ${ItemStack.EMPTY}" + ) + } + } + } + + literal("CustomPayload") { + executeSafe { + MessageSendHelper.sendChatMessage("To be implemented") + } + } + + literal("EnchantItem") { + int("windowId") { windowId -> + int("button") { button -> + executeSafe { + deployPacket( + CPacketEnchantItem(windowId.value, button.value), + "${windowId.value} ${button.value}" + ) + } + } + } + } + + literal("EntityAction") { + enum("action") { action -> + int("auxData") { auxData -> + executeSafe { + deployPacket( + CPacketEntityAction(player, action.value, auxData.value), + "${player.entityId} ${action.value} ${auxData.value}" + ) + } + } + } + } + + literal("HeldItemChange") { + int("slotId") { slotId -> + executeSafe { + deployPacket( + CPacketHeldItemChange(slotId.value), + "${slotId.value}" + ) + } + } + } + + literal("Input") { + float("strafeSpeed") { strafeSpeed -> + float("forwardSpeed") { forwardSpeed -> + boolean("jumping") { jumping -> + boolean("sneaking") { sneaking -> + executeSafe { + deployPacket( + CPacketInput(strafeSpeed.value, forwardSpeed.value, jumping.value, sneaking.value), + "${strafeSpeed.value} ${forwardSpeed.value} ${jumping.value} ${sneaking.value}" + ) + } + } + } + } + } + } + + literal("KeepAlive") { + long("key") { key -> + executeSafe { + deployPacket( + CPacketKeepAlive(key.value), + "${key.value}" + ) + } + } + } + + literal("PlaceRecipe") { + executeSafe { + MessageSendHelper.sendChatMessage("To be implemented") + } + } + + literal("PlayerPosition") { + double("x") { x -> + double("y") { y -> + double("z") { z -> + boolean("onGround") { onGround -> + executeSafe { + deployPacket( + CPacketPlayer.Position(x.value, y.value, z.value, onGround.value), + "${x.value} ${y.value} ${z.value} ${onGround.value}" + ) + } + } + } + } + } + } + + literal("PlayerPositionRotation") { + double("x") { x -> + double("y") { y -> + double("z") { z -> + float("yaw") { yaw -> + float("pitch") { pitch -> + boolean("onGround") { onGround -> + executeSafe { + deployPacket( + CPacketPlayer.PositionRotation(x.value, y.value, z.value, yaw.value, pitch.value, onGround.value), + "${x.value} ${y.value} ${z.value} ${yaw.value} ${pitch.value} ${onGround.value}" + ) + } + } + } + } + } + } + } + } + + literal("PlayerRotation") { + float("yaw") { yaw -> + float("pitch") { pitch -> + boolean("onGround") { onGround -> + executeSafe { + deployPacket( + CPacketPlayer.Rotation(yaw.value, pitch.value, onGround.value), + "${yaw.value} ${pitch.value} ${onGround.value}" + ) + } + } + } + } + } + + literal("PlayerAbilities") { + executeSafe { + MessageSendHelper.sendChatMessage("To be implemented") + } + } + + literal("PlayerDigging") { + enum("action") { action -> + blockPos("position") { position -> + enum("facing") { facing -> + executeSafe { + deployPacket( + CPacketPlayerDigging(action.value, position.value, facing.value), + "${action.value} ${position.value} ${facing.value}" + ) + } + } + } + } + } + + literal("PlayerTryUseItem") { + enum("hand") { hand -> + executeSafe { + deployPacket( + CPacketPlayerTryUseItem(hand.value), + "${hand.value}" + ) + } + } + } + + literal("PlayerTryUseItemOnBlock") { + blockPos("position") { position -> + enum("placedBlockDirection") { placedBlockDirection -> + enum("hand") { hand -> + float("facingX") { facingX -> + float("facingY") { facingY -> + float("facingZ") { facingZ -> + executeSafe { + deployPacket( + CPacketPlayerTryUseItemOnBlock(position.value, placedBlockDirection.value, hand.value, facingX.value, facingY.value, facingZ.value), + "${position.value} ${placedBlockDirection.value} ${hand.value} ${facingX.value} ${facingY.value} ${facingZ.value}" + ) + } + } + } + } + } + } + } + } + + literal("RecipeInfo") { + executeSafe { + MessageSendHelper.sendChatMessage("To be implemented") + } + } + + literal("ResourcePackStatus") { + enum("action") { action -> + executeSafe { + deployPacket( + CPacketResourcePackStatus(action.value), + "${action.value}" + ) + } + } + } + + literal("SeenAdvancements") { + executeSafe { + MessageSendHelper.sendChatMessage("To be implemented") + } + } + + literal("Spectate") { + executeSafe { + MessageSendHelper.sendChatMessage("To be implemented") + } + } + + literal("SteerBoat") { + boolean("left") { left -> + boolean("right") { right -> + executeSafe { + deployPacket( + CPacketSteerBoat(left.value, right.value), + "${left.value} ${right.value}" + ) + } + } + } + } + + literal("TabComplete") { + string("message") { message -> + blockPos("targetBlock") { targetBlock -> + boolean("hasTargetBlock") { hasTargetBlock -> + executeSafe { + deployPacket( + CPacketTabComplete(message.value, targetBlock.value, hasTargetBlock.value), + "${message.value} ${targetBlock.value} ${hasTargetBlock.value}" + ) + } + } + } + } + } + + literal("UpdateSign") { + blockPos("position") { position -> + string("line1") { line1 -> + string("line2") { line2 -> + string("line3") { line3 -> + string("line4") { line4 -> + executeSafe { + val lines = listOf(TextComponentString(line1.value), + TextComponentString(line2.value), + TextComponentString(line3.value), + TextComponentString(line4.value)) + + deployPacket( + CPacketUpdateSign(position.value, lines.toTypedArray()), + "${line1.value} ${line2.value} ${line3.value} ${line4.value}" + ) + } + } + } + } + } + } + } + + literal("UseEntityAttack") { + int("ID") { id -> + executeSafe { + val packet = CPacketUseEntity() + packet.id = id.value + + deployPacket( + packet, + "${id.value}" + ) + } + } + } + + literal("UseEntityInteract") { + enum("hand") { hand -> + int("ID") { id -> + executeSafe { + val entity = EntityDonkey(world) + entity.entityId = id.value + + deployPacket( + CPacketUseEntity(entity, hand.value), + "${id.value} ${hand.value}" + ) + } + } + } + } + + literal("UseEntityInteractAt") { + enum("hand") { hand -> + double("x") { x -> + double("y") { y -> + double("z") { z -> + int("ID") { id -> + executeSafe { + val entity = EntityDonkey(world) + entity.entityId = id.value + val vec = Vec3d(x.value, y.value, z.value) + + deployPacket( + CPacketUseEntity(entity, hand.value, vec), + "${id.value} ${hand.value} $vec" + ) + } + } + } + } + } + } + } + + literal("VehicleMove") { + double("x") { x -> + double("y") { y -> + double("z") { z -> + float("yaw") { yaw -> + float("pitch") { pitch -> + executeSafe { + deployPacket( + CPacketVehicleMove(player), + "${player.entityId}" + ) + } + } + } + } + } + } + } + } + + private fun SafeClientEvent.deployPacket(packet: Packet<*>, info: String) { + connection.sendPacket(packet) + MessageSendHelper.sendChatMessage("Sent ${TextFormatting.GRAY}${packet.javaClass.name.split(".").lastOrNull()}${TextFormatting.DARK_RED} > ${TextFormatting.GRAY}$info") + } +} \ No newline at end of file From 16a6f1890d245fc8d47e55ecd5b121389146d6ef Mon Sep 17 00:00:00 2001 From: Constructor Date: Wed, 2 Feb 2022 05:42:34 +0100 Subject: [PATCH 2/3] Fix synthetic reference --- .../com/lambda/client/command/commands/PacketCommand.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/command/commands/PacketCommand.kt b/src/main/kotlin/com/lambda/client/command/commands/PacketCommand.kt index a57beb400..991a554a2 100644 --- a/src/main/kotlin/com/lambda/client/command/commands/PacketCommand.kt +++ b/src/main/kotlin/com/lambda/client/command/commands/PacketCommand.kt @@ -2,7 +2,7 @@ package com.lambda.client.command.commands import com.lambda.client.command.ClientCommand import com.lambda.client.event.SafeClientEvent -import com.lambda.client.mixin.extension.id +import com.lambda.client.mixin.extension.useEntityId import com.lambda.client.util.text.MessageSendHelper import net.minecraft.entity.passive.EntityDonkey import net.minecraft.inventory.ClickType @@ -397,7 +397,7 @@ object PacketCommand : ClientCommand( int("ID") { id -> executeSafe { val packet = CPacketUseEntity() - packet.id = id.value + packet.useEntityId = id.value deployPacket( packet, From 40f0d6bcca70408ddf73d1925043178b71589625 Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 21 Feb 2022 03:23:20 +0100 Subject: [PATCH 3/3] Small supplement --- .../client/command/commands/PacketCommand.kt | 81 ++++++++++--------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/command/commands/PacketCommand.kt b/src/main/kotlin/com/lambda/client/command/commands/PacketCommand.kt index 991a554a2..5e791fc27 100644 --- a/src/main/kotlin/com/lambda/client/command/commands/PacketCommand.kt +++ b/src/main/kotlin/com/lambda/client/command/commands/PacketCommand.kt @@ -3,14 +3,17 @@ package com.lambda.client.command.commands import com.lambda.client.command.ClientCommand import com.lambda.client.event.SafeClientEvent import com.lambda.client.mixin.extension.useEntityId +import com.lambda.client.util.items.clickSlot import com.lambda.client.util.text.MessageSendHelper import net.minecraft.entity.passive.EntityDonkey +import net.minecraft.entity.player.EntityPlayer import net.minecraft.inventory.ClickType import net.minecraft.item.ItemStack import net.minecraft.network.Packet import net.minecraft.network.play.client.* import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand +import net.minecraft.util.EnumHandSide import net.minecraft.util.math.Vec3d import net.minecraft.util.text.TextComponentString import net.minecraft.util.text.TextFormatting @@ -45,22 +48,11 @@ object PacketCommand : ClientCommand( literal("ClickWindow") { int("windowId") { windowId -> int("slotId") { slotId -> - int("packedClickData") { packedClickData -> - enum("mode") { mode -> - short("actionNumber") { actionNumber -> - executeSafe { - // ToDo: Dynamic ItemStack - deployPacket( - CPacketClickWindow(windowId.value, - slotId.value, - packedClickData.value, - mode.value, - ItemStack.EMPTY, - actionNumber.value - ), - "${windowId.value} ${slotId.value} ${packedClickData.value} ${mode.value} ${ItemStack.EMPTY} ${actionNumber.value}" - ) - } + int("buttonId") { buttonId -> + enum("clickType") { clickType -> + executeSafe { + clickSlot(windowId.value, slotId.value, buttonId.value, clickType.value) + MessageSendHelper.sendChatMessage("Sent ${TextFormatting.GRAY}CPacketClickWindow${TextFormatting.DARK_RED} > ${TextFormatting.GRAY}windowId: ${windowId.value}, slotId: ${slotId.value}, buttonId: ${buttonId.value}, clickType: ${clickType.value}") } } } @@ -69,14 +61,36 @@ object PacketCommand : ClientCommand( } literal("ClientSettings") { - executeSafe { - MessageSendHelper.sendChatMessage("To be implemented") + string("lang") { lang -> + int ("renderDistanceIn") { renderDistanceIn -> + enum("chatVisibilityIn") { chatVisibilityIn -> + boolean("chatColorsIn") { chatColorsIn -> + int("modelPartsIn") { modelPartsIn -> + enum("mainHandIn") { mainHandIn -> + executeSafe { + deployPacket( + CPacketClientSettings( + lang.value, + renderDistanceIn.value, + chatVisibilityIn.value, + chatColorsIn.value, + modelPartsIn.value, + mainHandIn.value + ), + "${lang.value} ${renderDistanceIn.value} ${chatVisibilityIn.value} ${chatColorsIn.value} ${modelPartsIn.value} ${mainHandIn.value}" + ) + } + } + } + } + } + } } } literal("ClientStatus") { executeSafe { - MessageSendHelper.sendChatMessage("To be implemented") + MessageSendHelper.sendChatMessage("Not yet implemented. Consider to make a pull request.") } } @@ -131,7 +145,7 @@ object PacketCommand : ClientCommand( literal("CustomPayload") { executeSafe { - MessageSendHelper.sendChatMessage("To be implemented") + MessageSendHelper.sendChatMessage("Not yet implemented. Consider to make a pull request.") } } @@ -202,7 +216,7 @@ object PacketCommand : ClientCommand( literal("PlaceRecipe") { executeSafe { - MessageSendHelper.sendChatMessage("To be implemented") + MessageSendHelper.sendChatMessage("Not yet implemented. Consider to make a pull request.") } } @@ -261,7 +275,7 @@ object PacketCommand : ClientCommand( literal("PlayerAbilities") { executeSafe { - MessageSendHelper.sendChatMessage("To be implemented") + MessageSendHelper.sendChatMessage("Not yet implemented. Consider to make a pull request.") } } @@ -314,7 +328,7 @@ object PacketCommand : ClientCommand( literal("RecipeInfo") { executeSafe { - MessageSendHelper.sendChatMessage("To be implemented") + MessageSendHelper.sendChatMessage("Not yet implemented. Consider to make a pull request.") } } @@ -331,13 +345,13 @@ object PacketCommand : ClientCommand( literal("SeenAdvancements") { executeSafe { - MessageSendHelper.sendChatMessage("To be implemented") + MessageSendHelper.sendChatMessage("Not yet implemented. Consider to make a pull request.") } } literal("Spectate") { executeSafe { - MessageSendHelper.sendChatMessage("To be implemented") + MessageSendHelper.sendChatMessage("Not yet implemented. Consider to make a pull request.") } } @@ -447,21 +461,8 @@ object PacketCommand : ClientCommand( } literal("VehicleMove") { - double("x") { x -> - double("y") { y -> - double("z") { z -> - float("yaw") { yaw -> - float("pitch") { pitch -> - executeSafe { - deployPacket( - CPacketVehicleMove(player), - "${player.entityId}" - ) - } - } - } - } - } + executeSafe { + MessageSendHelper.sendChatMessage("Not yet implemented. Consider to make a pull request.") } } }