Java Code Examples for net.minecraft.world.chunk.Chunk#populate()

The following examples show how to use net.minecraft.world.chunk.Chunk#populate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockUtils.java    From GriefPrevention with MIT License 6 votes vote down vote up
private static void chunkLoadPostProcess(Chunk chunk) {
    if (chunk != null) {
        WorldServer world = (WorldServer) chunk.getWorld();
        world.getChunkProvider().id2ChunkMap.put(ChunkPos.asLong(chunk.x, chunk.z), chunk);

        org.spongepowered.api.world.Chunk spongeChunk = (org.spongepowered.api.world.Chunk) chunk;
        for (Direction direction : CARDINAL_SET) {
            Vector3i neighborPosition = spongeChunk.getPosition().add(direction.asBlockOffset());
            ChunkProviderBridge spongeChunkProvider = (ChunkProviderBridge) world.getChunkProvider();
            net.minecraft.world.chunk.Chunk neighbor = spongeChunkProvider.bridge$getLoadedChunkWithoutMarkingActive(neighborPosition.getX(), neighborPosition.getZ());
            if (neighbor != null) {
                int neighborIndex = directionToIndex(direction);
                int oppositeNeighborIndex = directionToIndex(direction.getOpposite());
                ((ChunkBridge) spongeChunk).bridge$setNeighborChunk(neighborIndex, neighbor);
                ((ChunkBridge) neighbor).bridge$setNeighborChunk(oppositeNeighborIndex, (net.minecraft.world.chunk.Chunk)(Object) chunk);
            }
        }

        chunk.populate(world.getChunkProvider(), world.getChunkProvider().chunkGenerator);
    }
}
 
Example 2
Source File: SpongeQueue_1_12.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public boolean regenerateChunk(net.minecraft.world.World world, int x, int z) {
    IChunkProvider provider = world.getChunkProvider();
    if (!(provider instanceof ChunkProviderServer)) {
        return false;
    }
    BlockFalling.fallInstantly = true;
    try {
        ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
        IChunkGenerator gen = (IChunkGenerator) fieldChunkGenerator.get(chunkServer);
        long pos = ChunkPos.asLong(x, z);
        Chunk mcChunk;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            mcChunk.onUnload();
        }
        PlayerChunkMap playerManager = ((WorldServer) getWorld()).getPlayerChunkMap();
        List<EntityPlayerMP> oldWatchers = null;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            PlayerChunkMapEntry entry = playerManager.getEntry(x, z);
            if (entry != null) {
                Field fieldPlayers = PlayerChunkMapEntry.class.getDeclaredField("field_187283_c");
                fieldPlayers.setAccessible(true);
                oldWatchers = (List<EntityPlayerMP>) fieldPlayers.get(entry);
                playerManager.removeEntry(entry);
            }
            mcChunk.onUnload();
        }
        try {
            Field droppedChunksSetField = chunkServer.getClass().getDeclaredField("field_73248_b");
            droppedChunksSetField.setAccessible(true);
            Set droppedChunksSet = (Set) droppedChunksSetField.get(chunkServer);
            droppedChunksSet.remove(pos);
        } catch (Throwable e) {
            MainUtil.handleError(e);
        }
        Long2ObjectMap<Chunk> id2ChunkMap = (Long2ObjectMap<Chunk>) fieldId2ChunkMap.get(chunkServer);
        id2ChunkMap.remove(pos);
        mcChunk = gen.generateChunk(x, z);
        id2ChunkMap.put(pos, mcChunk);
        if (mcChunk != null) {
            mcChunk.onLoad();
            mcChunk.populate(chunkServer, gen);
        }
        if (oldWatchers != null) {
            for (EntityPlayerMP player : oldWatchers) {
                playerManager.addPlayer(player);
            }
        }
        return true;
    } catch (Throwable t) {
        MainUtil.handleError(t);
        return false;
    } finally {
        BlockFalling.fallInstantly = false;
    }
}
 
Example 3
Source File: ForgeQueue_All.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public boolean regenerateChunk(World world, int x, int z) {
    IChunkProvider provider = world.getChunkProvider();
    if (!(provider instanceof ChunkProviderServer)) {
        return false;
    }
    BlockFalling.fallInstantly = true;
    try {
        ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
        IChunkGenerator gen = (IChunkGenerator) fieldChunkGenerator.get(chunkServer);
        long pos = ChunkPos.asLong(x, z);
        Chunk mcChunk;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            mcChunk.onUnload();
        }
        PlayerChunkMap playerManager = ((WorldServer) getWorld()).getPlayerChunkMap();
        List<EntityPlayerMP> oldWatchers = null;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            PlayerChunkMapEntry entry = playerManager.getEntry(x, z);
            if (entry != null) {
                Field fieldPlayers = PlayerChunkMapEntry.class.getDeclaredField("field_187283_c");
                fieldPlayers.setAccessible(true);
                oldWatchers = (List<EntityPlayerMP>) fieldPlayers.get(entry);
                playerManager.removeEntry(entry);
            }
            mcChunk.onUnload();
        }
        try {
            Field droppedChunksSetField = chunkServer.getClass().getDeclaredField("field_73248_b");
            droppedChunksSetField.setAccessible(true);
            Set droppedChunksSet = (Set) droppedChunksSetField.get(chunkServer);
            droppedChunksSet.remove(pos);
        } catch (Throwable e) {
            MainUtil.handleError(e);
        }
        Long2ObjectMap<Chunk> id2ChunkMap = chunkServer.id2ChunkMap;
        id2ChunkMap.remove(pos);
        mcChunk = gen.generateChunk(x, z);
        id2ChunkMap.put(pos, mcChunk);
        if (mcChunk != null) {
            mcChunk.onLoad();
            mcChunk.populate(chunkServer, gen);
        }
        if (oldWatchers != null) {
            for (EntityPlayerMP player : oldWatchers) {
                playerManager.addPlayer(player);
            }
        }
        return true;
    } catch (Throwable t) {
        MainUtil.handleError(t);
        return false;
    } finally {
        BlockFalling.fallInstantly = false;
    }
}