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

package com.hypixel.hytale.server.core.universe.world;

import javax.annotation.Nullable;
import com.hypixel.hytale.math.vector.Transform;
import com.hypixel.hytale.server.core.universe.world.spawn.ISpawnProvider;
import com.hypixel.hytale.server.core.modules.entity.component.HeadRotation;
import com.hypixel.hytale.math.vector.Vector3f;
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
import java.util.UUID;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Holder;

public final class SpawnUtil
{
    @Nullable
    public static TransformComponent applyFirstSpawnTransform(@Nonnull final Holder<EntityStore> holder, @Nonnull final World world, @Nonnull final WorldConfig worldConfig, @Nonnull final UUID playerUuid) {
        final ISpawnProvider spawnProvider = worldConfig.getSpawnProvider();
        if (spawnProvider == null) {
            return null;
        }
        final Transform spawnPoint = spawnProvider.getSpawnPoint(world, playerUuid);
        final Vector3f bodyRotation = new Vector3f(0.0f, spawnPoint.getRotation().getYaw(), 0.0f);
        final TransformComponent transformComponent = new TransformComponent(spawnPoint.getPosition(), bodyRotation);
        holder.addComponent(TransformComponent.getComponentType(), transformComponent);
        final HeadRotation headRotationComponent = holder.ensureAndGetComponent(HeadRotation.getComponentType());
        headRotationComponent.teleportRotation(spawnPoint.getRotation());
        return transformComponent;
    }
    
    public static void applyTransform(@Nonnull final Holder<EntityStore> holder, @Nonnull final Transform transform) {
        final TransformComponent transformComponent = holder.getComponent(TransformComponent.getComponentType());
        assert transformComponent != null;
        transformComponent.setPosition(transform.getPosition());
        transformComponent.getRotation().setYaw(transform.getRotation().getYaw());
        final HeadRotation headRotationComponent = holder.ensureAndGetComponent(HeadRotation.getComponentType());
        headRotationComponent.teleportRotation(transform.getRotation());
    }
}
