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

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

import com.hypixel.hytale.protocol.ChangeVelocityType;
import javax.annotation.Nullable;
import com.hypixel.hytale.server.core.modules.splitvelocity.VelocityConfig;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import com.hypixel.hytale.server.core.modules.entity.EntityModule;
import com.hypixel.hytale.component.ComponentType;
import com.hypixel.hytale.math.vector.Vector3d;
import java.util.List;
import javax.annotation.Nonnull;
import com.hypixel.hytale.codec.builder.BuilderCodec;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Component;

public class Velocity implements Component<EntityStore>
{
    @Nonnull
    public static final BuilderCodec<Velocity> CODEC;
    @Nonnull
    protected final List<Instruction> instructions;
    @Nonnull
    protected final Vector3d velocity;
    @Nonnull
    protected final Vector3d clientVelocity;
    
    @Nonnull
    public static ComponentType<EntityStore, Velocity> getComponentType() {
        return EntityModule.get().getVelocityComponentType();
    }
    
    public Velocity() {
        this.instructions = new ObjectArrayList<Instruction>();
        this.velocity = new Vector3d();
        this.clientVelocity = new Vector3d();
    }
    
    public Velocity(@Nonnull final Velocity other) {
        this(other.velocity.clone());
    }
    
    public Velocity(@Nonnull final Vector3d initialVelocity) {
        this.instructions = new ObjectArrayList<Instruction>();
        this.velocity = new Vector3d();
        this.clientVelocity = new Vector3d();
        this.velocity.assign(initialVelocity);
    }
    
    public void setZero() {
        this.set(0.0, 0.0, 0.0);
    }
    
    public void addForce(@Nonnull final Vector3d force) {
        this.velocity.add(force);
    }
    
    public void addForce(final double x, final double y, final double z) {
        this.velocity.add(x, y, z);
    }
    
    public void set(@Nonnull final Vector3d newVelocity) {
        this.set(newVelocity.getX(), newVelocity.getY(), newVelocity.getZ());
    }
    
    public void set(final double x, final double y, final double z) {
        this.velocity.assign(x, y, z);
    }
    
    public void setClient(@Nonnull final Vector3d newVelocity) {
        this.setClient(newVelocity.getX(), newVelocity.getY(), newVelocity.getZ());
    }
    
    public void setClient(final double x, final double y, final double z) {
        this.clientVelocity.assign(x, y, z);
    }
    
    public void setX(final double x) {
        this.velocity.setX(x);
    }
    
    public void setY(final double y) {
        this.velocity.setY(y);
    }
    
    public void setZ(final double z) {
        this.velocity.setZ(z);
    }
    
    public double getX() {
        return this.velocity.getX();
    }
    
    public double getY() {
        return this.velocity.getY();
    }
    
    public double getZ() {
        return this.velocity.getZ();
    }
    
    public double getSpeed() {
        return this.velocity.length();
    }
    
    public void addInstruction(@Nonnull final Vector3d velocity, @Nullable final VelocityConfig config, @Nonnull final ChangeVelocityType type) {
        this.instructions.add(new Instruction(velocity, config, type));
    }
    
    @Nonnull
    public List<Instruction> getInstructions() {
        return this.instructions;
    }
    
    @Nonnull
    public Vector3d getVelocity() {
        return this.velocity;
    }
    
    @Nonnull
    public Vector3d getClientVelocity() {
        return this.clientVelocity;
    }
    
    @Nonnull
    public Vector3d assignVelocityTo(@Nonnull final Vector3d vector) {
        return vector.assign(this.velocity);
    }
    
    @Nonnull
    @Override
    public Component<EntityStore> clone() {
        return new Velocity(this);
    }
    
    static {
        // 
        // This method could not be decompiled.
        // 
        // Original Bytecode:
        // 
        //     2: invokedynamic   BootstrapMethod #0, get:()Ljava/util/function/Supplier;
        //     7: invokestatic    com/hypixel/hytale/codec/builder/BuilderCodec.builder:(Ljava/lang/Class;Ljava/util/function/Supplier;)Lcom/hypixel/hytale/codec/builder/BuilderCodec$Builder;
        //    10: new             Lcom/hypixel/hytale/codec/KeyedCodec;
        //    13: dup            
        //    14: ldc             "Velocity"
        //    16: getstatic       com/hypixel/hytale/math/vector/Vector3d.CODEC:Lcom/hypixel/hytale/codec/builder/BuilderCodec;
        //    19: invokespecial   com/hypixel/hytale/codec/KeyedCodec.<init>:(Ljava/lang/String;Lcom/hypixel/hytale/codec/Codec;)V
        //    22: invokedynamic   BootstrapMethod #1, accept:()Ljava/util/function/BiConsumer;
        //    27: invokedynamic   BootstrapMethod #2, apply:()Ljava/util/function/Function;
        //    32: invokevirtual   com/hypixel/hytale/codec/builder/BuilderCodec$Builder.append:(Lcom/hypixel/hytale/codec/KeyedCodec;Ljava/util/function/BiConsumer;Ljava/util/function/Function;)Lcom/hypixel/hytale/codec/builder/BuilderField$FieldBuilder;
        //    35: invokevirtual   com/hypixel/hytale/codec/builder/BuilderField$FieldBuilder.add:()Lcom/hypixel/hytale/codec/builder/BuilderCodec$BuilderBase;
        //    38: checkcast       Lcom/hypixel/hytale/codec/builder/BuilderCodec$Builder;
        //    41: invokevirtual   com/hypixel/hytale/codec/builder/BuilderCodec$Builder.build:()Lcom/hypixel/hytale/codec/builder/BuilderCodec;
        //    44: putstatic       com/hypixel/hytale/server/core/modules/physics/component/Velocity.CODEC:Lcom/hypixel/hytale/codec/builder/BuilderCodec;
        //    47: return         
        // 
        // The error that occurred was:
        // 
        // java.lang.UnsupportedOperationException: The requested operation is not supported.
        //     at com.strobel.util.ContractUtils.unsupported(ContractUtils.java:27)
        //     at com.strobel.assembler.metadata.TypeReference.getRawType(TypeReference.java:284)
        //     at com.strobel.assembler.metadata.TypeReference.getRawType(TypeReference.java:279)
        //     at com.strobel.assembler.metadata.TypeReference.makeGenericType(TypeReference.java:154)
        //     at com.strobel.assembler.metadata.TypeSubstitutionVisitor.visitParameterizedType(TypeSubstitutionVisitor.java:225)
        //     at com.strobel.assembler.metadata.TypeSubstitutionVisitor.visitParameterizedType(TypeSubstitutionVisitor.java:25)
        //     at com.strobel.assembler.metadata.ParameterizedType.accept(ParameterizedType.java:103)
        //     at com.strobel.assembler.metadata.TypeSubstitutionVisitor.visit(TypeSubstitutionVisitor.java:40)
        //     at com.strobel.assembler.metadata.TypeSubstitutionVisitor.visitParameterizedType(TypeSubstitutionVisitor.java:211)
        //     at com.strobel.assembler.metadata.TypeSubstitutionVisitor.visitParameterizedType(TypeSubstitutionVisitor.java:25)
        //     at com.strobel.assembler.metadata.ParameterizedType.accept(ParameterizedType.java:103)
        //     at com.strobel.assembler.metadata.TypeSubstitutionVisitor.visit(TypeSubstitutionVisitor.java:40)
        //     at com.strobel.assembler.metadata.TypeSubstitutionVisitor.visitMethod(TypeSubstitutionVisitor.java:314)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferCall(TypeAnalysis.java:2611)
        //     at com.strobel.decompiler.ast.TypeAnalysis.doInferTypeForExpression(TypeAnalysis.java:1040)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:815)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:782)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:778)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferCall(TypeAnalysis.java:2483)
        //     at com.strobel.decompiler.ast.TypeAnalysis.doInferTypeForExpression(TypeAnalysis.java:1040)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:815)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:782)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:778)
        //     at com.strobel.decompiler.ast.TypeAnalysis.doInferTypeForExpression(TypeAnalysis.java:1510)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:815)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:782)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:778)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferCall(TypeAnalysis.java:2483)
        //     at com.strobel.decompiler.ast.TypeAnalysis.doInferTypeForExpression(TypeAnalysis.java:1040)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypeForExpression(TypeAnalysis.java:815)
        //     at com.strobel.decompiler.ast.TypeAnalysis.runInference(TypeAnalysis.java:684)
        //     at com.strobel.decompiler.ast.TypeAnalysis.inferTypesForVariables(TypeAnalysis.java:593)
        //     at com.strobel.decompiler.ast.TypeAnalysis.runInference(TypeAnalysis.java:405)
        //     at com.strobel.decompiler.ast.TypeAnalysis.run(TypeAnalysis.java:95)
        //     at com.strobel.decompiler.ast.AstOptimizer.optimize(AstOptimizer.java:109)
        //     at com.strobel.decompiler.ast.AstOptimizer.optimize(AstOptimizer.java:42)
        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:206)
        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:93)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createMethodBody(AstBuilder.java:868)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createMethod(AstBuilder.java:761)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.addTypeMembers(AstBuilder.java:638)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeCore(AstBuilder.java:605)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeNoCache(AstBuilder.java:195)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createType(AstBuilder.java:162)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.addType(AstBuilder.java:137)
        //     at com.strobel.decompiler.languages.java.JavaLanguage.buildAst(JavaLanguage.java:71)
        //     at com.strobel.decompiler.languages.java.JavaLanguage.decompileType(JavaLanguage.java:59)
        //     at com.strobel.decompiler.DecompilerDriver.decompileType(DecompilerDriver.java:333)
        //     at com.strobel.decompiler.DecompilerDriver.decompileJar(DecompilerDriver.java:254)
        //     at com.strobel.decompiler.DecompilerDriver.main(DecompilerDriver.java:129)
        // 
        throw new IllegalStateException("An error occurred while decompiling this method.");
    }
    
    public static final class Instruction
    {
        @Nonnull
        private final Vector3d velocity;
        @Nullable
        private final VelocityConfig config;
        @Nonnull
        private final ChangeVelocityType type;
        
        public Instruction(@Nonnull final Vector3d velocity, @Nullable final VelocityConfig config, @Nonnull final ChangeVelocityType type) {
            this.velocity = velocity;
            this.config = config;
            this.type = type;
        }
        
        @Nonnull
        public Vector3d getVelocity() {
            return this.velocity;
        }
        
        @Nullable
        public VelocityConfig getConfig() {
            return this.config;
        }
        
        @Nonnull
        public ChangeVelocityType getType() {
            return this.type;
        }
    }
}
