package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.player.Abilities;
import net.minecraft.network.protocol.Packet;

public class ClientboundPlayerAbilitiesPacket implements Packet<ClientGamePacketListener> {
    private boolean invulnerable;
    private boolean isFlying;
    private boolean canFly;
    private boolean instabuild;
    private float flyingSpeed;
    private float walkingSpeed;
    
    public ClientboundPlayerAbilitiesPacket() {
    }
    
    public ClientboundPlayerAbilitiesPacket(final Abilities bdz) {
        this.invulnerable = bdz.invulnerable;
        this.isFlying = bdz.flying;
        this.canFly = bdz.mayfly;
        this.instabuild = bdz.instabuild;
        this.flyingSpeed = bdz.getFlyingSpeed();
        this.walkingSpeed = bdz.getWalkingSpeed();
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        final byte byte3 = mg.readByte();
        this.invulnerable = ((byte3 & 0x1) != 0x0);
        this.isFlying = ((byte3 & 0x2) != 0x0);
        this.canFly = ((byte3 & 0x4) != 0x0);
        this.instabuild = ((byte3 & 0x8) != 0x0);
        this.flyingSpeed = mg.readFloat();
        this.walkingSpeed = mg.readFloat();
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        byte byte3 = 0;
        if (this.invulnerable) {
            byte3 |= 0x1;
        }
        if (this.isFlying) {
            byte3 |= 0x2;
        }
        if (this.canFly) {
            byte3 |= 0x4;
        }
        if (this.instabuild) {
            byte3 |= 0x8;
        }
        mg.writeByte(byte3);
        mg.writeFloat(this.flyingSpeed);
        mg.writeFloat(this.walkingSpeed);
    }
    
    @Override
    public void handle(final ClientGamePacketListener nl) {
        nl.handlePlayerAbilities(this);
    }
    
    public boolean isInvulnerable() {
        return this.invulnerable;
    }
    
    public boolean isFlying() {
        return this.isFlying;
    }
    
    public boolean canFly() {
        return this.canFly;
    }
    
    public boolean canInstabuild() {
        return this.instabuild;
    }
    
    public float getFlyingSpeed() {
        return this.flyingSpeed;
    }
    
    public float getWalkingSpeed() {
        return this.walkingSpeed;
    }
}
