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

package com.hypixel.hytale.builtin.weather.resources;

import com.hypixel.hytale.server.core.asset.type.weather.config.Weather;
import javax.annotation.Nullable;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import com.hypixel.hytale.builtin.weather.WeatherPlugin;
import com.hypixel.hytale.component.ResourceType;
import javax.annotation.Nonnull;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Resource;

public class WeatherResource implements Resource<EntityStore>
{
    public static final float WEATHER_UPDATE_RATE_S = 1.0f;
    private int forcedWeatherIndex;
    private int previousForcedWeatherIndex;
    @Nonnull
    private final Int2IntMap environmentWeather;
    private int previousHour;
    public float playerUpdateDelay;
    
    public static ResourceType<EntityStore, WeatherResource> getResourceType() {
        return WeatherPlugin.get().getWeatherResourceType();
    }
    
    public WeatherResource() {
        this.environmentWeather = new Int2IntOpenHashMap();
        this.previousHour = -1;
        this.environmentWeather.defaultReturnValue(Integer.MIN_VALUE);
    }
    
    @Nonnull
    public Int2IntMap getEnvironmentWeather() {
        return this.environmentWeather;
    }
    
    public int getWeatherIndexForEnvironment(final int environmentId) {
        return this.environmentWeather.get(environmentId);
    }
    
    public int getForcedWeatherIndex() {
        return this.forcedWeatherIndex;
    }
    
    public void setForcedWeather(@Nullable final String forcedWeather) {
        this.previousForcedWeatherIndex = this.forcedWeatherIndex;
        this.forcedWeatherIndex = ((forcedWeather == null) ? 0 : Weather.getAssetMap().getIndex(forcedWeather));
    }
    
    public boolean consumeForcedWeatherChange() {
        if (this.previousForcedWeatherIndex == this.forcedWeatherIndex) {
            return false;
        }
        this.previousForcedWeatherIndex = this.forcedWeatherIndex;
        return true;
    }
    
    public boolean compareAndSwapHour(final int currentHour) {
        if (currentHour == this.previousHour) {
            return false;
        }
        this.previousHour = currentHour;
        return true;
    }
    
    @Nonnull
    @Override
    public Resource<EntityStore> clone() {
        return new WeatherResource();
    }
}
