2024-07-04 18:04:46 +02:00
|
|
|
package net.pivipi.ball;
|
|
|
|
|
2024-07-05 15:13:16 +02:00
|
|
|
import net.minestom.server.coordinate.Vec;
|
2024-07-04 18:04:46 +02:00
|
|
|
import net.minestom.server.entity.Entity;
|
|
|
|
import net.minestom.server.entity.EntityType;
|
|
|
|
import net.minestom.server.entity.metadata.other.FallingBlockMeta;
|
2024-07-05 15:13:16 +02:00
|
|
|
import net.minestom.server.event.player.PlayerDisconnectEvent;
|
2024-07-04 18:04:46 +02:00
|
|
|
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;
|
2024-07-04 18:04:46 +02:00
|
|
|
|
|
|
|
public class Ball extends Entity {
|
|
|
|
private long lastTick;
|
2024-07-05 15:13:16 +02:00
|
|
|
|
2024-07-04 18:04:46 +02:00
|
|
|
private final Physics physics = new Physics(this);
|
2024-07-05 15:13:16 +02:00
|
|
|
public final Stadium stadium;
|
2024-07-04 18:04:46 +02:00
|
|
|
|
2024-07-05 15:13:16 +02:00
|
|
|
public Ball(Block block, Stadium stadium) {
|
2024-07-04 18:04:46 +02:00
|
|
|
super(EntityType.FALLING_BLOCK); // not block display because its movement lags for some reason
|
|
|
|
|
|
|
|
this.setNoGravity(true);
|
|
|
|
this.setGlowing(true);
|
2024-07-05 15:13:16 +02:00
|
|
|
this.hasPhysics = true;
|
2024-07-04 18:04:46 +02:00
|
|
|
|
|
|
|
this.editEntityMeta(FallingBlockMeta.class, meta -> {
|
|
|
|
meta.setBlock(block);
|
|
|
|
});
|
2024-07-05 15:13:16 +02:00
|
|
|
|
|
|
|
this.stadium = stadium;
|
2024-07-04 18:04:46 +02:00
|
|
|
}
|
|
|
|
|
2024-07-05 15:13:16 +02:00
|
|
|
public Ball(Stadium stadium) {
|
|
|
|
this(Block.WHITE_WOOL, stadium);
|
2024-07-04 18:04:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-07-05 15:13:16 +02:00
|
|
|
public void update(long time) {
|
2024-07-04 18:04:46 +02:00
|
|
|
if (this.lastTick == 0) {
|
|
|
|
this.lastTick = time;
|
|
|
|
}
|
|
|
|
|
|
|
|
long delay = time - this.lastTick;
|
|
|
|
|
2024-07-05 15:13:16 +02:00
|
|
|
physics.applyPhysics(delay / 1000.0, stadium.players);
|
2024-07-04 18:04:46 +02:00
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
2024-07-04 18:04:46 +02:00
|
|
|
|
|
|
|
}
|