use of org.spongepowered.common.interfaces.world.IMixinWorldServer in project SpongeCommon by SpongePowered.
the class SpongeHooks method getActiveConfig.
public static SpongeConfig<? extends GeneralConfigBase> getActiveConfig(Path dimensionPath, String worldFolder) {
if (dimensionPath == null) {
// If no dimension type, go global
return SpongeImpl.getGlobalConfig();
}
if (worldFolder != null) {
final Optional<org.spongepowered.api.world.World> optWorld = SpongeImpl.getGame().getServer().getWorld(worldFolder);
// If this is a loaded world then we only return configs on the loaded objects. Don't go to disk.
if (optWorld.isPresent()) {
return ((IMixinWorldServer) optWorld.get()).getActiveConfig();
}
}
// No in-memory config objects, lookup from disk.
final Path dimConfPath = dimensionPath.resolve("dimension.conf");
if (worldFolder != null) {
final Path worldConfPath = dimensionPath.resolve(worldFolder).resolve("world.conf");
final SpongeConfig<WorldConfig> worldConfig = new SpongeConfig<>(SpongeConfig.Type.WORLD, worldConfPath, SpongeImpl.ECOSYSTEM_ID);
if (worldConfig.getConfig().isConfigEnabled()) {
return worldConfig;
}
}
final SpongeConfig<DimensionConfig> dimConfig = new SpongeConfig<>(SpongeConfig.Type.DIMENSION, dimConfPath, SpongeImpl.ECOSYSTEM_ID);
if (dimConfig.getConfig().isConfigEnabled()) {
return dimConfig;
}
// Neither in-memory or on-disk enabled configs. Go global.
return SpongeImpl.getGlobalConfig();
}
use of org.spongepowered.common.interfaces.world.IMixinWorldServer in project SpongeCommon by SpongePowered.
the class MixinChunkProviderServer method tick.
/**
* @author blood - October 20th, 2016
* @reason Refactors entire method to not use the droppedChunksSet by
* simply looping through all loaded chunks and determining whether it
* can unload or not.
*
* @return true if unload queue was processed
*/
@Overwrite
public boolean tick() {
if (!this.world.disableLevelSaving) {
((IMixinWorldServer) this.world).getTimingsHandler().doChunkUnload.startTiming();
Iterator<Chunk> iterator = this.id2ChunkMap.values().iterator();
int chunksUnloaded = 0;
long now = System.currentTimeMillis();
while (chunksUnloaded < this.maxChunkUnloads && iterator.hasNext()) {
Chunk chunk = iterator.next();
IMixinChunk spongeChunk = (IMixinChunk) chunk;
if (chunk != null && chunk.unloadQueued && !spongeChunk.isPersistedChunk()) {
if (this.getChunkUnloadDelay() > 0) {
if ((now - spongeChunk.getScheduledForUnload()) < this.chunkUnloadDelay) {
continue;
}
spongeChunk.setScheduledForUnload(-1);
}
chunk.onUnload();
this.saveChunkData(chunk);
this.saveChunkExtraData(chunk);
iterator.remove();
chunksUnloaded++;
}
}
((IMixinWorldServer) this.world).getTimingsHandler().doChunkUnload.stopTiming();
}
this.chunkLoader.chunkTick();
return false;
}
use of org.spongepowered.common.interfaces.world.IMixinWorldServer in project SpongeCommon by SpongePowered.
the class SpongeHooks method getActiveConfig.
public static SpongeConfig<? extends GeneralConfigBase> getActiveConfig(WorldServer world, boolean refresh) {
final IMixinWorldServer mixinWorldServer = (IMixinWorldServer) world;
SpongeConfig<? extends GeneralConfigBase> activeConfig = mixinWorldServer.getActiveConfig();
if (activeConfig == null || refresh) {
final SpongeConfig<WorldConfig> worldConfig = mixinWorldServer.getWorldConfig();
final SpongeConfig<DimensionConfig> dimensionConfig = ((IMixinDimensionType) ((Dimension) world.provider).getType()).getDimensionConfig();
if (worldConfig != null && worldConfig.getConfig().isConfigEnabled()) {
activeConfig = worldConfig;
} else if (dimensionConfig != null && dimensionConfig.getConfig().isConfigEnabled()) {
activeConfig = dimensionConfig;
} else {
activeConfig = SpongeImpl.getGlobalConfig();
}
mixinWorldServer.setActiveConfig(activeConfig);
}
return activeConfig;
}
use of org.spongepowered.common.interfaces.world.IMixinWorldServer in project SpongeCommon by SpongePowered.
the class MixinEntity_Collisions method initializeCollisionState.
@Override
public void initializeCollisionState(World worldObj) {
SpongeConfig<? extends GeneralConfigBase> activeConfig = ((IMixinWorldServer) worldObj).getActiveConfig();
EntityCollisionCategory collisionCat = activeConfig.getConfig().getEntityCollisionCategory();
this.maxCollisions = collisionCat.getMaxEntitiesWithinAABB();
boolean requiresSave = false;
CollisionModCategory collisionMod = collisionCat.getModList().get(this.entityModId);
if (collisionMod == null && activeConfig.getConfig().getEntityCollisionCategory().autoPopulateData()) {
collisionMod = new CollisionModCategory(this.entityModId);
collisionCat.getModList().put(this.entityModId, collisionMod);
collisionMod.getEntityList().put(this.entityName, this.maxCollisions);
activeConfig.save();
return;
} else if (collisionMod != null) {
if (!collisionMod.isEnabled()) {
this.maxCollisions = -1;
return;
}
// check mod overrides
Integer modCollisionMax = collisionMod.getDefaultMaxCollisions().get("entities");
if (modCollisionMax != null) {
this.maxCollisions = modCollisionMax;
}
Integer entityMaxCollision = null;
if ((Object) this instanceof EntityItem) {
// check if all items are overridden
entityMaxCollision = collisionMod.getEntityList().get(this.spongeEntityType.getName());
}
if (entityMaxCollision == null) {
entityMaxCollision = collisionMod.getEntityList().get(this.entityName);
}
// entity overrides
if (entityMaxCollision == null && activeConfig.getConfig().getEntityCollisionCategory().autoPopulateData()) {
collisionMod.getEntityList().put(this.entityName, this.maxCollisions);
requiresSave = true;
} else if (entityMaxCollision != null) {
this.maxCollisions = entityMaxCollision;
}
}
if (this.maxCollisions <= 0) {
return;
}
if (requiresSave && activeConfig.getConfig().getEntityCollisionCategory().autoPopulateData()) {
activeConfig.save();
}
return;
}
use of org.spongepowered.common.interfaces.world.IMixinWorldServer in project SpongeCommon by SpongePowered.
the class MixinChunk_Async_Lighting method markBlocksDirtyVerticalAsync.
/**
* Marks a vertical line of blocks as dirty async.
* Instead of calling world directly, we pass chunk safely for async light method.
*
* @param x1
* @param z1
* @param x2
* @param z2
*/
private void markBlocksDirtyVerticalAsync(int x1, int z1, int x2, int z2) {
if (x2 > z2) {
int i = z2;
z2 = x2;
x2 = i;
}
if (this.world.provider.hasSkyLight()) {
for (int j = x2; j <= z2; ++j) {
final BlockPos pos = new BlockPos(x1, j, z1);
final Chunk chunk = this.getLightChunk(pos.getX() >> 4, pos.getZ() >> 4, null);
if (chunk == null) {
continue;
}
((IMixinWorldServer) this.world).updateLightAsync(EnumSkyBlock.SKY, new BlockPos(x1, j, z1), (Chunk) (Object) chunk);
}
}
this.world.markBlockRangeForRenderUpdate(x1, x2, z1, x1, z2, z1);
}
Aggregations