Search in sources :

Example 1 with GreenhouseChunk

use of forestry.greenhouse.multiblock.blocks.storage.GreenhouseChunk in project ForestryMC by ForestryMC.

the class ChunkManager method createChunk.

public GreenhouseChunk createChunk(long pos) {
    GreenhouseChunk chunk = new GreenhouseChunk();
    id2ChunkMap.put(pos, chunk);
    return chunk;
}
Also used : GreenhouseChunk(forestry.greenhouse.multiblock.blocks.storage.GreenhouseChunk)

Example 2 with GreenhouseChunk

use of forestry.greenhouse.multiblock.blocks.storage.GreenhouseChunk in project ForestryMC by ForestryMC.

the class ChunkManager method unload.

public void unload(int x, int z) {
    long pos = ChunkPos.asLong(x, z);
    GreenhouseChunk chunk = id2ChunkMap.remove(pos);
    if (chunk != null) {
        for (IGreenhouseProvider manager : chunk.getProviders()) {
            manager.onUnloadChunk(pos);
        }
    }
}
Also used : IGreenhouseProvider(forestry.greenhouse.api.greenhouse.IGreenhouseProvider) GreenhouseChunk(forestry.greenhouse.multiblock.blocks.storage.GreenhouseChunk)

Example 3 with GreenhouseChunk

use of forestry.greenhouse.multiblock.blocks.storage.GreenhouseChunk in project ForestryMC by ForestryMC.

the class GreenhouseBlockManager method markBlockDirty.

@Nullable
public synchronized void markBlockDirty(World world, BlockPos pos) {
    long position = ChunkPos.asLong(pos.getX() >> 4, pos.getZ() >> 4);
    GreenhouseChunk chunk = getChunk(world, position);
    if (chunk != null) {
        IGreenhouseBlock block = chunk.get(pos);
        if (block != null) {
            IGreenhouseProvider provider = block.getProvider();
            provider.onBlockChange();
        // markChunkDirty(world, position);
        // chunk.markProviderDirty(pos);
        }
    }
}
Also used : IGreenhouseProvider(forestry.greenhouse.api.greenhouse.IGreenhouseProvider) IGreenhouseChunk(forestry.greenhouse.api.greenhouse.IGreenhouseChunk) GreenhouseChunk(forestry.greenhouse.multiblock.blocks.storage.GreenhouseChunk) IGreenhouseBlock(forestry.greenhouse.api.greenhouse.IGreenhouseBlock) Nullable(javax.annotation.Nullable)

Example 4 with GreenhouseChunk

use of forestry.greenhouse.multiblock.blocks.storage.GreenhouseChunk in project ForestryMC by ForestryMC.

the class GreenhouseBlockManager method markProviderDirty.

@Nullable
public synchronized void markProviderDirty(World world, BlockPos pos, IGreenhouseProvider provider) {
    if (provider != null) {
        long position = ChunkPos.asLong(pos.getX() >> 4, pos.getZ() >> 4);
        GreenhouseChunk chunk = getChunk(world, position);
        if (chunk != null) {
            markChunkDirty(world, position);
            chunk.markProviderDirty(provider);
        }
    }
}
Also used : IGreenhouseChunk(forestry.greenhouse.api.greenhouse.IGreenhouseChunk) GreenhouseChunk(forestry.greenhouse.multiblock.blocks.storage.GreenhouseChunk) Nullable(javax.annotation.Nullable)

Example 5 with GreenhouseChunk

use of forestry.greenhouse.multiblock.blocks.storage.GreenhouseChunk in project ForestryMC by ForestryMC.

the class ChunkThread method handleDirtyChunks.

private static void handleDirtyChunks(World world) {
    if (world == null || world.provider == null) {
        return;
    }
    GreenhouseBlockManager manager = GreenhouseBlockManager.getInstance();
    synchronized (manager) {
        List<Long> dirtyChunks = manager.getDirtyChunks(world);
        Iterator<Long> dirtyChunksIterator = dirtyChunks.iterator();
        while (dirtyChunksIterator.hasNext()) {
            Long chunkPos = dirtyChunksIterator.next();
            GreenhouseChunk chunk = manager.getChunk(world, chunkPos);
            if (chunk != null) {
                synchronized (chunk) {
                    Collection<IGreenhouseProvider> providers = chunk.getDirtyProviders();
                    Iterator<IGreenhouseProvider> dirtyProviders = providers.iterator();
                    while (dirtyProviders.hasNext()) {
                        IGreenhouseProvider provider = dirtyProviders.next();
                        provider.recreate();
                        dirtyProviders.remove();
                    }
                }
            }
            dirtyChunksIterator.remove();
        }
        manager.tickUpdates(world);
    }
}
Also used : IGreenhouseProvider(forestry.greenhouse.api.greenhouse.IGreenhouseProvider) GreenhouseChunk(forestry.greenhouse.multiblock.blocks.storage.GreenhouseChunk)

Aggregations

GreenhouseChunk (forestry.greenhouse.multiblock.blocks.storage.GreenhouseChunk)5 IGreenhouseProvider (forestry.greenhouse.api.greenhouse.IGreenhouseProvider)3 IGreenhouseChunk (forestry.greenhouse.api.greenhouse.IGreenhouseChunk)2 Nullable (javax.annotation.Nullable)2 IGreenhouseBlock (forestry.greenhouse.api.greenhouse.IGreenhouseBlock)1