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 bbd) {
        this.id = bbd.getId();
        this.uuid = bbd.getUUID();
        this.pos = bbd.getPos();
        this.direction = bbd.getDirection();
        this.motive = Registry.MOTIVE.getId(bbd.motive);
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        this.id = mg.readVarInt();
        this.uuid = mg.readUUID();
        this.motive = mg.readVarInt();
        this.pos = mg.readBlockPos();
        this.direction = Direction.from2DDataValue(mg.readUnsignedByte());
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeVarInt(this.id);
        mg.writeUUID(this.uuid);
        mg.writeVarInt(this.motive);
        mg.writeBlockPos(this.pos);
        mg.writeByte(this.direction.get2DDataValue());
    }
    
    @Override
    public void handle(final ClientGamePacketListener nl) {
        nl.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);
    }
}
