secreterproject/src/main/java/net/pivipi/physics/aabb/AABBPlayer.java
2024-07-09 13:55:05 +02:00

44 lines
1.3 KiB
Java

package net.pivipi.physics.aabb;
import java.util.UUID;
import org.jetbrains.annotations.NotNull;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.coordinate.Vec;
import net.minestom.server.entity.Player;
import net.minestom.server.network.PlayerProvider;
import net.minestom.server.network.player.PlayerConnection;
public class AABBPlayer extends Player {
protected AABB aabb = new AABB(Vec.ZERO, Vec.ZERO);
private Pos lastPosition = Pos.ZERO;
private long lastUpdate;
private double delta;
private Pos movement;
public AABBPlayer(@NotNull UUID uuid, @NotNull String username, @NotNull PlayerConnection playerConnection) {
super(uuid, username, playerConnection);
// TODO Auto-generated constructor stub
}
public AABB getAabb() {
aabb.min = this.getPosition().sub(this.getBoundingBox().width() / 2, 0, this.getBoundingBox().depth() / 2).asVec();
aabb.max = this.getPosition().add(this.getBoundingBox().width() / 2, this.getBoundingBox().height(), this.getBoundingBox().depth() / 2).asVec();
aabb.velocity = this.getVelocity().mul(delta).add(movement);
return aabb;
}
@Override
public void update(long time) {
super.update(time);
this.movement = this.getPosition().sub(lastPosition);
this.lastPosition = this.getPosition();
this.delta = (time - lastUpdate) / 1000.0;
this.lastUpdate = time;
}
}