use of net.minecraft.world.entity.projectile.FireworkRocketEntity in project SpongeCommon by SpongePowered.
the class EntityActivationRange method checkIfActive.
/**
* Checks if the entity is active for this tick.
*
* @param entity The entity to check for activity
* @return Whether the given entity should be active
*/
public static boolean checkIfActive(final Entity entity) {
// Never safe to skip fireworks or entities not yet added to chunk
if (entity instanceof Player || entity.level.isClientSide() || !entity.inChunk || entity instanceof FireworkRocketEntity) {
return true;
}
final LevelChunkBridge activeChunk = ((ActiveChunkReferantBridge) entity).bridge$getActiveChunk();
if (activeChunk == null) {
// Should never happen but just in case for mods, always tick
return true;
}
if (!activeChunk.bridge$isActive()) {
return false;
}
// If in forced chunk or is player
if (activeChunk.bridge$isPersistedChunk() || ((PlatformEntityBridge) entity).bridge$isFakePlayer() && entity instanceof ServerPlayer) {
return true;
}
final long currentTick = SpongeCommon.server().getTickCount();
final ActivationCapabilityBridge spongeEntity = (ActivationCapabilityBridge) entity;
boolean isActive = spongeEntity.activation$getActivatedTick() >= currentTick || spongeEntity.activation$getDefaultActivationState();
// Should this entity tick?
if (!isActive) {
if ((currentTick - spongeEntity.activation$getActivatedTick() - 1) % 20 == 0) {
// Check immunities every 20 ticks.
if (EntityActivationRange.checkEntityImmunities(entity)) {
// Triggered some sort of immunity, give 20 full ticks before we check again.
spongeEntity.activation$setActivatedTick(currentTick + 20);
}
isActive = true;
}
// Add a little performance juice to active entities. Skip 1/4 if not immune.
} else if (!spongeEntity.activation$getDefaultActivationState() && entity.tickCount % 4 == 0 && !EntityActivationRange.checkEntityImmunities(entity)) {
isActive = false;
}
if (isActive && !activeChunk.bridge$areNeighborsLoaded()) {
isActive = false;
}
return isActive;
}
use of net.minecraft.world.entity.projectile.FireworkRocketEntity in project SpongeCommon by SpongePowered.
the class EntityActivationRange method initializeEntityActivationState.
/**
* Initialize entity activation state.
*
* @param entity Entity to check
*/
public static void initializeEntityActivationState(final Entity entity) {
final ActivationCapabilityBridge spongeEntity = (ActivationCapabilityBridge) entity;
if (entity.level.isClientSide()) {
return;
}
// types that should always be active
if (entity instanceof Player && !((PlatformEntityBridge) entity).bridge$isFakePlayer() || entity instanceof ThrowableProjectile || entity instanceof EnderDragon || entity instanceof EnderDragonPart || entity instanceof WitherBoss || entity instanceof AbstractHurtingProjectile || entity instanceof LightningBolt || entity instanceof PrimedTnt || entity instanceof Painting || entity instanceof EndCrystal || entity instanceof FireworkRocketEntity || // Always tick falling blocks
entity instanceof FallingBlockEntity) {
return;
}
final InheritableConfigHandle<WorldConfig> configAdapter = SpongeGameConfigs.getForWorld(entity.level);
final EntityActivationRangeCategory config = configAdapter.get().entityActivationRange;
final EntityTypeBridge type = (EntityTypeBridge) entity.getType();
final ResourceLocation key = EntityType.getKey(entity.getType());
final byte activationType = spongeEntity.activation$getActivationType();
final String activationTypeName = EntityActivationRange.activationTypeMappings.getOrDefault(activationType, "misc");
if (!type.bridge$isActivationRangeInitialized()) {
EntityActivationRange.addEntityToConfig(config.autoPopulate, key, activationType, activationTypeName);
type.bridge$setActivationRangeInitialized(true);
}
final EntityActivationRangeCategory.ModSubCategory entityMod = config.mods.get(key.getNamespace());
final int defaultActivationRange = config.globalRanges.get(activationTypeName);
if (entityMod == null) {
// use default activation range
spongeEntity.activation$setActivationRange(defaultActivationRange);
if (defaultActivationRange > 0) {
spongeEntity.activation$setDefaultActivationState(false);
}
} else {
if (!entityMod.enabled) {
spongeEntity.activation$setDefaultActivationState(true);
return;
}
final Integer defaultModActivationRange = entityMod.defaultRanges.get(activationTypeName);
final Integer entityActivationRange = entityMod.entities.get(key.getPath());
if (defaultModActivationRange != null && entityActivationRange == null) {
spongeEntity.activation$setActivationRange(defaultModActivationRange);
if (defaultModActivationRange > 0) {
spongeEntity.activation$setDefaultActivationState(false);
}
} else if (entityActivationRange != null) {
spongeEntity.activation$setActivationRange(entityActivationRange);
if (entityActivationRange > 0) {
spongeEntity.activation$setDefaultActivationState(false);
}
}
}
}
Aggregations