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

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

import com.hypixel.hytale.math.vector.Transform;
import com.hypixel.hytale.server.core.modules.entity.EntityModule;
import com.hypixel.hytale.component.ComponentType;
import com.hypixel.hytale.math.vector.Vector3f;
import javax.annotation.Nonnull;
import com.hypixel.hytale.math.vector.Vector3d;
import javax.annotation.Nullable;
import com.hypixel.hytale.server.core.universe.world.World;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Component;

public class Teleport implements Component<EntityStore>
{
    @Nullable
    private final World world;
    @Nonnull
    private final Vector3d position;
    @Nonnull
    private final Vector3f rotation;
    @Nullable
    private Vector3f headRotation;
    private boolean resetVelocity;
    
    @Nonnull
    public static ComponentType<EntityStore, Teleport> getComponentType() {
        return EntityModule.get().getTeleportComponentType();
    }
    
    public Teleport(@Nullable final World world, @Nonnull final Vector3d position, @Nonnull final Vector3f rotation) {
        this.position = new Vector3d();
        this.rotation = new Vector3f();
        this.resetVelocity = true;
        this.world = world;
        this.position.assign(position);
        this.rotation.assign(rotation);
    }
    
    public Teleport(@Nonnull final Vector3d position, @Nonnull final Vector3f rotation) {
        this.position = new Vector3d();
        this.rotation = new Vector3f();
        this.resetVelocity = true;
        this.world = null;
        this.position.assign(position);
        this.rotation.assign(rotation);
    }
    
    @Nonnull
    public static Teleport createForPlayer(@Nullable final World world, @Nonnull final Transform transform) {
        final Vector3f headRotation = transform.getRotation();
        final Vector3f bodyRotation = new Vector3f(0.0f, headRotation.getYaw(), 0.0f);
        return new Teleport(world, transform.getPosition(), bodyRotation).setHeadRotation(headRotation);
    }
    
    @Nonnull
    public static Teleport createForPlayer(@Nullable final World world, @Nonnull final Vector3d position, @Nonnull final Vector3f rotation) {
        final Vector3f headRotation = rotation.clone();
        final Vector3f bodyRotation = new Vector3f(0.0f, headRotation.getYaw(), 0.0f);
        return new Teleport(world, position, bodyRotation).setHeadRotation(headRotation);
    }
    
    @Nonnull
    public static Teleport createForPlayer(@Nonnull final Vector3d position, @Nonnull final Vector3f rotation) {
        return createForPlayer(null, position, rotation);
    }
    
    @Nonnull
    public static Teleport createForPlayer(@Nonnull final Transform transform) {
        return createForPlayer(null, transform);
    }
    
    @Nonnull
    public static Teleport createExact(@Nonnull final Vector3d position, @Nonnull final Vector3f bodyRotation, @Nonnull final Vector3f headRotation) {
        return new Teleport(position, bodyRotation).setHeadRotation(headRotation);
    }
    
    @Nonnull
    public static Teleport createExact(@Nonnull final Vector3d position, @Nonnull final Vector3f bodyRotation) {
        return new Teleport(position, bodyRotation);
    }
    
    public void setPosition(@Nonnull final Vector3d position) {
        this.position.assign(position);
    }
    
    public void setRotation(@Nonnull final Vector3f rotation) {
        this.rotation.assign(rotation);
    }
    
    @Nonnull
    public Teleport setHeadRotation(@Nonnull final Vector3f headRotation) {
        this.headRotation = headRotation.clone();
        return this;
    }
    
    public Teleport withoutVelocityReset() {
        this.resetVelocity = false;
        return this;
    }
    
    @Nullable
    public World getWorld() {
        return this.world;
    }
    
    @Nonnull
    public Vector3d getPosition() {
        return this.position;
    }
    
    @Nonnull
    public Vector3f getRotation() {
        return this.rotation;
    }
    
    @Nullable
    public Vector3f getHeadRotation() {
        return this.headRotation;
    }
    
    public boolean isResetVelocity() {
        return this.resetVelocity;
    }
    
    @Nonnull
    @Override
    public Teleport clone() {
        return new Teleport(this.world, this.position, this.rotation);
    }
}
