Skip to content

Commit b59215b

Browse files
committed
Adding packet command scetch
1 parent a31b105 commit b59215b

File tree

1 file changed

+389
-0
lines changed

1 file changed

+389
-0
lines changed
Lines changed: 389 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,389 @@
1+
package com.lambda.client.command.commands
2+
3+
import com.lambda.client.command.ClientCommand
4+
import com.lambda.client.util.text.MessageSendHelper
5+
import net.minecraft.inventory.ClickType
6+
import net.minecraft.item.ItemStack
7+
import net.minecraft.network.play.client.*
8+
import net.minecraft.util.EnumFacing
9+
import net.minecraft.util.EnumHand
10+
import net.minecraft.util.math.Vec3d
11+
import net.minecraft.util.text.TextComponentString
12+
13+
object PacketCommand : ClientCommand(
14+
name = "packet",
15+
description = "Send any packet you want"
16+
) {
17+
init {
18+
literal("Animation") {
19+
enum<EnumHand>("hand") { hand ->
20+
executeSafe {
21+
connection.sendPacket(CPacketAnimation(hand.value))
22+
postSend(this@literal.name,"${hand.value}")
23+
}
24+
}
25+
}
26+
27+
literal("ChatMessage") {
28+
string("message") { message ->
29+
executeSafe {
30+
connection.sendPacket(CPacketChatMessage(message.value))
31+
postSend(this@literal.name, message.value)
32+
}
33+
}
34+
}
35+
36+
literal("ClickWindow") {
37+
int("windowId") { windowId ->
38+
int("slotId") { slotId ->
39+
int("packedClickData") { packedClickData ->
40+
enum<ClickType>("mode") { mode ->
41+
short("actionNumber") { actionNumber ->
42+
executeSafe {
43+
// ToDo: Dynamic ItemStack
44+
connection.sendPacket(CPacketClickWindow(windowId.value,
45+
slotId.value,
46+
packedClickData.value,
47+
mode.value,
48+
ItemStack.EMPTY,
49+
actionNumber.value))
50+
postSend(this@literal.name,"${windowId.value} ${slotId.value} ${packedClickData.value} ${mode.value} ${ItemStack.EMPTY} ${actionNumber.value}")
51+
}
52+
}
53+
}
54+
}
55+
}
56+
}
57+
}
58+
59+
literal("ClientSettings") {
60+
executeSafe {
61+
MessageSendHelper.sendChatMessage("To be implemented")
62+
}
63+
}
64+
65+
literal("ClientStatus") {
66+
executeSafe {
67+
MessageSendHelper.sendChatMessage("To be implemented")
68+
}
69+
}
70+
71+
literal("CloseWindow") {
72+
int("windowId") { windowId ->
73+
executeSafe {
74+
connection.sendPacket(CPacketCloseWindow(windowId.value))
75+
postSend(this@literal.name,"${windowId.value}")
76+
}
77+
}
78+
}
79+
80+
literal("ConfirmTeleport") {
81+
int("teleportId") { teleportId ->
82+
executeSafe {
83+
connection.sendPacket(CPacketConfirmTeleport(teleportId.value))
84+
postSend(this@literal.name,"${teleportId.value}")
85+
}
86+
}
87+
}
88+
89+
literal("ConfirmTransaction") {
90+
int("windowId") { windowId ->
91+
short("uid") { uid ->
92+
boolean("accepted") { accepted ->
93+
executeSafe {
94+
connection.sendPacket(CPacketConfirmTransaction(windowId.value, uid.value, accepted.value))
95+
postSend(this@literal.name,"${windowId.value} ${uid.value} ${accepted.value}")
96+
}
97+
}
98+
}
99+
}
100+
}
101+
102+
literal("CreativeInventoryAction") {
103+
int("slotId") { slotId ->
104+
executeSafe {
105+
// ToDo: Dynamic ItemStack
106+
connection.sendPacket(CPacketCreativeInventoryAction(slotId.value, ItemStack.EMPTY))
107+
postSend(this@literal.name,"${slotId.value} ${ItemStack.EMPTY}")
108+
}
109+
}
110+
}
111+
112+
literal("CustomPayload") {
113+
executeSafe {
114+
MessageSendHelper.sendChatMessage("To be implemented")
115+
}
116+
}
117+
118+
literal("EnchantItem") {
119+
int("windowId") { windowId ->
120+
int("button") { button ->
121+
executeSafe {
122+
connection.sendPacket(CPacketEnchantItem(windowId.value, button.value))
123+
postSend(this@literal.name,"${windowId.value} ${button.value}")
124+
}
125+
}
126+
}
127+
}
128+
129+
literal("EntityAction") {
130+
enum<CPacketEntityAction.Action>("action") { action ->
131+
int("auxData") { auxData ->
132+
executeSafe {
133+
connection.sendPacket(CPacketEntityAction(player, action.value, auxData.value))
134+
postSend(this@literal.name,"${player.entityId} ${action.value} ${auxData.value}")
135+
}
136+
}
137+
}
138+
}
139+
140+
literal("HeldItemChange") {
141+
int("slotId") { slotId ->
142+
executeSafe {
143+
connection.sendPacket(CPacketHeldItemChange(slotId.value))
144+
postSend(this@literal.name,"${slotId.value}")
145+
}
146+
}
147+
}
148+
149+
literal("Input") {
150+
float("strafeSpeed") { strafeSpeed ->
151+
float("forwardSpeed") { forwardSpeed ->
152+
boolean("jumping") { jumping ->
153+
boolean("sneaking") { sneaking ->
154+
executeSafe {
155+
connection.sendPacket(CPacketInput(strafeSpeed.value, forwardSpeed.value, jumping.value, sneaking.value))
156+
postSend(this@literal.name,"${strafeSpeed.value} ${forwardSpeed.value} ${jumping.value} ${sneaking.value}")
157+
}
158+
}
159+
}
160+
}
161+
}
162+
}
163+
164+
literal("KeepAlive") {
165+
long("key") { key ->
166+
executeSafe {
167+
connection.sendPacket(CPacketKeepAlive(key.value))
168+
postSend(this@literal.name,"${key.value}")
169+
}
170+
}
171+
}
172+
173+
literal("PlaceRecipe") {
174+
executeSafe {
175+
MessageSendHelper.sendChatMessage("To be implemented")
176+
}
177+
}
178+
179+
literal("PlayerPosition") {
180+
double("x") { x ->
181+
double("y") { y ->
182+
double("z") { z ->
183+
boolean("onGround") { onGround ->
184+
executeSafe {
185+
connection.sendPacket(CPacketPlayer.Position(x.value, y.value, z.value, onGround.value))
186+
postSend(this@literal.name,"${x.value} ${y.value} ${z.value} ${onGround.value}")
187+
}
188+
}
189+
}
190+
}
191+
}
192+
}
193+
194+
literal("PlayerPositionRotation") {
195+
double("x") { x ->
196+
double("y") { y ->
197+
double("z") { z ->
198+
float("yaw") { yaw ->
199+
float("pitch") { pitch ->
200+
boolean("onGround") { onGround ->
201+
executeSafe {
202+
connection.sendPacket(CPacketPlayer.PositionRotation(x.value, y.value, z.value, yaw.value, pitch.value, onGround.value))
203+
postSend(this@literal.name,"${x.value} ${y.value} ${z.value} ${yaw.value} ${pitch.value} ${onGround.value}")
204+
}
205+
}
206+
}
207+
}
208+
}
209+
}
210+
}
211+
}
212+
213+
literal("PlayerRotation") {
214+
float("yaw") { yaw ->
215+
float("pitch") { pitch ->
216+
boolean("onGround") { onGround ->
217+
executeSafe {
218+
connection.sendPacket(CPacketPlayer.Rotation(yaw.value, pitch.value, onGround.value))
219+
postSend(this@literal.name,"${yaw.value} ${pitch.value} ${onGround.value}")
220+
}
221+
}
222+
}
223+
}
224+
}
225+
226+
literal("PlayerAbilities") {
227+
executeSafe {
228+
MessageSendHelper.sendChatMessage("To be implemented")
229+
}
230+
}
231+
232+
literal("PlayerDigging") {
233+
enum<CPacketPlayerDigging.Action>("action") { action ->
234+
blockPos("position") { position ->
235+
enum<EnumFacing>("facing") { facing ->
236+
executeSafe {
237+
connection.sendPacket(CPacketPlayerDigging(action.value, position.value, facing.value))
238+
postSend(this@literal.name,"${action.value} ${position.value} ${facing.value}")
239+
}
240+
}
241+
}
242+
}
243+
}
244+
245+
literal("PlayerTryUseItem") {
246+
enum<EnumHand>("hand") { hand ->
247+
executeSafe {
248+
connection.sendPacket(CPacketPlayerTryUseItem(hand.value))
249+
postSend(this@literal.name,"${hand.value}")
250+
}
251+
}
252+
}
253+
254+
literal("PlayerTryUseItemOnBlock") {
255+
blockPos("position") { position ->
256+
enum<EnumFacing>("placedBlockDirection") { placedBlockDirection ->
257+
enum<EnumHand>("hand") { hand ->
258+
float("facingX") { facingX ->
259+
float("facingY") { facingY ->
260+
float("facingZ") { facingZ ->
261+
executeSafe {
262+
connection.sendPacket(CPacketPlayerTryUseItemOnBlock(position.value, placedBlockDirection.value, hand.value, facingX.value, facingY.value, facingZ.value))
263+
postSend(this@literal.name,"${position.value} ${placedBlockDirection.value} ${hand.value} ${facingX.value} ${facingY.value} ${facingZ.value}")
264+
}
265+
}
266+
}
267+
}
268+
}
269+
}
270+
}
271+
}
272+
273+
literal("RecipeInfo") {
274+
executeSafe {
275+
MessageSendHelper.sendChatMessage("To be implemented")
276+
}
277+
}
278+
279+
literal("ResourcePackStatus") {
280+
enum<CPacketResourcePackStatus.Action>("action") { action ->
281+
executeSafe {
282+
connection.sendPacket(CPacketResourcePackStatus(action.value))
283+
postSend(this@literal.name,"${action.value}")
284+
}
285+
}
286+
}
287+
288+
literal("SeenAdvancements") {
289+
executeSafe {
290+
MessageSendHelper.sendChatMessage("To be implemented")
291+
}
292+
}
293+
294+
literal("Spectate") {
295+
executeSafe {
296+
MessageSendHelper.sendChatMessage("To be implemented")
297+
}
298+
}
299+
300+
literal("SteerBoat") {
301+
boolean("left") { left ->
302+
boolean("right") { right ->
303+
executeSafe {
304+
connection.sendPacket(CPacketSteerBoat(left.value, right.value))
305+
postSend(this@literal.name,"${left.value} ${right.value}")
306+
}
307+
}
308+
}
309+
}
310+
311+
literal("TabComplete") {
312+
string("message") { message ->
313+
blockPos("targetBlock") { targetBlock ->
314+
boolean("hasTargetBlock") { hasTargetBlock ->
315+
executeSafe {
316+
connection.sendPacket(CPacketTabComplete(message.value, targetBlock.value, hasTargetBlock.value))
317+
postSend(this@literal.name,"${message.value} ${targetBlock.value} ${hasTargetBlock.value}")
318+
}
319+
}
320+
}
321+
}
322+
}
323+
324+
literal("UpdateSign") {
325+
blockPos("position") { position ->
326+
string("line1") { line1 ->
327+
string("line2") { line2 ->
328+
string("line3") { line3 ->
329+
string("line4") { line4 ->
330+
executeSafe {
331+
val lines = listOf(TextComponentString(line1.value),
332+
TextComponentString(line2.value),
333+
TextComponentString(line3.value),
334+
TextComponentString(line4.value))
335+
336+
connection.sendPacket(CPacketUpdateSign(position.value, lines.toTypedArray()))
337+
postSend(this@literal.name,"${line1.value} ${line2.value} ${line3.value} ${line4.value}")
338+
}
339+
}
340+
}
341+
}
342+
}
343+
}
344+
}
345+
346+
literal("UseEntityAttack") {
347+
executeSafe {
348+
connection.sendPacket(CPacketUseEntity(player))
349+
postSend(this@literal.name,"${player.entityId}")
350+
}
351+
}
352+
353+
literal("UseEntityInteract") {
354+
enum<EnumHand>("hand") { hand ->
355+
executeSafe {
356+
connection.sendPacket(CPacketUseEntity(player, hand.value))
357+
postSend(this@literal.name,"${player.entityId} ${hand.value}")
358+
}
359+
}
360+
}
361+
362+
literal("UseEntityInteractAt") {
363+
enum<EnumHand>("hand") { hand ->
364+
double("x") { x ->
365+
double("y") { y ->
366+
double("z") { z ->
367+
executeSafe {
368+
val vec = Vec3d(x.value, y.value, z.value)
369+
connection.sendPacket(CPacketUseEntity(player, hand.value, vec))
370+
postSend(this@literal.name,"${player.entityId} ${hand.value} $vec")
371+
}
372+
}
373+
}
374+
}
375+
}
376+
}
377+
378+
literal("VehicleMove") {
379+
executeSafe {
380+
connection.sendPacket(CPacketVehicleMove(player))
381+
postSend(this@literal.name,"${player.entityId}")
382+
}
383+
}
384+
}
385+
386+
private fun postSend(literal: String, info: String) {
387+
MessageSendHelper.sendChatMessage("Sent CPacket$literal > $info")
388+
}
389+
}

0 commit comments

Comments
 (0)