Java Code Examples for net.minecraft.world.WorldServer#getChunkProvider()

The following examples show how to use net.minecraft.world.WorldServer#getChunkProvider() . 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
public static boolean refreshChunk(Chunk chunk) {
    int x = chunk.x;
    int z = chunk.z;
    WorldServer world = (WorldServer) chunk.getWorld();
    ChunkProviderBridge chunkProviderServer = (ChunkProviderBridge) world.getChunkProvider();
    if (chunkProviderServer.bridge$getLoadedChunkWithoutMarkingActive(x, z) == null) {
        return false;
    }

    int px = x << 4;
    int pz = z << 4;

    int height = world.getHeight() / 16;
    for (int y = 0; y < 64; y++) {
        world.notifyBlockUpdate(new BlockPos(px + (y / height), ((y % height) * 16), pz), Blocks.AIR.getDefaultState(), Blocks.STONE.getDefaultState(), 3);
    }
    world.notifyBlockUpdate(new BlockPos(px + 15, (height * 16) - 1, pz + 15), Blocks.AIR.getDefaultState(), Blocks.STONE.getDefaultState(), 3);

    return true;
}
 
Example 2
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 3
Source File: ChunkLoading.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean loadChunkWithoutForce(WorldServer worldServer, int chunkX, int chunkZ)
{
    //System.out.println("loadChunkWithoutForce() start");
    if (worldServer == null || worldServer.getChunkProvider() == null)
    {
        return false;
    }

    if (worldServer.getChunkProvider().chunkExists(chunkX, chunkZ) == false)
    {
        //System.out.println("loadChunkWithoutForce() loading chunk");
        worldServer.getChunkProvider().loadChunk(chunkX, chunkZ);
    }

    //System.out.println("loadChunkWithoutForce() end");
    return true;
}
 
Example 4
Source File: WorldRetrogen.java    From simpleretrogen with GNU General Public License v3.0 5 votes vote down vote up
private void runRetrogen(WorldServer world, ChunkPos chunkCoords, String retroClass)
{
    long worldSeed = world.getSeed();
    Random fmlRandom = new Random(worldSeed);
    long xSeed = fmlRandom.nextLong() >> 2 + 1L;
    long zSeed = fmlRandom.nextLong() >> 2 + 1L;
    long chunkSeed = (xSeed * chunkCoords.chunkXPos + zSeed * chunkCoords.chunkZPos) ^ worldSeed;

    fmlRandom.setSeed(chunkSeed);
    ChunkProviderServer providerServer = world.getChunkProvider();
    IChunkGenerator generator = ObfuscationReflectionHelper.getPrivateValue(ChunkProviderServer.class, providerServer, "field_186029_c", "chunkGenerator");
    delegates.get(retroClass).delegate.generate(fmlRandom, chunkCoords.chunkXPos, chunkCoords.chunkZPos, world, generator, providerServer);
    FMLLog.fine("Retrogenerated chunk for %s", retroClass);
    completeRetrogen(chunkCoords, world, retroClass);
}
 
Example 5
Source File: StructureRegistry.java    From OpenModsLib with MIT License 5 votes vote down vote up
private void visitStructures(WorldServer world, IStructureVisitor visitor) {
	ChunkProviderServer provider = world.getChunkProvider();
	IChunkGenerator inner = provider.chunkGenerator;

	if (inner != null) {
		for (IStructureGenProvider<?> p : providers)
			tryVisit(visitor, inner, p);
	}
}
 
Example 6
Source File: BlockUtils.java    From GriefPrevention with MIT License 4 votes vote down vote up
public static boolean createFillerChunk(GPPlayerData playerData, WorldServer world, int chunkX, int chunkZ) {
    ChunkProviderServer chunkProviderServer = world.getChunkProvider();
    Chunk chunk = ((ChunkProviderBridge) chunkProviderServer).bridge$getLoadedChunkWithoutMarkingActive(chunkX, chunkZ);
    if (chunk == null) {
        return false;
    }

    unloadChunk(chunk);
    org.spongepowered.api.world.Chunk fillerChunk = (org.spongepowered.api.world.Chunk) chunkProviderServer.chunkGenerator.generateChunk(chunk.x, chunk.z);
    int maxBuildHeight = fillerChunk.getWorld().getDimension().getBuildHeight() - 1;
    BlockSnapshot[][][] snapshots = new BlockSnapshot[18][maxBuildHeight][18];
    BlockSnapshot startBlock = fillerChunk.createSnapshot(0, 0, 0);
    Location<World> startLocation =
            new Location<World>(fillerChunk.getWorld(), startBlock.getPosition().getX() - 1, 0, startBlock.getPosition().getZ() - 1);
    for (int x = 0; x < snapshots.length; x++) {
        for (int z = 0; z < snapshots[0][0].length; z++) {
            for (int y = 0; y < snapshots[0].length; y++) {
                snapshots[x][y][z] = fillerChunk.getWorld()
                        .createSnapshot(startLocation.getBlockX() + x, startLocation.getBlockY() + y, startLocation.getBlockZ() + z);
            }
        }
    }
    fillerChunk = null;
    playerData.fillerBlocks = snapshots;
    if (chunk != null) {
        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);
            }
        }
    }
    return true;
}
 
Example 7
Source File: RegenChunkCommand.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] params)
{
	EntityPlayerMP player;
	try {
		player = getCommandSenderAsPlayer(sender);
	} catch (PlayerNotFoundException e) {
		return;
	}

	if(!player.isCreative())
		return;

	WorldServer world = server.worldServerForDimension(player.getEntityWorld().provider.getDimension());

	if(player.getEntityWorld().provider.getDimension() == 0 && params.length == 1)
	{
		int radius = Integer.parseInt(params[0]);

		for(int i = -radius; i <= radius; i++)
		{
			for(int k = -radius; k <= radius; k++)
			{
				int x = (((int)player.posX+i*16) >> 4);
				int z = (((int)player.posZ+k*16) >> 4);

				ChunkProviderServer cps = world.getChunkProvider();

				Chunk c = cps.chunkGenerator.provideChunk(x, z);
				Chunk old = world.getChunkProvider().provideChunk(x, z);
				old.setStorageArrays(c.getBlockStorageArray());
				c.setTerrainPopulated(false);
				c.onChunkLoad();
				c.setChunkModified();
				c.checkLight();
				cps.chunkGenerator.populate(c.xPosition, c.zPosition);
				net.minecraftforge.fml.common.registry.GameRegistry.generateWorld(c.xPosition, c.zPosition, world, cps.chunkGenerator, world.getChunkProvider());
				c.setChunkModified();
				player.connection.sendPacket(new SPacketChunkData(cps.provideChunk(x, z), 0xffffffff));
			}
		}

		/*for(int i = -radius; i <= radius; i++)
		{
			for(int k = -radius; k <= radius; k++)
			{
				int x = (((int)player.posX+i*16) >> 4);
				int z = (((int)player.posZ+k*16) >> 4);

				ChunkProviderServer cps = world.getChunkProvider();

				Chunk c = cps.chunkGenerator.provideChunk(x, z);
				Chunk old = world.getChunkProvider().provideChunk(x, z);
				old.populateChunk(cps, cps.chunkGenerator);

				if (c.isTerrainPopulated())
				{
					if (cps.chunkGenerator.generateStructures(c, c.xPosition, c.zPosition))
					{
						c.setChunkModified();
					}
				}
				else
				{
					c.checkLight();
					cps.chunkGenerator.populate(c.xPosition, c.zPosition);
					net.minecraftforge.fml.common.registry.GameRegistry.generateWorld(c.xPosition, c.zPosition, world, cps.chunkGenerator, world.getChunkProvider());
					c.setChunkModified();
				}

				player.connection.sendPacket(new SPacketChunkData(cps.provideChunk(x, z), 0xffffffff));
			}
		}*/
	}
	else if(player.getEntityWorld().provider.getDimension() == 0 && params.length == 2 && params[1].equalsIgnoreCase("hex"))
	{
		execute(server, sender, new String[] {params[0]});
		IslandMap map = Core.getMapForWorld(world, player.getPosition());
		HexGenRegistry.generate(Core.getMapForWorld(world, player.getPosition()), map.getClosestCenter(player.getPosition()), world);
	}
}