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

package com.hypixel.hytale.server.spawning.blockstates;

import com.hypixel.hytale.codec.validation.Validators;
import com.hypixel.hytale.server.spawning.assets.spawnmarker.config.SpawnMarker;
import com.hypixel.hytale.codec.validation.LateValidator;
import com.hypixel.hytale.math.vector.Vector3i;
import com.hypixel.hytale.server.core.asset.type.blocktype.config.StateData;
import com.hypixel.hytale.codec.KeyedCodec;
import com.hypixel.hytale.codec.builder.BuilderCodec;
import com.hypixel.hytale.server.core.entity.reference.PersistentRef;
import com.hypixel.hytale.codec.Codec;
import com.hypixel.hytale.server.core.universe.world.meta.BlockState;

public class SpawnMarkerBlockState extends BlockState
{
    public static final Codec<SpawnMarkerBlockState> CODEC;
    private PersistentRef spawnMarkerReference;
    private float markerLostTimeout;
    
    public SpawnMarkerBlockState() {
        this.markerLostTimeout = 30.0f;
    }
    
    public PersistentRef getSpawnMarkerReference() {
        return this.spawnMarkerReference;
    }
    
    public void setSpawnMarkerReference(final PersistentRef spawnMarkerReference) {
        this.spawnMarkerReference = spawnMarkerReference;
    }
    
    public void refreshMarkerLostTimeout() {
        this.markerLostTimeout = 30.0f;
    }
    
    public boolean tickMarkerLostTimeout(final float dt) {
        final float markerLostTimeout = this.markerLostTimeout - dt;
        this.markerLostTimeout = markerLostTimeout;
        return markerLostTimeout <= 0.0f;
    }
    
    static {
        CODEC = BuilderCodec.builder(SpawnMarkerBlockState.class, SpawnMarkerBlockState::new, BlockState.BASE_CODEC).append(new KeyedCodec<PersistentRef>("MarkerReference", PersistentRef.CODEC), (spawn, o) -> spawn.spawnMarkerReference = o, spawn -> spawn.spawnMarkerReference).add().build();
    }
    
    public static class Data extends StateData
    {
        public static final BuilderCodec<Data> CODEC;
        private String spawnMarker;
        private Vector3i markerOffset;
        
        protected Data() {
        }
        
        public String getSpawnMarker() {
            return this.spawnMarker;
        }
        
        public Vector3i getMarkerOffset() {
            return this.markerOffset;
        }
        
        static {
            CODEC = BuilderCodec.builder(Data.class, Data::new, StateData.DEFAULT_CODEC).appendInherited(new KeyedCodec<String>("SpawnMarker", Codec.STRING), (spawn, s) -> spawn.spawnMarker = s, spawn -> spawn.spawnMarker, (spawn, parent) -> spawn.spawnMarker = parent.spawnMarker).documentation("The spawn marker to use.").addValidator(Validators.nonNull()).addValidatorLate(() -> SpawnMarker.VALIDATOR_CACHE.getValidator().late()).add().appendInherited(new KeyedCodec("MarkerOffset", Vector3i.CODEC), (spawn, o) -> spawn.markerOffset = o, spawn -> spawn.markerOffset, (spawn, parent) -> spawn.markerOffset = parent.markerOffset).documentation("An offset from the block at which the marker entity should be spawned.").add().build();
        }
    }
}
