package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import net.minecraft.world.entity.decoration.Motive;
import java.io.IOException;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.core.Registry;
import net.minecraft.world.entity.decoration.Painting;
import net.minecraft.core.Direction;
import net.minecraft.core.BlockPos;
import java.util.UUID;
import net.minecraft.network.protocol.Packet;

public class ClientboundAddPaintingPacket implements Packet<ClientGamePacketListener> {
    private int id;
    private UUID uuid;
    private BlockPos pos;
    private Direction direction;
    private int motive;
    
    public ClientboundAddPaintingPacket() {
    }
    
    public ClientboundAddPaintingPacket(final Painting avu) {
        this.id = avu.getId();
        this.uuid = avu.getUUID();
        this.pos = avu.getPos();
        this.direction = avu.getDirection();
        this.motive = Registry.MOTIVE.getId(avu.motive);
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.id = kv.readVarInt();
        this.uuid = kv.readUUID();
        this.motive = kv.readVarInt();
        this.pos = kv.readBlockPos();
        this.direction = Direction.from2DDataValue(kv.readUnsignedByte());
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeVarInt(this.id);
        kv.writeUUID(this.uuid);
        kv.writeVarInt(this.motive);
        kv.writeBlockPos(this.pos);
        kv.writeByte(this.direction.get2DDataValue());
    }
    
    @Override
    public void handle(final ClientGamePacketListener lw) {
        lw.handleAddPainting(this);
    }
    
    public int getId() {
        return this.id;
    }
    
    public UUID getUUID() {
        return this.uuid;
    }
    
    public BlockPos getPos() {
        return this.pos;
    }
    
    public Direction getDirection() {
        return this.direction;
    }
    
    public Motive getMotive() {
        return Registry.MOTIVE.byId(this.motive);
    }
}
