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 ServerboundPlayerAbilitiesPacket implements Packet<ServerGamePacketListener> {
    private boolean invulnerable;
    private boolean isFlying;
    private boolean canFly;
    private boolean instabuild;
    private float flyingSpeed;
    private float walkingSpeed;
    
    public ServerboundPlayerAbilitiesPacket() {
    }
    
    public ServerboundPlayerAbilitiesPacket(final Abilities ayg) {
        this.setInvulnerable(ayg.invulnerable);
        this.setFlying(ayg.flying);
        this.setCanFly(ayg.mayfly);
        this.setInstabuild(ayg.instabuild);
        this.setFlyingSpeed(ayg.getFlyingSpeed());
        this.setWalkingSpeed(ayg.getWalkingSpeed());
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        final byte byte3 = kv.readByte();
        this.setInvulnerable((byte3 & 0x1) > 0);
        this.setFlying((byte3 & 0x2) > 0);
        this.setCanFly((byte3 & 0x4) > 0);
        this.setInstabuild((byte3 & 0x8) > 0);
        this.setFlyingSpeed(kv.readFloat());
        this.setWalkingSpeed(kv.readFloat());
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        byte byte3 = 0;
        if (this.isInvulnerable()) {
            byte3 |= 0x1;
        }
        if (this.isFlying()) {
            byte3 |= 0x2;
        }
        if (this.canFly()) {
            byte3 |= 0x4;
        }
        if (this.canInstabuild()) {
            byte3 |= 0x8;
        }
        kv.writeByte(byte3);
        kv.writeFloat(this.flyingSpeed);
        kv.writeFloat(this.walkingSpeed);
    }
    
    @Override
    public void handle(final ServerGamePacketListener pl) {
        pl.handlePlayerAbilities(this);
    }
    
    public boolean isInvulnerable() {
        return this.invulnerable;
    }
    
    public void setInvulnerable(final boolean boolean1) {
        this.invulnerable = boolean1;
    }
    
    public boolean isFlying() {
        return this.isFlying;
    }
    
    public void setFlying(final boolean boolean1) {
        this.isFlying = boolean1;
    }
    
    public boolean canFly() {
        return this.canFly;
    }
    
    public void setCanFly(final boolean boolean1) {
        this.canFly = boolean1;
    }
    
    public boolean canInstabuild() {
        return this.instabuild;
    }
    
    public void setInstabuild(final boolean boolean1) {
        this.instabuild = boolean1;
    }
    
    public void setFlyingSpeed(final float float1) {
        this.flyingSpeed = float1;
    }
    
    public void setWalkingSpeed(final float float1) {
        this.walkingSpeed = float1;
    }
}
