| 1 | package net.minecraft.network.protocol.game;
|
| 2 |
|
| 3 | import net.minecraft.network.FriendlyByteBuf;
|
| 4 | import net.minecraft.network.codec.StreamCodec;
|
| 5 | import net.minecraft.network.protocol.Packet;
|
| 6 | import net.minecraft.network.protocol.PacketType;
|
| 7 | import net.minecraft.world.entity.vehicle.minecart.MinecartCommandBlock;
|
| 8 | import net.minecraft.world.level.BaseCommandBlock;
|
| 9 | import net.minecraft.world.level.Level;
|
| 10 | import org.jspecify.annotations.Nullable;
|
| 11 |
|
| 12 | public class ServerboundSetCommandMinecartPacket implements Packet<ServerGamePacketListener> {
|
| 13 | public static final StreamCodec<FriendlyByteBuf, ServerboundSetCommandMinecartPacket> STREAM_CODEC = Packet.codec(
|
| 14 | ServerboundSetCommandMinecartPacket::write, ServerboundSetCommandMinecartPacket::new
|
| 15 | );
|
| 16 | private final int entity;
|
| 17 | private final String command;
|
| 18 | private final boolean trackOutput;
|
| 19 |
|
| 20 | public ServerboundSetCommandMinecartPacket(final int entity, final String command, final boolean trackOutput) {
|
| 21 | this.entity = entity;
|
| 22 | this.command = command;
|
| 23 | this.trackOutput = trackOutput;
|
| 24 | }
|
| 25 |
|
| 26 | private ServerboundSetCommandMinecartPacket(final FriendlyByteBuf input) {
|
| 27 | this.entity = input.readVarInt();
|
| 28 | this.command = input.readUtf();
|
| 29 | this.trackOutput = input.readBoolean();
|
| 30 | }
|
| 31 |
|
| 32 | private void write(final FriendlyByteBuf output) {
|
| 33 | output.writeVarInt(this.entity);
|
| 34 | output.writeUtf(this.command);
|
| 35 | output.writeBoolean(this.trackOutput);
|
| 36 | }
|
| 37 |
|
| 38 | @Override
|
| 39 | public PacketType<ServerboundSetCommandMinecartPacket> type() {
|
| 40 | return GamePacketTypes.SERVERBOUND_SET_COMMAND_MINECART;
|
| 41 | }
|
| 42 |
|
| 43 | public void handle(final ServerGamePacketListener listener) {
|
| 44 | listener.handleSetCommandMinecart(this);
|
| 45 | }
|
| 46 |
|
| 47 | public @Nullable BaseCommandBlock getCommandBlock(final Level level) {
|
| 48 | return level.getEntity(this.entity) instanceof MinecartCommandBlock minecartCommandBlock ? minecartCommandBlock.getCommandBlock() : null;
|
| 49 | }
|
| 50 |
|
| 51 | public String getCommand() {
|
| 52 | return this.command;
|
| 53 | }
|
| 54 |
|
| 55 | public boolean isTrackOutput() {
|
| 56 | return this.trackOutput;
|
| 57 | }
|
| 58 | }
|
| 59 |
|