/** * These entities are excluded from Activation range checks. * * @param entity * @param world * @return boolean If it should always tick. */ public static boolean initializeEntityActivationState(Entity entity, SpigotWorldConfig config) { if ( ( entity.activationType == 3 && config.miscActivationRange == 0 ) || ( entity.activationType == 2 && config.animalActivationRange == 0 ) || ( entity.activationType == 1 && config.monsterActivationRange == 0 ) || entity instanceof EntityHuman || entity instanceof EntityProjectile || entity instanceof EntityEnderDragon || entity instanceof EntityComplexPart || entity instanceof EntityWither || entity instanceof EntityFireball || entity instanceof EntityWeather || entity instanceof EntityTNTPrimed || entity instanceof EntityEnderCrystal || entity instanceof EntityFireworks ) { return true; } return false; }
@Override public void setFireworkMeta(FireworkMeta meta) { item.setItemMeta(meta); // Copied from EntityFireworks constructor, update firework lifetime/power getHandle().expectedLifespan = 10 * (1 + meta.getPower()) + random.nextInt(6) + random.nextInt(7); getHandle().getDataWatcher().markDirty(EntityFireworks.FIREWORK_ITEM); }
public static void setFireworksTicksFlown(Firework firework, int ticks) { EntityFireworks entityFirework = ((CraftFirework) firework).getHandle(); entityFirework.ticksFlown = ticks; }
@Override public EntityFireworks getHandle() { return (EntityFireworks) entity; }
public static void explodeFirework(Firework firework) { EntityFireworks nmsFirework = ((CraftFirework)firework).getHandle(); nmsFirework.ticksFlown = 1; nmsFirework.expectedLifespan = 2; }
/** * Checks if the entity is active for this tick. * * @param entity * @return */ public static boolean checkIfActive(Entity entity) { SpigotTimings.checkIfActiveTimer.startTiming(); // Never safe to skip fireworks or entities not yet added to chunk // PAIL: inChunk if ( !entity.aa || entity instanceof EntityFireworks ) { SpigotTimings.checkIfActiveTimer.stopTiming(); 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.ticksLived % 4 == 0 && !checkEntityImmunities( entity ) ) { isActive = false; } int x = MathHelper.floor( entity.locX ); int z = MathHelper.floor( entity.locZ ); // Make sure not on edge of unloaded chunk Chunk chunk = entity.world.getChunkIfLoaded( x >> 4, z >> 4 ); if ( isActive && !( chunk != null && chunk.areNeighborsLoaded( 1 ) ) ) { isActive = false; } SpigotTimings.checkIfActiveTimer.stopTiming(); return isActive; }