Search in sources :

Example 1 with EntityMinecartAbstract

use of cn.nukkit.entity.item.EntityMinecartAbstract in project Nukkit by Nukkit.

the class BlockRailDetector method updateState.

protected void updateState() {
    boolean wasPowered = isActive();
    boolean isPowered = false;
    for (Entity entity : level.getNearbyEntities(new SimpleAxisAlignedBB(getFloorX() + 0.125D, getFloorY(), getFloorZ() + 0.125D, getFloorX() + 0.875D, getFloorY() + 0.525D, getFloorZ() + 0.875D))) {
        if (entity instanceof EntityMinecartAbstract) {
            isPowered = true;
        }
    }
    if (isPowered && !wasPowered) {
        setActive(true);
        level.scheduleUpdate(this, this, 0);
        level.scheduleUpdate(this, this.down(), 0);
    }
    if (!isPowered && wasPowered) {
        setActive(false);
        level.scheduleUpdate(this, this, 0);
        level.scheduleUpdate(this, this.down(), 0);
    }
    level.updateComparatorOutputLevel(this);
}
Also used : Entity(cn.nukkit.entity.Entity) EntityMinecartAbstract(cn.nukkit.entity.item.EntityMinecartAbstract) SimpleAxisAlignedBB(cn.nukkit.math.SimpleAxisAlignedBB)

Aggregations

Entity (cn.nukkit.entity.Entity)1 EntityMinecartAbstract (cn.nukkit.entity.item.EntityMinecartAbstract)1 SimpleAxisAlignedBB (cn.nukkit.math.SimpleAxisAlignedBB)1