use of org.spongepowered.common.interfaces.world.IMixinWorld in project SpongeCommon by SpongePowered.
the class EntityActivationRange method initializeEntityActivationState.
/**
* These entities are excluded from Activation range checks.
*
* @param entity Entity to check
* @return boolean If it should always tick.
*/
public static boolean initializeEntityActivationState(Entity entity) {
if (((IMixinWorld) entity.world).isFake()) {
return true;
}
// types that should always be active
if (entity instanceof EntityPlayer && !SpongeImplHooks.isFakePlayer(entity) || entity instanceof EntityThrowable || entity instanceof EntityDragon || entity instanceof MultiPartEntityPart || entity instanceof EntityWither || entity instanceof EntityFireball || entity instanceof EntityWeatherEffect || entity instanceof EntityTNTPrimed || entity instanceof EntityEnderCrystal || entity instanceof EntityFireworkRocket || // Always tick falling blocks
entity instanceof EntityFallingBlock) {
return true;
}
EntityActivationRangeCategory config = ((IMixinWorldServer) entity.world).getActiveConfig().getConfig().getEntityActivationRange();
EntityType type = ((org.spongepowered.api.entity.Entity) entity).getType();
IModData_Activation spongeEntity = (IModData_Activation) entity;
if (type == EntityTypes.UNKNOWN || !(type instanceof SpongeEntityType)) {
return false;
}
final SpongeEntityType spongeType = (SpongeEntityType) type;
final byte activationType = spongeEntity.getActivationType();
if (!spongeType.isActivationRangeInitialized()) {
addEntityToConfig(entity.world, spongeType, activationType);
spongeType.setActivationRangeInitialized(true);
}
EntityActivationModCategory entityMod = config.getModList().get(spongeType.getModId().toLowerCase());
int defaultActivationRange = config.getDefaultRanges().get(activationTypeMappings.get(activationType));
if (entityMod == null) {
// use default activation range
spongeEntity.setActivationRange(defaultActivationRange);
if (defaultActivationRange <= 0) {
return true;
}
return false;
} else if (!entityMod.isEnabled()) {
spongeEntity.setActivationRange(defaultActivationRange);
return true;
}
Integer defaultModActivationRange = entityMod.getDefaultRanges().get(activationTypeMappings.get(activationType));
Integer entityActivationRange = entityMod.getEntityList().get(type.getName().toLowerCase());
if (defaultModActivationRange != null && entityActivationRange == null) {
spongeEntity.setActivationRange(defaultModActivationRange);
if (defaultModActivationRange <= 0) {
return true;
}
return false;
} else if (entityActivationRange != null) {
spongeEntity.setActivationRange(entityActivationRange);
if (entityActivationRange <= 0) {
return true;
}
}
return false;
}
use of org.spongepowered.common.interfaces.world.IMixinWorld in project SpongeForge by SpongePowered.
the class SpongeForgeEventFactory method callWorldSaveEvent.
private static SaveWorldEvent callWorldSaveEvent(Event event) {
SaveWorldEvent spongeEvent = (SaveWorldEvent) event;
// Since Forge only uses a single save handler, we need to make sure to pass the overworld's handler.
// This makes sure that mods dont attempt to save/read their data from the wrong location.
((IMixinWorld) spongeEvent.getTargetWorld()).setCallingWorldEvent(true);
((IMixinEventBus) MinecraftForge.EVENT_BUS).post(new WorldEvent.Save((net.minecraft.world.World) spongeEvent.getTargetWorld()), true);
((IMixinWorld) spongeEvent.getTargetWorld()).setCallingWorldEvent(false);
return spongeEvent;
}
Aggregations