// 
// 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 AOECylinderSelector extends Selector
{
    public static final int NULLABLE_BIT_FIELD_SIZE = 1;
    public static final int FIXED_BLOCK_SIZE = 21;
    public static final int VARIABLE_FIELD_COUNT = 0;
    public static final int VARIABLE_BLOCK_START = 21;
    public static final int MAX_SIZE = 21;
    public float range;
    public float height;
    @Nullable
    public Vector3f offset;
    
    public AOECylinderSelector() {
    }
    
    public AOECylinderSelector(final float range, final float height, @Nullable final Vector3f offset) {
        this.range = range;
        this.height = height;
        this.offset = offset;
    }
    
    public AOECylinderSelector(@Nonnull final AOECylinderSelector other) {
        this.range = other.range;
        this.height = other.height;
        this.offset = other.offset;
    }
    
    @Nonnull
    public static AOECylinderSelector deserialize(@Nonnull final ByteBuf buf, final int offset) {
        final AOECylinderSelector obj = new AOECylinderSelector();
        final byte nullBits = buf.getByte(offset);
        obj.range = buf.getFloatLE(offset + 1);
        obj.height = buf.getFloatLE(offset + 5);
        if ((nullBits & 0x1) != 0x0) {
            obj.offset = Vector3f.deserialize(buf, offset + 9);
        }
        return obj;
    }
    
    public static int computeBytesConsumed(@Nonnull final ByteBuf buf, final int offset) {
        return 21;
    }
    
    @Override
    public int serialize(@Nonnull final ByteBuf buf) {
        final int startPos = buf.writerIndex();
        byte nullBits = 0;
        if (this.offset != null) {
            nullBits |= 0x1;
        }
        buf.writeByte(nullBits);
        buf.writeFloatLE(this.range);
        buf.writeFloatLE(this.height);
        if (this.offset != null) {
            this.offset.serialize(buf);
        }
        else {
            buf.writeZero(12);
        }
        return buf.writerIndex() - startPos;
    }
    
    @Override
    public int computeSize() {
        return 21;
    }
    
    public static ValidationResult validateStructure(@Nonnull final ByteBuf buffer, final int offset) {
        if (buffer.readableBytes() - offset < 21) {
            return ValidationResult.error("Buffer too small: expected at least 21 bytes");
        }
        return ValidationResult.OK;
    }
    
    public AOECylinderSelector clone() {
        final AOECylinderSelector copy = new AOECylinderSelector();
        copy.range = this.range;
        copy.height = this.height;
        copy.offset = ((this.offset != null) ? this.offset.clone() : null);
        return copy;
    }
    
    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof final AOECylinderSelector other) {
            return this.range == other.range && this.height == other.height && Objects.equals(this.offset, other.offset);
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(this.range, this.height, this.offset);
    }
}
