use of org.spongepowered.common.interfaces.world.IMixinWorldServer in project SpongeCommon by SpongePowered.
the class MixinBlock_Collisions method initializeCollisionState.
@Override
public void initializeCollisionState(World worldIn) {
SpongeConfig<? extends GeneralConfigBase> activeConfig = ((IMixinWorldServer) worldIn).getActiveConfig();
EntityCollisionCategory collisionCat = activeConfig.getConfig().getEntityCollisionCategory();
this.setMaxCollisions(collisionCat.getMaxEntitiesWithinAABB());
String[] ids = ((BlockType) this).getId().split(":");
String modId = ids[0];
String name = ids[1];
CollisionModCategory collisionMod = collisionCat.getModList().get(modId);
if (collisionMod == null && activeConfig.getConfig().getEntityCollisionCategory().autoPopulateData()) {
collisionMod = new CollisionModCategory(modId);
collisionCat.getModList().put(modId, collisionMod);
collisionMod.getBlockList().put(name, this.getMaxCollisions());
if (activeConfig.getConfig().getEntityCollisionCategory().autoPopulateData()) {
activeConfig.save();
}
return;
} else if (collisionMod != null) {
if (!collisionMod.isEnabled()) {
this.setMaxCollisions(-1);
return;
}
// check mod overrides
Integer modCollisionMax = collisionMod.getDefaultMaxCollisions().get("blocks");
if (modCollisionMax != null) {
this.setMaxCollisions(modCollisionMax);
}
Integer blockMaxCollision = collisionMod.getBlockList().get(name);
// entity overrides
if (blockMaxCollision == null && activeConfig.getConfig().getEntityCollisionCategory().autoPopulateData()) {
collisionMod.getBlockList().put(name, this.getMaxCollisions());
} else if (blockMaxCollision != null) {
this.setMaxCollisions(blockMaxCollision);
}
}
if (this.getMaxCollisions() <= 0) {
return;
}
if (activeConfig.getConfig().getEntityCollisionCategory().autoPopulateData()) {
activeConfig.save();
}
}
use of org.spongepowered.common.interfaces.world.IMixinWorldServer in project SpongeCommon by SpongePowered.
the class MixinChunk_Collisions method allowEntityCollision.
private <T extends Entity> boolean allowEntityCollision(List<T> listToFill) {
if (this.world instanceof IMixinWorldServer) {
IMixinWorldServer spongeWorld = (IMixinWorldServer) this.world;
if (spongeWorld.isProcessingExplosion()) {
// allow explosions
return true;
}
final PhaseContext<?> phaseContext = PhaseTracker.getInstance().getCurrentContext();
LocatableBlock locatable = phaseContext.getSource(LocatableBlock.class).orElse(null);
if (locatable != null) {
BlockType blockType = locatable.getLocation().getBlockType();
IModData_Collisions spongeBlock = (IModData_Collisions) blockType;
if (spongeBlock.requiresCollisionsCacheRefresh()) {
spongeBlock.initializeCollisionState(this.world);
spongeBlock.requiresCollisionsCacheRefresh(false);
}
return !((spongeBlock.getMaxCollisions() >= 0) && (listToFill.size() >= spongeBlock.getMaxCollisions()));
}
IModData_Collisions spongeEntity = phaseContext.getSource(IModData_Collisions.class).orElse(null);
if (spongeEntity != null) {
if (spongeEntity.requiresCollisionsCacheRefresh()) {
spongeEntity.initializeCollisionState(this.world);
spongeEntity.requiresCollisionsCacheRefresh(false);
}
return !((spongeEntity.getMaxCollisions() >= 0) && (listToFill.size() >= spongeEntity.getMaxCollisions()));
}
return true;
}
return true;
}
use of org.spongepowered.common.interfaces.world.IMixinWorldServer in project SpongeCommon by SpongePowered.
the class MixinChunk_Async_Lighting method checkWorldLight.
/**
* Checks world light async.
*
* @param pos The block position
* @param neighbors A thread-safe list of surrounding neighbor chunks
* @return True if light update was successful, false if not
*/
private boolean checkWorldLight(BlockPos pos, List<Chunk> neighbors) {
boolean flag = false;
final Chunk chunk = this.getLightChunk(pos.getX() >> 4, pos.getZ() >> 4, neighbors);
if (chunk == null) {
return false;
}
if (this.world.provider.hasSkyLight()) {
flag |= ((IMixinWorldServer) this.world).updateLightAsync(EnumSkyBlock.SKY, pos, (Chunk) (Object) chunk);
}
flag = flag | ((IMixinWorldServer) this.world).updateLightAsync(EnumSkyBlock.BLOCK, pos, (Chunk) (Object) chunk);
return flag;
}
use of org.spongepowered.common.interfaces.world.IMixinWorldServer in project SpongeCommon by SpongePowered.
the class EntityActivationRange method addEntityToConfig.
public static void addEntityToConfig(World world, SpongeEntityType type, byte activationType) {
checkNotNull(world, "world");
checkNotNull(type, "type");
SpongeConfig<? extends GeneralConfigBase> config = ((IMixinWorldServer) world).getActiveConfig();
if (config == null || type == null) {
return;
}
final boolean autoPopulate = config.getConfig().getEntityActivationRange().autoPopulateData();
boolean requiresSave = false;
String entityType = "misc";
entityType = EntityActivationRange.activationTypeMappings.get(activationType);
final String entityModId = type.getModId().toLowerCase();
final String entityId = type.getName().toLowerCase();
EntityActivationRangeCategory activationCategory = config.getConfig().getEntityActivationRange();
EntityActivationModCategory entityMod = activationCategory.getModList().get(entityModId);
Integer defaultActivationRange = activationCategory.getDefaultRanges().get(entityType);
if (defaultActivationRange == null) {
defaultActivationRange = 32;
}
Integer activationRange = activationCategory.getDefaultRanges().get(entityType);
if (autoPopulate && entityMod == null) {
entityMod = new EntityActivationModCategory();
activationCategory.getModList().put(entityModId, entityMod);
requiresSave = true;
}
if (entityMod != null) {
final Integer modActivationRange = entityMod.getDefaultRanges().get(entityType);
if (autoPopulate && modActivationRange == null) {
entityMod.getDefaultRanges().put(entityType, defaultActivationRange);
requiresSave = true;
} else if (modActivationRange != null && modActivationRange > activationRange) {
activationRange = modActivationRange;
}
final Integer entityActivationRange = entityMod.getEntityList().get(entityId);
if (autoPopulate && entityActivationRange == null) {
entityMod.getEntityList().put(entityId, entityMod.getDefaultRanges().get(entityType));
requiresSave = true;
}
if (entityActivationRange != null && entityActivationRange > activationRange) {
activationRange = entityActivationRange;
}
}
// check max ranges
Integer maxRange = maxActivationRanges.get(activationType);
if (maxRange == null) {
maxActivationRanges.put(activationType, activationRange);
} else if (activationRange > maxRange) {
maxActivationRanges.put(activationType, activationRange);
}
if (autoPopulate && requiresSave) {
config.save();
}
}
use of org.spongepowered.common.interfaces.world.IMixinWorldServer in project SpongeCommon by SpongePowered.
the class TileEntityActivation method addTileEntityToConfig.
public static void addTileEntityToConfig(World world, SpongeTileEntityType type) {
checkNotNull(world, "world");
checkNotNull(type, "type");
SpongeConfig<? extends GeneralConfigBase> config = ((IMixinWorldServer) world).getActiveConfig();
if (config == null || type == null || !config.getConfig().getTileEntityActivationRange().autoPopulateData()) {
return;
}
boolean requiresSave = false;
final String tileModId = type.getModId().toLowerCase();
TileEntityActivationCategory activationCategory = config.getConfig().getTileEntityActivationRange();
TileEntityActivationModCategory tileEntityMod = activationCategory.getModList().get(tileModId);
int defaultRange = activationCategory.getDefaultBlockRange();
int defaultTickRate = activationCategory.getDefaultTickRate();
if (tileEntityMod == null) {
tileEntityMod = new TileEntityActivationModCategory(tileModId);
activationCategory.getModList().put(tileModId, tileEntityMod);
requiresSave = true;
}
if (tileEntityMod != null) {
// check for tileentity range overrides
final String tileId = type.getName().toLowerCase();
Integer tileEntityActivationRange = tileEntityMod.getTileEntityRangeList().get(tileId);
Integer modDefaultRange = tileEntityMod.getDefaultBlockRange();
if (modDefaultRange == null) {
modDefaultRange = defaultRange;
}
if (tileEntityActivationRange == null) {
tileEntityMod.getTileEntityRangeList().put(tileId, modDefaultRange);
requiresSave = true;
}
// check for tileentity tick rate overrides
Integer modDefaultTickRate = tileEntityMod.getDefaultTickRate();
if (modDefaultTickRate == null) {
modDefaultTickRate = defaultTickRate;
}
Integer tileEntityActivationTickRate = tileEntityMod.getTileEntityTickRateList().get(tileId);
if (tileEntityActivationTickRate == null) {
tileEntityMod.getTileEntityTickRateList().put(tileId, modDefaultTickRate);
requiresSave = true;
}
}
if (requiresSave) {
config.save();
}
}
Aggregations