// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.protocol;

import java.util.Objects;
import com.hypixel.hytale.protocol.io.ValidationResult;
import io.netty.buffer.ByteBuf;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class InitialVelocity
{
    public static final int NULLABLE_BIT_FIELD_SIZE = 1;
    public static final int FIXED_BLOCK_SIZE = 25;
    public static final int VARIABLE_FIELD_COUNT = 0;
    public static final int VARIABLE_BLOCK_START = 25;
    public static final int MAX_SIZE = 25;
    @Nullable
    public Rangef yaw;
    @Nullable
    public Rangef pitch;
    @Nullable
    public Rangef speed;
    
    public InitialVelocity() {
    }
    
    public InitialVelocity(@Nullable final Rangef yaw, @Nullable final Rangef pitch, @Nullable final Rangef speed) {
        this.yaw = yaw;
        this.pitch = pitch;
        this.speed = speed;
    }
    
    public InitialVelocity(@Nonnull final InitialVelocity other) {
        this.yaw = other.yaw;
        this.pitch = other.pitch;
        this.speed = other.speed;
    }
    
    @Nonnull
    public static InitialVelocity deserialize(@Nonnull final ByteBuf buf, final int offset) {
        final InitialVelocity obj = new InitialVelocity();
        final byte nullBits = buf.getByte(offset);
        if ((nullBits & 0x1) != 0x0) {
            obj.yaw = Rangef.deserialize(buf, offset + 1);
        }
        if ((nullBits & 0x2) != 0x0) {
            obj.pitch = Rangef.deserialize(buf, offset + 9);
        }
        if ((nullBits & 0x4) != 0x0) {
            obj.speed = Rangef.deserialize(buf, offset + 17);
        }
        return obj;
    }
    
    public static int computeBytesConsumed(@Nonnull final ByteBuf buf, final int offset) {
        return 25;
    }
    
    public void serialize(@Nonnull final ByteBuf buf) {
        byte nullBits = 0;
        if (this.yaw != null) {
            nullBits |= 0x1;
        }
        if (this.pitch != null) {
            nullBits |= 0x2;
        }
        if (this.speed != null) {
            nullBits |= 0x4;
        }
        buf.writeByte(nullBits);
        if (this.yaw != null) {
            this.yaw.serialize(buf);
        }
        else {
            buf.writeZero(8);
        }
        if (this.pitch != null) {
            this.pitch.serialize(buf);
        }
        else {
            buf.writeZero(8);
        }
        if (this.speed != null) {
            this.speed.serialize(buf);
        }
        else {
            buf.writeZero(8);
        }
    }
    
    public int computeSize() {
        return 25;
    }
    
    public static ValidationResult validateStructure(@Nonnull final ByteBuf buffer, final int offset) {
        if (buffer.readableBytes() - offset < 25) {
            return ValidationResult.error("Buffer too small: expected at least 25 bytes");
        }
        return ValidationResult.OK;
    }
    
    public InitialVelocity clone() {
        final InitialVelocity copy = new InitialVelocity();
        copy.yaw = ((this.yaw != null) ? this.yaw.clone() : null);
        copy.pitch = ((this.pitch != null) ? this.pitch.clone() : null);
        copy.speed = ((this.speed != null) ? this.speed.clone() : null);
        return copy;
    }
    
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof final InitialVelocity other) {
            return Objects.equals(this.yaw, other.yaw) && Objects.equals(this.pitch, other.pitch) && Objects.equals(this.speed, other.speed);
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(this.yaw, this.pitch, this.speed);
    }
}
