Search in sources :

Example 1 with TickBase

use of thpmc.vanilla_source.api.entity.TickBase in project VanillaSource by TheHollowPlanetMC.

the class TickRunner method run.

@Override
public void run() {
    if (beforeTime + TIME - 20 > System.currentTimeMillis())
        return;
    if (isStopped)
        return;
    if (i % TPS == 0) {
        long time = System.currentTimeMillis();
        tps = ((double) Math.round((20.0 / (((double) (time - beforeTime)) / 1000.0)) * 10)) / 10;
        beforeTime = time;
    }
    currentThread = Thread.currentThread();
    this.lastTickMS = System.currentTimeMillis();
    // Should remove check
    entities.removeIf(TickBase::shouldRemove);
    tickOnlyEntities.removeIf(TickBase::shouldRemove);
    // Add entities
    if (addEntities.size() != 0) {
        try {
            ADD_LOCK.lock();
            for (TickBase entity : addEntities) {
                if (entity instanceof EngineEntity) {
                    entities.add((EngineEntity) entity);
                } else {
                    tickOnlyEntities.add(entity);
                }
            }
            addEntities.clear();
        } finally {
            ADD_LOCK.unlock();
        }
    }
    // tick
    tickOnlyEntities.forEach(TickBase::tick);
    entities.forEach(TickBase::tick);
    // Tracker
    for (EnginePlayer enginePlayer : EnginePlayer.getAllPlayers()) {
        EntityTracker entityTracker = getEntityTracker(enginePlayer);
        entityTracker.tick(entities);
    }
    if (i % 40 == 0) {
        // Remove offline player
        trackerMap.keySet().removeIf(enginePlayer -> !enginePlayer.getBukkitPlayer().isOnline());
    }
    entities.forEach(EngineEntity::setPreviousPosition);
    i++;
}
Also used : EngineEntity(thpmc.vanilla_source.api.entity.EngineEntity) TickBase(thpmc.vanilla_source.api.entity.TickBase) EnginePlayer(thpmc.vanilla_source.api.player.EnginePlayer)

Aggregations

EngineEntity (thpmc.vanilla_source.api.entity.EngineEntity)1 TickBase (thpmc.vanilla_source.api.entity.TickBase)1 EnginePlayer (thpmc.vanilla_source.api.player.EnginePlayer)1