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

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

import com.hypixel.hytale.math.vector.Vector3f;
import com.hypixel.hytale.component.CommandBuffer;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.component.ArchetypeChunk;
import com.hypixel.hytale.component.query.Query;
import com.hypixel.hytale.server.core.modules.entity.component.RotateObjectComponent;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
import com.hypixel.hytale.component.ComponentType;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.system.tick.EntityTickingSystem;

public class RotateObjectSystem extends EntityTickingSystem<EntityStore>
{
    @Nonnull
    private final ComponentType<EntityStore, TransformComponent> transformComponentType;
    @Nonnull
    private final ComponentType<EntityStore, RotateObjectComponent> rotateObjectComponentType;
    
    public RotateObjectSystem(@Nonnull final ComponentType<EntityStore, TransformComponent> transformComponentType, @Nonnull final ComponentType<EntityStore, RotateObjectComponent> rotateObjectComponentType) {
        this.transformComponentType = transformComponentType;
        this.rotateObjectComponentType = rotateObjectComponentType;
    }
    
    @Override
    public Query<EntityStore> getQuery() {
        return (Query<EntityStore>)Query.and(this.rotateObjectComponentType, this.transformComponentType);
    }
    
    @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 RotateObjectComponent rotateObjectComponent = archetypeChunk.getComponent(index, this.rotateObjectComponentType);
        assert rotateObjectComponent != null;
        final TransformComponent transformComponent = archetypeChunk.getComponent(index, this.transformComponentType);
        assert transformComponent != null;
        final Vector3f rotation2;
        final Vector3f rotation = rotation2 = transformComponent.getRotation();
        rotation2.y += rotateObjectComponent.getRotationSpeed() * dt;
        if (rotation.y >= 360.0f) {
            final Vector3f vector3f = rotation;
            vector3f.y %= 360.0f;
        }
        transformComponent.setRotation(rotation);
    }
}
