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

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

import javax.annotation.Nonnull;

public class PhysicsBodyStateUpdaterRK4 extends PhysicsBodyStateUpdater
{
    private final PhysicsBodyState state;
    
    public PhysicsBodyStateUpdaterRK4() {
        this.state = new PhysicsBodyState();
    }
    
    @Override
    public void update(@Nonnull final PhysicsBodyState before, @Nonnull final PhysicsBodyState after, final double mass, final double dt, final boolean onGround, @Nonnull final ForceProvider[] forceProvider) {
        final double halfTime = dt * 0.5;
        this.computeAcceleration(before, onGround, forceProvider, mass, halfTime);
        this.assignAcceleration(after);
        this.updateVelocity(before, this.state, halfTime);
        PhysicsBodyStateUpdater.updatePositionBeforeVelocity(before, this.state, halfTime);
        this.computeAcceleration(this.state, onGround, forceProvider, mass, halfTime);
        this.addAcceleration(after, 2.0);
        this.updateVelocity(before, this.state, halfTime);
        PhysicsBodyStateUpdater.updatePositionAfterVelocity(before, this.state, halfTime);
        this.computeAcceleration(this.state, onGround, forceProvider, mass, halfTime);
        this.addAcceleration(after, 2.0);
        this.updateVelocity(before, this.state, dt);
        PhysicsBodyStateUpdater.updatePositionAfterVelocity(before, this.state, dt);
        this.computeAcceleration(this.state, onGround, forceProvider, mass, dt);
        this.addAcceleration(after);
        this.convertAccelerationToVelocity(before, after, dt / 6.0);
        PhysicsBodyStateUpdater.updatePositionAfterVelocity(before, after, dt);
    }
}
