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

package com.hypixel.hytale.server.core.modules.debug.commands;

import com.hypixel.hytale.server.core.asset.type.model.config.Model;
import com.hypixel.hytale.math.vector.Vector3d;
import com.hypixel.hytale.server.core.modules.debug.DebugUtils;
import com.hypixel.hytale.math.vector.Vector3f;
import java.util.concurrent.ThreadLocalRandom;
import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.math.matrix.Matrix4d;
import com.hypixel.hytale.server.core.modules.entity.component.HeadRotation;
import com.hypixel.hytale.server.core.modules.entity.component.ModelComponent;
import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.server.core.universe.world.World;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.server.core.command.system.CommandContext;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractPlayerCommand;

public class DebugShapeArrowCommand extends AbstractPlayerCommand
{
    @Nonnull
    private static final Message MESSAGE_COMMANDS_DEBUG_SHAPE_ARROW_SUCCESS;
    
    public DebugShapeArrowCommand() {
        super("arrow", "server.commands.debug.shape.arrow.desc");
    }
    
    @Override
    protected void execute(@Nonnull final CommandContext context, @Nonnull final Store<EntityStore> store, @Nonnull final Ref<EntityStore> ref, @Nonnull final PlayerRef playerRef, @Nonnull final World world) {
        final Player playerComponent = store.getComponent(ref, Player.getComponentType());
        assert playerComponent != null;
        final TransformComponent transformComponent = store.getComponent(ref, TransformComponent.getComponentType());
        assert transformComponent != null;
        final Vector3d pos = transformComponent.getPosition();
        final ModelComponent modelComponent = store.getComponent(ref, ModelComponent.getComponentType());
        assert modelComponent != null;
        final Model model = modelComponent.getModel();
        final HeadRotation headRotationComponent = store.getComponent(ref, HeadRotation.getComponentType());
        assert headRotationComponent != null;
        final Vector3f headRotation = headRotationComponent.getRotation();
        final float lookYaw = headRotation.getYaw();
        final float lookPitch = headRotation.getPitch();
        final Matrix4d tmp = new Matrix4d();
        final float eyeHeight = (model != null) ? model.getEyeHeight(ref, store) : 0.0f;
        final ThreadLocalRandom random = ThreadLocalRandom.current();
        final Vector3f color = new Vector3f(random.nextFloat(), random.nextFloat(), random.nextFloat());
        final Matrix4d matrix = new Matrix4d();
        matrix.identity();
        matrix.translate(pos.x, pos.y + eyeHeight, pos.z);
        matrix.rotateAxis(-lookYaw, 0.0, 1.0, 0.0, tmp);
        matrix.rotateAxis(1.5707963267948966 - lookPitch, 1.0, 0.0, 0.0, tmp);
        DebugUtils.addArrow(world, matrix, color, 1.0, 30.0f, true);
        context.sendMessage(DebugShapeArrowCommand.MESSAGE_COMMANDS_DEBUG_SHAPE_ARROW_SUCCESS);
    }
    
    static {
        MESSAGE_COMMANDS_DEBUG_SHAPE_ARROW_SUCCESS = Message.translation("server.commands.debug.shape.arrow.success");
    }
}
