secreterproject/src/main/java/net/pivipi/ball/Ball.java

56 lines
1.4 KiB
Java
Raw Normal View History

package net.pivipi.ball;
2024-07-05 15:13:16 +02:00
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;
2024-07-05 15:13:16 +02:00
import net.pivipi.world.Stadium;
public class Ball extends Entity {
private long lastTick;
2024-07-05 15:13:16 +02:00
private final Physics physics = new Physics(this);
2024-07-05 15:13:16 +02:00
public final Stadium stadium;
2024-07-05 15:13:16 +02:00
public Ball(Block block, Stadium stadium) {
super(EntityType.FALLING_BLOCK); // not block display because its movement lags for some reason
this.setNoGravity(true);
2024-07-05 15:13:16 +02:00
this.hasPhysics = true;
this.editEntityMeta(FallingBlockMeta.class, meta -> {
meta.setBlock(block);
});
2024-07-05 15:13:16 +02:00
this.stadium = stadium;
}
2024-07-05 15:13:16 +02:00
public Ball(Stadium stadium) {
this(Block.WHITE_WOOL, stadium);
}
2024-07-05 15:13:16 +02:00
public void update(long time) {
if (this.lastTick == 0) {
this.lastTick = time;
}
long delay = time - this.lastTick;
2024-07-06 16:15:39 +02:00
physics.process(delay / 1000.0, stadium.players);
this.lastTick = time;
}
2024-07-05 15:13:16 +02:00
public void addVelocity(Vec velocity) {
physics.addVelocity(velocity);
}
public void addPos(Vec vec) {
this.teleport(this.getPosition().add(vec));
}
}