Search in sources :

Example 51 with IMixinWorldServer

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();
}
Also used : Path(java.nio.file.Path) DimensionConfig(org.spongepowered.common.config.type.DimensionConfig) SpongeConfig(org.spongepowered.common.config.SpongeConfig) WorldConfig(org.spongepowered.common.config.type.WorldConfig) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) World(net.minecraft.world.World)

Example 52 with IMixinWorldServer

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;
}
Also used : IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk) SpongeEmptyChunk(org.spongepowered.common.world.SpongeEmptyChunk) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 53 with IMixinWorldServer

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;
}
Also used : DimensionConfig(org.spongepowered.common.config.type.DimensionConfig) IMixinDimensionType(org.spongepowered.common.interfaces.world.IMixinDimensionType) WorldConfig(org.spongepowered.common.config.type.WorldConfig) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer)

Example 54 with IMixinWorldServer

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;
}
Also used : CollisionModCategory(org.spongepowered.common.config.category.CollisionModCategory) EntityCollisionCategory(org.spongepowered.common.config.category.EntityCollisionCategory) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) EntityItem(net.minecraft.entity.item.EntityItem)

Example 55 with IMixinWorldServer

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);
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk)

Aggregations

IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)61 WorldServer (net.minecraft.world.WorldServer)25 BlockPos (net.minecraft.util.math.BlockPos)19 ArrayList (java.util.ArrayList)17 Entity (org.spongepowered.api.entity.Entity)15 World (org.spongepowered.api.world.World)15 IBlockState (net.minecraft.block.state.IBlockState)13 SpawnEntityEvent (org.spongepowered.api.event.entity.SpawnEntityEvent)13 CauseStackManager (org.spongepowered.api.event.CauseStackManager)11 Overwrite (org.spongepowered.asm.mixin.Overwrite)11 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)9 IMixinEntity (org.spongepowered.common.interfaces.entity.IMixinEntity)9 EntityItem (net.minecraft.entity.item.EntityItem)8 User (org.spongepowered.api.entity.living.player.User)8 LocatableBlock (org.spongepowered.api.world.LocatableBlock)8 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)7 Entity (net.minecraft.entity.Entity)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 Chunk (net.minecraft.world.chunk.Chunk)6 IMixinChunk (org.spongepowered.common.interfaces.IMixinChunk)6