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

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

import com.hypixel.hytale.component.CommandBuffer;
import com.hypixel.hytale.component.ArchetypeChunk;
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.component.system.tick.EntityTickingSystem;
import com.hypixel.hytale.component.RemoveReason;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.component.AddReason;
import com.hypixel.hytale.component.Holder;
import com.hypixel.hytale.component.query.Query;
import javax.annotation.Nonnull;
import com.hypixel.hytale.component.ComponentType;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.system.HolderSystem;

public class PlayerChunkTrackerSystems
{
    public static class AddSystem extends HolderSystem<EntityStore>
    {
        @Nonnull
        private static final ComponentType<EntityStore, ChunkTracker> CHUNK_TRACKER_COMPONENT_TYPE;
        
        @Override
        public Query<EntityStore> getQuery() {
            return AddSystem.CHUNK_TRACKER_COMPONENT_TYPE;
        }
        
        @Override
        public void onEntityAdd(@Nonnull final Holder<EntityStore> holder, @Nonnull final AddReason reason, @Nonnull final Store<EntityStore> store) {
            final ChunkTracker chunkTrackerComponent = holder.getComponent(AddSystem.CHUNK_TRACKER_COMPONENT_TYPE);
            assert chunkTrackerComponent != null;
            chunkTrackerComponent.setReadyForChunks(true);
        }
        
        @Override
        public void onEntityRemoved(@Nonnull final Holder<EntityStore> holder, @Nonnull final RemoveReason reason, @Nonnull final Store<EntityStore> store) {
        }
        
        static {
            CHUNK_TRACKER_COMPONENT_TYPE = ChunkTracker.getComponentType();
        }
    }
    
    public static class UpdateSystem extends EntityTickingSystem<EntityStore>
    {
        @Nonnull
        private static final ComponentType<EntityStore, ChunkTracker> CHUNK_TRACKER_COMPONENT_TYPE;
        @Nonnull
        private static final ComponentType<EntityStore, Player> PLAYER_COMPONENT_TYPE;
        @Nonnull
        private static final ComponentType<EntityStore, PlayerRef> PLAYER_REF_COMPONENT_TYPE;
        @Nonnull
        private static final ComponentType<EntityStore, TransformComponent> TRANSFORM_COMPONENT_TYPE;
        
        @Override
        public Query<EntityStore> getQuery() {
            return (Query<EntityStore>)Query.and(UpdateSystem.CHUNK_TRACKER_COMPONENT_TYPE, UpdateSystem.PLAYER_COMPONENT_TYPE, UpdateSystem.PLAYER_REF_COMPONENT_TYPE, UpdateSystem.TRANSFORM_COMPONENT_TYPE);
        }
        
        @Override
        public boolean isParallel(final int archetypeChunkSize, final int taskCount) {
            return false;
        }
        
        @Override
        public void tick(final float dt, final int index, @Nonnull final ArchetypeChunk<EntityStore> archetypeChunk, @Nonnull final Store<EntityStore> store, @Nonnull final CommandBuffer<EntityStore> commandBuffer) {
            final ChunkTracker chunkTrackerComponent = archetypeChunk.getComponent(index, UpdateSystem.CHUNK_TRACKER_COMPONENT_TYPE);
            assert chunkTrackerComponent != null;
            final Player playerComponent = archetypeChunk.getComponent(index, UpdateSystem.PLAYER_COMPONENT_TYPE);
            assert playerComponent != null;
            final PlayerRef playerRefComponent = archetypeChunk.getComponent(index, UpdateSystem.PLAYER_REF_COMPONENT_TYPE);
            assert playerRefComponent != null;
            final TransformComponent transformComponent = archetypeChunk.getComponent(index, UpdateSystem.TRANSFORM_COMPONENT_TYPE);
            assert transformComponent != null;
            chunkTrackerComponent.tick(playerComponent, playerRefComponent, transformComponent, dt, commandBuffer);
        }
        
        static {
            CHUNK_TRACKER_COMPONENT_TYPE = ChunkTracker.getComponentType();
            PLAYER_COMPONENT_TYPE = Player.getComponentType();
            PLAYER_REF_COMPONENT_TYPE = PlayerRef.getComponentType();
            TRANSFORM_COMPONENT_TYPE = TransformComponent.getComponentType();
        }
    }
}
