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.event.player.PlayerDisconnectEvent; 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.setGlowing(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.applyPhysics(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)); } }