| 1 | package net.minecraft.network.protocol.game;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.network.FriendlyByteBuf;
|
| 5 | import net.minecraft.network.codec.StreamCodec;
|
| 6 | import net.minecraft.network.protocol.Packet;
|
| 7 | import net.minecraft.network.protocol.PacketType;
|
| 8 | import net.minecraft.world.level.block.entity.CommandBlockEntity;
|
| 9 |
|
| 10 | public class ServerboundSetCommandBlockPacket implements Packet<ServerGamePacketListener> {
|
| 11 | public static final StreamCodec<FriendlyByteBuf, ServerboundSetCommandBlockPacket> STREAM_CODEC = Packet.codec(
|
| 12 | ServerboundSetCommandBlockPacket::write, ServerboundSetCommandBlockPacket::new
|
| 13 | );
|
| 14 | private static final int FLAG_TRACK_OUTPUT = 1;
|
| 15 | private static final int FLAG_CONDITIONAL = 2;
|
| 16 | private static final int FLAG_AUTOMATIC = 4;
|
| 17 | private final BlockPos pos;
|
| 18 | private final String command;
|
| 19 | private final boolean trackOutput;
|
| 20 | private final boolean conditional;
|
| 21 | private final boolean automatic;
|
| 22 | private final CommandBlockEntity.Mode mode;
|
| 23 |
|
| 24 | public ServerboundSetCommandBlockPacket(
|
| 25 | final BlockPos pos, final String command, final CommandBlockEntity.Mode mode, final boolean trackOutput, final boolean conditional, final boolean automatic
|
| 26 | ) {
|
| 27 | this.pos = pos;
|
| 28 | this.command = command;
|
| 29 | this.trackOutput = trackOutput;
|
| 30 | this.conditional = conditional;
|
| 31 | this.automatic = automatic;
|
| 32 | this.mode = mode;
|
| 33 | }
|
| 34 |
|
| 35 | private ServerboundSetCommandBlockPacket(final FriendlyByteBuf input) {
|
| 36 | this.pos = input.readBlockPos();
|
| 37 | this.command = input.readUtf();
|
| 38 | this.mode = input.readEnum(CommandBlockEntity.Mode.class);
|
| 39 | int flags = input.readByte();
|
| 40 | this.trackOutput = (flags & 1) != 0;
|
| 41 | this.conditional = (flags & 2) != 0;
|
| 42 | this.automatic = (flags & 4) != 0;
|
| 43 | }
|
| 44 |
|
| 45 | private void write(final FriendlyByteBuf output) {
|
| 46 | output.writeBlockPos(this.pos);
|
| 47 | output.writeUtf(this.command);
|
| 48 | output.writeEnum(this.mode);
|
| 49 | int flags = 0;
|
| 50 | if (this.trackOutput) {
|
| 51 | flags |= 1;
|
| 52 | }
|
| 53 |
|
| 54 | if (this.conditional) {
|
| 55 | flags |= 2;
|
| 56 | }
|
| 57 |
|
| 58 | if (this.automatic) {
|
| 59 | flags |= 4;
|
| 60 | }
|
| 61 |
|
| 62 | output.writeByte(flags);
|
| 63 | }
|
| 64 |
|
| 65 | @Override
|
| 66 | public PacketType<ServerboundSetCommandBlockPacket> type() {
|
| 67 | return GamePacketTypes.SERVERBOUND_SET_COMMAND_BLOCK;
|
| 68 | }
|
| 69 |
|
| 70 | public void handle(final ServerGamePacketListener listener) {
|
| 71 | listener.handleSetCommandBlock(this);
|
| 72 | }
|
| 73 |
|
| 74 | public BlockPos getPos() {
|
| 75 | return this.pos;
|
| 76 | }
|
| 77 |
|
| 78 | public String getCommand() {
|
| 79 | return this.command;
|
| 80 | }
|
| 81 |
|
| 82 | public boolean isTrackOutput() {
|
| 83 | return this.trackOutput;
|
| 84 | }
|
| 85 |
|
| 86 | public boolean isConditional() {
|
| 87 | return this.conditional;
|
| 88 | }
|
| 89 |
|
| 90 | public boolean isAutomatic() {
|
| 91 | return this.automatic;
|
| 92 | }
|
| 93 |
|
| 94 | public CommandBlockEntity.Mode getMode() {
|
| 95 | return this.mode;
|
| 96 | }
|
| 97 | }
|
| 98 |
|