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

package com.hypixel.hytale.server.core.modules.entity.component;

import java.util.function.Predicate;
import javax.annotation.Nonnull;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.server.core.modules.entity.EntityModule;
import com.hypixel.hytale.component.ComponentType;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Component;

public class MovementAudioComponent implements Component<EntityStore>
{
    public static float NO_REPEAT;
    private final ShouldHearPredicate shouldHearPredicate;
    private int lastInsideBlockTypeId;
    private float nextMoveInRepeat;
    
    public static ComponentType<EntityStore, MovementAudioComponent> getComponentType() {
        return EntityModule.get().getMovementAudioComponentType();
    }
    
    public MovementAudioComponent() {
        this.shouldHearPredicate = new ShouldHearPredicate();
        this.lastInsideBlockTypeId = 0;
        this.nextMoveInRepeat = MovementAudioComponent.NO_REPEAT;
    }
    
    @Nonnull
    public ShouldHearPredicate getShouldHearPredicate(final Ref<EntityStore> ref) {
        this.shouldHearPredicate.owner = ref;
        return this.shouldHearPredicate;
    }
    
    public int getLastInsideBlockTypeId() {
        return this.lastInsideBlockTypeId;
    }
    
    public void setLastInsideBlockTypeId(final int lastInsideBlockTypeId) {
        this.lastInsideBlockTypeId = lastInsideBlockTypeId;
    }
    
    public boolean canMoveInRepeat() {
        return this.nextMoveInRepeat != MovementAudioComponent.NO_REPEAT;
    }
    
    public boolean tickMoveInRepeat(final float dt) {
        final float nextMoveInRepeat = this.nextMoveInRepeat - dt;
        this.nextMoveInRepeat = nextMoveInRepeat;
        return nextMoveInRepeat <= 0.0f;
    }
    
    public void setNextMoveInRepeat(final float nextMoveInRepeat) {
        this.nextMoveInRepeat = nextMoveInRepeat;
    }
    
    @Nonnull
    @Override
    public Component<EntityStore> clone() {
        return new MovementAudioComponent();
    }
    
    static {
        MovementAudioComponent.NO_REPEAT = -1.0f;
    }
    
    public static class ShouldHearPredicate implements Predicate<Ref<EntityStore>>
    {
        protected Ref<EntityStore> owner;
        
        @Override
        public boolean test(@Nonnull final Ref<EntityStore> targetRef) {
            return !this.owner.equals(targetRef);
        }
    }
}
