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

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

import com.hypixel.hytale.server.core.universe.world.World;
import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.component.Store;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.system.tick.EntityTickingSystem;
import com.hypixel.hytale.server.spawning.jobs.SpawnJob;

public abstract class SpawnControllerSystem<J extends SpawnJob, T extends SpawnController<J>> extends EntityTickingSystem<EntityStore>
{
    protected void tickController(@Nonnull final T spawnController, @Nonnull final Store<EntityStore> store) {
        final World world = store.getExternalData().getWorld();
        if (world.getPlayerCount() == 0 || !world.getWorldConfig().isSpawningNPC() || spawnController.isUnspawnable() || world.getChunkStore().getStore().getEntityCount() == 0) {
            return;
        }
        if (spawnController.getActualNPCs() > spawnController.getExpectedNPCs()) {
            return;
        }
        this.prepareSpawnJobGeneration(spawnController, store);
        this.createRandomSpawnJobs(spawnController, store);
    }
    
    protected abstract void prepareSpawnJobGeneration(final T p0, final ComponentAccessor<EntityStore> p1);
    
    protected void createRandomSpawnJobs(@Nonnull final T spawnController, @Nonnull final ComponentAccessor<EntityStore> componentAccessor) {
        while (spawnController.getActiveJobCount() < spawnController.getMaxActiveJobs() && spawnController.createRandomSpawnJob(componentAccessor) != null) {}
    }
}
