Java Code Examples for net.minecraft.server.MinecraftServer#currentTick()

The following examples show how to use net.minecraft.server.MinecraftServer#currentTick() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActivationRange.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Find what entities are in range of the players in the world and set
 * active if in range.
 *
 * @param world
 */
public static void activateEntities(World world) {
    final int miscActivationRange = world.spigotConfig.miscActivationRange;
    final int animalActivationRange = world.spigotConfig.animalActivationRange;
    final int monsterActivationRange = world.spigotConfig.monsterActivationRange;

    int maxRange = Math.max(monsterActivationRange, animalActivationRange);
    maxRange = Math.max(maxRange, miscActivationRange);
    maxRange = Math.min((world.spigotConfig.viewDistance << 4) - 8, maxRange);

    for (EntityPlayer player : world.playerEntities) {

        player.activatedTick = MinecraftServer.currentTick;
        maxBB = player.getEntityBoundingBox().grow(maxRange, 256, maxRange);
        miscBB = player.getEntityBoundingBox().grow(miscActivationRange, 256, miscActivationRange);
        animalBB = player.getEntityBoundingBox().grow(animalActivationRange, 256, animalActivationRange);
        monsterBB = player.getEntityBoundingBox().grow(monsterActivationRange, 256, monsterActivationRange);

        int i = MathHelper.floor(maxBB.minX / 16.0D);
        int j = MathHelper.floor(maxBB.maxX / 16.0D);
        int k = MathHelper.floor(maxBB.minZ / 16.0D);
        int l = MathHelper.floor(maxBB.maxZ / 16.0D);

        for (int i1 = i; i1 <= j; ++i1) {
            for (int j1 = k; j1 <= l; ++j1) {
                if (world.getWorld().isChunkLoaded(i1, j1)) {
                    activateChunkEntities(world.getChunkFromChunkCoords(i1, j1));
                }
            }
        }
    }
}
 
Example 2
Source File: ActivationRange.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks for the activation state of all entities in this chunk.
 *
 * @param chunk
 */
private static void activateChunkEntities(Chunk chunk) {
    for (ClassInheritanceMultiMap<Entity> slice : chunk.entityLists) {
        for (Entity entity : slice) {
            if (entity == null) {
                continue;
            }
            if (MinecraftServer.currentTick > entity.activatedTick) {
                if (entity.defaultActivationState) {
                    entity.activatedTick = MinecraftServer.currentTick;
                    continue;
                }
                switch (entity.activationType) {
                    case 1:
                        if (monsterBB.intersects(entity.getEntityBoundingBox())) {
                            entity.activatedTick = MinecraftServer.currentTick;
                        }
                        break;
                    case 2:
                        if (animalBB.intersects(entity.getEntityBoundingBox())) {
                            entity.activatedTick = MinecraftServer.currentTick;
                        }
                        break;
                    case 3:
                    default:
                        if (miscBB.intersects(entity.getEntityBoundingBox())) {
                            entity.activatedTick = MinecraftServer.currentTick;
                        }
                }
            }
        }
    }
}
 
Example 3
Source File: ActivationRange.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks if the entity is active for this tick.
 *
 * @param entity
 * @return
 */
public static boolean checkIfActive(Entity entity) {
    // Never safe to skip fireworks or entities not yet added to chunk
    // PAIL: inChunk - boolean under datawatchers
    if (!entity.addedToChunk || entity instanceof EntityFireworkRocket) {
        return true;
    }

    boolean isActive = entity.activatedTick >= MinecraftServer.currentTick || entity.defaultActivationState;

    // Should this entity tick?
    if (!isActive) {
        if ((MinecraftServer.currentTick - entity.activatedTick - 1) % 20 == 0) {
            // Check immunities every 20 ticks.
            if (checkEntityImmunities(entity)) {
                // Triggered some sort of immunity, give 20 full ticks before we check again.
                entity.activatedTick = MinecraftServer.currentTick + 20;
            }
            isActive = true;
        }
        // Add a little performance juice to active entities. Skip 1/4 if not immune.
    } else if (!entity.defaultActivationState && entity.ticksExisted % 4 == 0 && !checkEntityImmunities(entity)) {
        isActive = false;
    }
    int x = MathHelper.floor(entity.posX);
    int z = MathHelper.floor(entity.posZ);
    // Make sure not on edge of unloaded chunk
    Chunk chunk = entity.world.getChunkIfLoaded(x >> 4, z >> 4);
    if (isActive && !(chunk != null)) {
        isActive = false;
    }
    return isActive;
}
 
Example 4
Source File: ActivationRange.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks for the activation state of all entities in this chunk.
 *
 * @param chunk
 */
private static void activateChunkEntities(Chunk chunk)
{
    for ( List<Entity> slice : chunk.entityLists )
    {
        for ( Entity entity : slice )
        {
            if ( MinecraftServer.currentTick > entity.activatedTick )
            {
                if ( entity.defaultActivationState )
                {
                    entity.activatedTick = MinecraftServer.currentTick;
                    continue;
                }
                switch ( entity.activationType )
                {
                    case 1:
                        if ( monsterBB.intersectsWith( entity.boundingBox ) )
                        {
                            entity.activatedTick = MinecraftServer.currentTick;
                        }
                        break;
                    case 2:
                        if ( animalBB.intersectsWith( entity.boundingBox ) )
                        {
                            entity.activatedTick = MinecraftServer.currentTick;
                        }
                        break;
                    case 3:
                    default:
                        if ( miscBB.intersectsWith( entity.boundingBox ) )
                        {
                            entity.activatedTick = MinecraftServer.currentTick;
                        }
                }
            }
        }
    }
}
 
Example 5
Source File: ActivationRange.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Find what entities are in range of the players in the world and set
 * active if in range.
 *
 * @param world
 */
public static void activateEntities(World world)
{
    SpigotTimings.entityActivationCheckTimer.startTiming();
    // Cauldron start - proxy world support
    final int miscActivationRange = world.getSpigotConfig().miscActivationRange;
    final int animalActivationRange = world.getSpigotConfig().animalActivationRange;
    final int monsterActivationRange = world.getSpigotConfig().monsterActivationRange;
    // Cauldron end

    int maxRange = Math.max( monsterActivationRange, animalActivationRange );
    maxRange = Math.max( maxRange, miscActivationRange );
    maxRange = Math.min( ( world.getSpigotConfig().viewDistance << 4 ) - 8, maxRange ); // Cauldron

    for ( Entity player : new ArrayList<Entity>( world.playerEntities ) )
    {

        player.activatedTick = MinecraftServer.currentTick;
        growBB( maxBB, player.boundingBox, maxRange, 256, maxRange );
        growBB( miscBB, player.boundingBox, miscActivationRange, 256, miscActivationRange );
        growBB( animalBB, player.boundingBox, animalActivationRange, 256, animalActivationRange );
        growBB( monsterBB, player.boundingBox, monsterActivationRange, 256, monsterActivationRange );

        int i = MathHelper.floor_double( maxBB.minX / 16.0D );
        int j = MathHelper.floor_double( maxBB.maxX / 16.0D );
        int k = MathHelper.floor_double( maxBB.minZ / 16.0D );
        int l = MathHelper.floor_double( maxBB.maxZ / 16.0D );

        for ( int i1 = i; i1 <= j; ++i1 )
        {
            for ( int j1 = k; j1 <= l; ++j1 )
            {
                if ( world.getWorld().isChunkLoaded( i1, j1 ) )
                {
                    activateChunkEntities( world.getChunkFromChunkCoords( i1, j1 ) );
                }
            }
        }
    }
    SpigotTimings.entityActivationCheckTimer.stopTiming();
}
 
Example 6
Source File: ActivationRange.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Checks if the entity is active for this tick.
 *
 * @param entity
 * @return
 */
public static boolean checkIfActive(Entity entity)
{
    SpigotTimings.checkIfActiveTimer.startTiming();

    boolean isActive = entity.activatedTick >= MinecraftServer.currentTick || entity.defaultActivationState;

    // Should this entity tick?
    if ( !isActive )
    {
        if ( ( MinecraftServer.currentTick - entity.activatedTick - 1 ) % 20 == 0 )
        {
            // Check immunities every 20 ticks.
            if ( checkEntityImmunities( entity ) )
            {
                // Triggered some sort of immunity, give 20 full ticks before we check again.
                entity.activatedTick = MinecraftServer.currentTick + 20;
            }
            isActive = true;
        }
        // Add a little performance juice to active entities. Skip 1/4 if not immune.
    } else if ( !entity.defaultActivationState && entity.ticksExisted % 4 == 0 && !checkEntityImmunities( entity ) )
    {
        isActive = false;
    }

    // Cauldron - we check for entities in forced chunks in World.updateEntityWithOptionalForce
    // Make sure not on edge of unloaded chunk
    int x = net.minecraft.util.MathHelper.floor_double( entity.posX );
    int z = net.minecraft.util.MathHelper.floor_double( entity.posZ );
    
    if ( isActive && !(entity.worldObj.isActiveBlockCoord(x, z) || entity.worldObj.doChunksNearChunkExist( x, 0, z, 16 ) )) {
        isActive = false;
    }
    
    if(entity instanceof EntityFireworkRocket || !entity.isAddedToChunk()) // Force continued activation for teleporting entities
    {
    	isActive = true;
    }
    SpigotTimings.checkIfActiveTimer.stopTiming();
    return isActive;
}