package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.util.Mth;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.state.properties.StructureMode;
import net.minecraft.world.level.block.entity.StructureBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.network.protocol.Packet;

public class ServerboundSetStructureBlockPacket implements Packet<ServerGamePacketListener> {
    private BlockPos pos;
    private StructureBlockEntity.UpdateType updateType;
    private StructureMode mode;
    private String name;
    private BlockPos offset;
    private BlockPos size;
    private Mirror mirror;
    private Rotation rotation;
    private String data;
    private boolean ignoreEntities;
    private boolean showAir;
    private boolean showBoundingBox;
    private float integrity;
    private long seed;
    
    public ServerboundSetStructureBlockPacket() {
    }
    
    public ServerboundSetStructureBlockPacket(final BlockPos fk1, final StructureBlockEntity.UpdateType a, final StructureMode bzr, final String string4, final BlockPos fk5, final BlockPos fk6, final Mirror bsu, final Rotation btu, final String string9, final boolean boolean10, final boolean boolean11, final boolean boolean12, final float float13, final long long14) {
        this.pos = fk1;
        this.updateType = a;
        this.mode = bzr;
        this.name = string4;
        this.offset = fk5;
        this.size = fk6;
        this.mirror = bsu;
        this.rotation = btu;
        this.data = string9;
        this.ignoreEntities = boolean10;
        this.showAir = boolean11;
        this.showBoundingBox = boolean12;
        this.integrity = float13;
        this.seed = long14;
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.pos = kv.readBlockPos();
        this.updateType = kv.<StructureBlockEntity.UpdateType>readEnum(StructureBlockEntity.UpdateType.class);
        this.mode = kv.<StructureMode>readEnum(StructureMode.class);
        this.name = kv.readUtf(32767);
        this.offset = new BlockPos(Mth.clamp(kv.readByte(), -32, 32), Mth.clamp(kv.readByte(), -32, 32), Mth.clamp(kv.readByte(), -32, 32));
        this.size = new BlockPos(Mth.clamp(kv.readByte(), 0, 32), Mth.clamp(kv.readByte(), 0, 32), Mth.clamp(kv.readByte(), 0, 32));
        this.mirror = kv.<Mirror>readEnum(Mirror.class);
        this.rotation = kv.<Rotation>readEnum(Rotation.class);
        this.data = kv.readUtf(12);
        this.integrity = Mth.clamp(kv.readFloat(), 0.0f, 1.0f);
        this.seed = kv.readVarLong();
        final int integer3 = kv.readByte();
        this.ignoreEntities = ((integer3 & 0x1) != 0x0);
        this.showAir = ((integer3 & 0x2) != 0x0);
        this.showBoundingBox = ((integer3 & 0x4) != 0x0);
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeBlockPos(this.pos);
        kv.writeEnum(this.updateType);
        kv.writeEnum(this.mode);
        kv.writeUtf(this.name);
        kv.writeByte(this.offset.getX());
        kv.writeByte(this.offset.getY());
        kv.writeByte(this.offset.getZ());
        kv.writeByte(this.size.getX());
        kv.writeByte(this.size.getY());
        kv.writeByte(this.size.getZ());
        kv.writeEnum(this.mirror);
        kv.writeEnum(this.rotation);
        kv.writeUtf(this.data);
        kv.writeFloat(this.integrity);
        kv.writeVarLong(this.seed);
        int integer3 = 0;
        if (this.ignoreEntities) {
            integer3 |= 0x1;
        }
        if (this.showAir) {
            integer3 |= 0x2;
        }
        if (this.showBoundingBox) {
            integer3 |= 0x4;
        }
        kv.writeByte(integer3);
    }
    
    @Override
    public void handle(final ServerGamePacketListener pl) {
        pl.handleSetStructureBlock(this);
    }
    
    public BlockPos getPos() {
        return this.pos;
    }
    
    public StructureBlockEntity.UpdateType getUpdateType() {
        return this.updateType;
    }
    
    public StructureMode getMode() {
        return this.mode;
    }
    
    public String getName() {
        return this.name;
    }
    
    public BlockPos getOffset() {
        return this.offset;
    }
    
    public BlockPos getSize() {
        return this.size;
    }
    
    public Mirror getMirror() {
        return this.mirror;
    }
    
    public Rotation getRotation() {
        return this.rotation;
    }
    
    public String getData() {
        return this.data;
    }
    
    public boolean isIgnoreEntities() {
        return this.ignoreEntities;
    }
    
    public boolean isShowAir() {
        return this.showAir;
    }
    
    public boolean isShowBoundingBox() {
        return this.showBoundingBox;
    }
    
    public float getIntegrity() {
        return this.integrity;
    }
    
    public long getSeed() {
        return this.seed;
    }
}
