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

package com.hypixel.hytale.server.core.modules.physics.systems;

import java.util.Iterator;
import com.hypixel.hytale.component.CommandBuffer;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.component.ArchetypeChunk;
import com.hypixel.hytale.server.core.modules.physics.component.Velocity;
import com.hypixel.hytale.component.SystemType;
import com.hypixel.hytale.component.dependency.SystemTypeDependency;
import com.hypixel.hytale.server.core.modules.entity.EntityModule;
import com.hypixel.hytale.component.dependency.Order;
import com.hypixel.hytale.component.query.Query;
import javax.annotation.Nonnull;
import com.hypixel.hytale.component.dependency.Dependency;
import java.util.Set;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.system.tick.EntityTickingSystem;

public class GenericVelocityInstructionSystem extends EntityTickingSystem<EntityStore>
{
    @Nonnull
    private final Set<Dependency<EntityStore>> dependencies;
    @Nonnull
    private final Query<EntityStore> query;
    
    public GenericVelocityInstructionSystem() {
        this.dependencies = (Set<Dependency<EntityStore>>)Set.of(new SystemTypeDependency(Order.AFTER, EntityModule.get().getVelocityModifyingSystemType()));
        this.query = (Query<EntityStore>)Query.and(Velocity.getComponentType());
    }
    
    @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 Velocity velocityComponent = archetypeChunk.getComponent(index, Velocity.getComponentType());
        assert velocityComponent != null;
        for (final Velocity.Instruction instruction : velocityComponent.getInstructions()) {
            switch (instruction.getType()) {
                case Set: {
                    velocityComponent.set(instruction.getVelocity());
                    continue;
                }
                case Add: {
                    velocityComponent.addForce(instruction.getVelocity());
                    continue;
                }
            }
        }
        velocityComponent.getInstructions().clear();
    }
    
    @Nonnull
    @Override
    public Set<Dependency<EntityStore>> getDependencies() {
        return this.dependencies;
    }
    
    @Nonnull
    @Override
    public Query<EntityStore> getQuery() {
        return this.query;
    }
}
