Skip to content

Commit 9b1e89e

Browse files
authored
Merge pull request #558 from rfresh2/packetcommand
Additional packets support for command: `;packet`
2 parents d49d568 + 0aeceb7 commit 9b1e89e

File tree

4 files changed

+95
-15
lines changed

4 files changed

+95
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.lambda.mixin.accessor.network;
2+
3+
import net.minecraft.network.play.client.CPacketVehicleMove;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
import org.spongepowered.asm.mixin.gen.Accessor;
6+
7+
@Mixin(value = CPacketVehicleMove.class)
8+
public interface AccessorCPacketVehicleMove {
9+
@Accessor(value = "x")
10+
void setX(double x);
11+
12+
@Accessor(value = "y")
13+
void setY(double y);
14+
15+
@Accessor(value = "z")
16+
void setZ(double z);
17+
18+
@Accessor(value = "yaw")
19+
void setYaw(float yaw);
20+
21+
@Accessor(value = "pitch")
22+
void setPitch(float pitch);
23+
}

src/main/kotlin/com/lambda/client/command/commands/PacketCommand.kt

+61-11
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ package com.lambda.client.command.commands
22

33
import com.lambda.client.command.ClientCommand
44
import com.lambda.client.event.SafeClientEvent
5+
import com.lambda.client.mixin.extension.setValues
6+
import com.lambda.client.mixin.extension.useEntityAction
57
import com.lambda.client.mixin.extension.useEntityId
68
import com.lambda.client.util.items.clickSlotUnsynced
79
import com.lambda.client.util.text.MessageSendHelper
10+
import io.netty.buffer.Unpooled
811
import net.minecraft.entity.passive.EntityDonkey
912
import net.minecraft.entity.player.EntityPlayer
1013
import net.minecraft.inventory.ClickType
1114
import net.minecraft.item.ItemStack
15+
import net.minecraft.item.crafting.CraftingManager
1216
import net.minecraft.network.Packet
17+
import net.minecraft.network.PacketBuffer
1318
import net.minecraft.network.play.client.*
1419
import net.minecraft.util.EnumFacing
1520
import net.minecraft.util.EnumHand
@@ -20,7 +25,7 @@ import net.minecraft.util.text.TextFormatting
2025

2126
object PacketCommand : ClientCommand(
2227
name = "packet",
23-
description = "Send any packet you want"
28+
description = "Send (almost) any packet you want"
2429
) {
2530
init {
2631
literal("Animation") {
@@ -89,8 +94,13 @@ object PacketCommand : ClientCommand(
8994
}
9095

9196
literal("ClientStatus") {
92-
executeSafe {
93-
MessageSendHelper.sendChatMessage("Not yet implemented. Consider to make a pull request.")
97+
enum<CPacketClientStatus.State>("state") { state ->
98+
executeSafe {
99+
deployPacket(
100+
CPacketClientStatus(state.value),
101+
"${state.value}"
102+
)
103+
}
94104
}
95105
}
96106

@@ -144,8 +154,20 @@ object PacketCommand : ClientCommand(
144154
}
145155

146156
literal("CustomPayload") {
147-
executeSafe {
148-
MessageSendHelper.sendChatMessage("Not yet implemented. Consider to make a pull request.")
157+
string("channel") { channel ->
158+
// todo: technically we need to be able to send more data types to fully utilize this packet, but I'm too lazy to implement it and it doesn't fit in well with commands
159+
string("stringData") { data ->
160+
executeSafe {
161+
PacketBuffer(Unpooled.buffer())
162+
.apply { writeString(data.value) }
163+
.also {
164+
deployPacket(
165+
CPacketCustomPayload(channel.value, it),
166+
"${channel.value} ${data.value}"
167+
)
168+
}
169+
}
170+
}
149171
}
150172
}
151173

@@ -215,8 +237,22 @@ object PacketCommand : ClientCommand(
215237
}
216238

217239
literal("PlaceRecipe") {
218-
executeSafe {
219-
MessageSendHelper.sendChatMessage("Not yet implemented. Consider to make a pull request.")
240+
int("windowId") { windowId ->
241+
string("recipe") { recipe ->
242+
boolean("makeAll") { makeAll ->
243+
executeSafe {
244+
CraftingManager.REGISTRY.keys
245+
.find { it.toString() == recipe.value }?.let {
246+
CraftingManager.REGISTRY.getObject(it)?.let { iRecipe ->
247+
deployPacket(
248+
CPacketPlaceRecipe(windowId.value, iRecipe, makeAll.value),
249+
"${windowId.value} ${recipe.value} ${makeAll.value}"
250+
)
251+
}
252+
}
253+
}
254+
}
255+
}
220256
}
221257
}
222258

@@ -412,6 +448,7 @@ object PacketCommand : ClientCommand(
412448
executeSafe {
413449
val packet = CPacketUseEntity()
414450
packet.useEntityId = id.value
451+
packet.useEntityAction = CPacketUseEntity.Action.ATTACK
415452

416453
deployPacket(
417454
packet,
@@ -459,16 +496,29 @@ object PacketCommand : ClientCommand(
459496
}
460497
}
461498
}
462-
463499
literal("VehicleMove") {
464-
executeSafe {
465-
MessageSendHelper.sendChatMessage("Not yet implemented. Consider to make a pull request.")
500+
double("x") { x ->
501+
double("y") { y ->
502+
double("z") { z ->
503+
float("yaw") { yaw ->
504+
float("pitch") { pitch ->
505+
executeSafe {
506+
deployPacket(
507+
CPacketVehicleMove().setValues(x.value, y.value, z.value, yaw.value, pitch.value),
508+
"${x.value} ${y.value} ${z.value} ${yaw.value} ${pitch.value}"
509+
)
510+
}
511+
}
512+
}
513+
}
514+
}
466515
}
467516
}
468517
}
469518

470519
private fun SafeClientEvent.deployPacket(packet: Packet<*>, info: String) {
471-
connection.sendPacket(packet)
520+
// bypasses packet cancel :trollepic:
521+
connection.networkManager.sendPacket(packet, null)
472522
MessageSendHelper.sendChatMessage("Sent ${TextFormatting.GRAY}${packet.javaClass.name.split(".").lastOrNull()}${TextFormatting.DARK_RED} > ${TextFormatting.GRAY}$info")
473523
}
474524
}

src/main/kotlin/com/lambda/client/mixin/extension/Network.kt

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package com.lambda.client.mixin.extension
22

33
import com.lambda.mixin.accessor.network.*
4-
import net.minecraft.network.play.client.CPacketChatMessage
5-
import net.minecraft.network.play.client.CPacketCloseWindow
6-
import net.minecraft.network.play.client.CPacketPlayer
7-
import net.minecraft.network.play.client.CPacketUseEntity
4+
import net.minecraft.network.play.client.*
85
import net.minecraft.network.play.server.*
96
import net.minecraft.util.text.ITextComponent
107

@@ -78,6 +75,15 @@ var CPacketUseEntity.useEntityAction: CPacketUseEntity.Action
7875
(this as AccessorCPacketUseEntity).setAction(value)
7976
}
8077

78+
fun CPacketVehicleMove.setValues(x: Double, y: Double, z: Double, yaw: Float, pitch: Float): CPacketVehicleMove {
79+
(this as AccessorCPacketVehicleMove).setX(x)
80+
(this as AccessorCPacketVehicleMove).setY(y)
81+
(this as AccessorCPacketVehicleMove).setZ(z)
82+
(this as AccessorCPacketVehicleMove).setYaw(yaw)
83+
(this as AccessorCPacketVehicleMove).setPitch(pitch)
84+
return this
85+
}
86+
8187
var SPacketChat.textComponent: ITextComponent
8288
get() = this.chatComponent
8389
set(value) {

src/main/resources/mixins.lambda.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"accessor.network.AccessorCPacketCloseWindow",
2424
"accessor.network.AccessorCPacketPlayer",
2525
"accessor.network.AccessorCPacketUseEntity",
26+
"accessor.network.AccessorCPacketVehicleMove",
2627
"accessor.network.AccessorSPacketChat",
2728
"accessor.network.AccessorSPacketEntity",
2829
"accessor.network.AccessorSPacketEntityHeadLook",

0 commit comments

Comments
 (0)