secreterproject/src/main/java/net/pivipi/ball/Ball.java
2024-07-06 16:15:39 +02:00

55 lines
1.4 KiB
Java

package net.pivipi.ball;
import net.minestom.server.coordinate.Vec;
import net.minestom.server.entity.Entity;
import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.metadata.other.FallingBlockMeta;
import net.minestom.server.instance.block.Block;
import net.pivipi.physics.Physics;
import net.pivipi.world.Stadium;
public class Ball extends Entity {
private long lastTick;
private final Physics physics = new Physics(this);
public final Stadium stadium;
public Ball(Block block, Stadium stadium) {
super(EntityType.FALLING_BLOCK); // not block display because its movement lags for some reason
this.setNoGravity(true);
this.hasPhysics = true;
this.editEntityMeta(FallingBlockMeta.class, meta -> {
meta.setBlock(block);
});
this.stadium = stadium;
}
public Ball(Stadium stadium) {
this(Block.WHITE_WOOL, stadium);
}
public void update(long time) {
if (this.lastTick == 0) {
this.lastTick = time;
}
long delay = time - this.lastTick;
physics.process(delay / 1000.0, stadium.players);
this.lastTick = time;
}
public void addVelocity(Vec velocity) {
physics.addVelocity(velocity);
}
public void addPos(Vec vec) {
this.teleport(this.getPosition().add(vec));
}
}