| 1 | package net.minecraft.network.protocol.game;
|
| 2 |
|
| 3 | import io.netty.buffer.ByteBuf;
|
| 4 | import java.util.Optional;
|
| 5 | import java.util.function.IntFunction;
|
| 6 | import net.minecraft.core.BlockPos;
|
| 7 | import net.minecraft.core.Vec3i;
|
| 8 | import net.minecraft.gametest.framework.GameTestInstance;
|
| 9 | import net.minecraft.network.RegistryFriendlyByteBuf;
|
| 10 | import net.minecraft.network.codec.ByteBufCodecs;
|
| 11 | import net.minecraft.network.codec.StreamCodec;
|
| 12 | import net.minecraft.network.protocol.Packet;
|
| 13 | import net.minecraft.network.protocol.PacketType;
|
| 14 | import net.minecraft.resources.ResourceKey;
|
| 15 | import net.minecraft.util.ByIdMap;
|
| 16 | import net.minecraft.world.level.block.Rotation;
|
| 17 | import net.minecraft.world.level.block.entity.TestInstanceBlockEntity;
|
| 18 |
|
| 19 | public record ServerboundTestInstanceBlockActionPacket(BlockPos pos, ServerboundTestInstanceBlockActionPacket.Action action, TestInstanceBlockEntity.Data data)
|
| 20 | implements Packet<ServerGamePacketListener> {
|
| 21 | public static final StreamCodec<RegistryFriendlyByteBuf, ServerboundTestInstanceBlockActionPacket> STREAM_CODEC = StreamCodec.composite(
|
| 22 | BlockPos.STREAM_CODEC,
|
| 23 | ServerboundTestInstanceBlockActionPacket::pos,
|
| 24 | ServerboundTestInstanceBlockActionPacket.Action.STREAM_CODEC,
|
| 25 | ServerboundTestInstanceBlockActionPacket::action,
|
| 26 | TestInstanceBlockEntity.Data.STREAM_CODEC,
|
| 27 | ServerboundTestInstanceBlockActionPacket::data,
|
| 28 | ServerboundTestInstanceBlockActionPacket::new
|
| 29 | );
|
| 30 |
|
| 31 | public ServerboundTestInstanceBlockActionPacket(
|
| 32 | final BlockPos pos,
|
| 33 | final ServerboundTestInstanceBlockActionPacket.Action action,
|
| 34 | final Optional<ResourceKey<GameTestInstance>> test,
|
| 35 | final Vec3i size,
|
| 36 | final Rotation rotation,
|
| 37 | final boolean ignoreEntities
|
| 38 | ) {
|
| 39 | this(pos, action, new TestInstanceBlockEntity.Data(test, size, rotation, ignoreEntities, TestInstanceBlockEntity.Status.CLEARED, Optional.empty()));
|
| 40 | }
|
| 41 |
|
| 42 | @Override
|
| 43 | public PacketType<ServerboundTestInstanceBlockActionPacket> type() {
|
| 44 | return GamePacketTypes.SERVERBOUND_TEST_INSTANCE_BLOCK_ACTION;
|
| 45 | }
|
| 46 |
|
| 47 | public void handle(final ServerGamePacketListener listener) {
|
| 48 | listener.handleTestInstanceBlockAction(this);
|
| 49 | }
|
| 50 |
|
| 51 | public enum Action {
|
| 52 | INIT(0),
|
| 53 | QUERY(1),
|
| 54 | SET(2),
|
| 55 | RESET(3),
|
| 56 | SAVE(4),
|
| 57 | EXPORT(5),
|
| 58 | RUN(6);
|
| 59 |
|
| 60 | private static final IntFunction<ServerboundTestInstanceBlockActionPacket.Action> BY_ID = ByIdMap.continuous(
|
| 61 | e -> e.id, values(), ByIdMap.OutOfBoundsStrategy.ZERO
|
| 62 | );
|
| 63 | public static final StreamCodec<ByteBuf, ServerboundTestInstanceBlockActionPacket.Action> STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, e -> e.id);
|
| 64 | private final int id;
|
| 65 |
|
| 66 | Action(final int id) {
|
| 67 | this.id = id;
|
| 68 | }
|
| 69 | }
|
| 70 | }
|
| 71 |
|