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

The following examples show how to use net.minecraft.world.World#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: ForgeQueue_All.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Chunk loadChunk(World world, int x, int z, boolean generate) {
    ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
    if (generate) {
        return provider.originalLoadChunk(x, z);
    } else {
        return provider.loadChunk(x, z);
    }
}
 
Example 2
Source File: BRSimpleOreGenerator.java    From BigReactors with MIT License 5 votes vote down vote up
/**
 * Call to discover if this generator WISHES to generate in this world.
 * @param world
 * @return
 */
public boolean shouldGenerateInWorld(World world) {
	IChunkProvider chunkProvider = world.getChunkProvider();
	if(dimensionBlacklist.contains(world.provider.dimensionId)) {
		return false;
	}
	else if(chunkProvider instanceof ChunkProviderHell) {
		return false;
	}
	else if(chunkProvider instanceof ChunkProviderEnd) {
		return false;
	}

	return true;
}
 
Example 3
Source File: FakeWorldServer.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
private FakeWorldServer(World world) {

        super(MinecraftServer.getServer(), new NonSavingHandler(), world.getWorldInfo().getWorldName(), world.provider.dimensionId,
                new WorldSettings(world.getWorldInfo()), world.theProfiler);
        DimensionManager.setWorld(world.provider.dimensionId, (WorldServer) world);

        chunkProvider = world.getChunkProvider();
    }
 
Example 4
Source File: ForgeQueue_All.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Chunk loadChunk(World world, int x, int z, boolean generate) {
    ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
    if (generate) {
        return provider.provideChunk(x, z);
    } else {
        return provider.loadChunk(x, z);
    }
}
 
Example 5
Source File: ForgeQueue_All.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Chunk loadChunk(World world, int x, int z, boolean generate) {
    ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
    if (generate) {
        return provider.provideChunk(x, z);
    } else {
        return provider.loadChunk(x, z);
    }
}
 
Example 6
Source File: PhysicsParticleManager.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
private boolean canParticlePassThrough(World world, BlockPos pos) {
    ChunkProviderServer serverProvider = (ChunkProviderServer) world.getChunkProvider();
    // If the chunk isn't loaded, then no problem ignore it.
    long chunkKey = ChunkPos.asLong(pos.getX() >> 4, pos.getZ() >> 4);
    if (!serverProvider.loadedChunks.containsKey(chunkKey)) {
        this.isParticleDead = true;
        return true;
    }
    IBlockState collisionState = serverProvider.loadedChunks.get(chunkKey)
        .getBlockState(pos);
    // Otherwise we have to bypass the world blockstate get because sponge has some protection on it.
    // System.out.println("oof");
    return collisionState.getBlock().isPassable(world, pos);
}
 
Example 7
Source File: ForgeQueue_All.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Chunk loadChunk(World world, int x, int z, boolean generate) {
    ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
    if (generate) {
        return provider.provideChunk(x, z);
    } else {
        return provider.loadChunk(x, z);
    }
}
 
Example 8
Source File: SpongeQueue_1_12.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Chunk loadChunk(World world, int x, int z, boolean generate) {
    ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
    if (generate) {
        return provider.provideChunk(x, z);
    } else {
        return provider.loadChunk(x, z);
    }
}
 
Example 9
Source File: ForgeQueue_All.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean regenerateChunk(World world, int x, int z, BaseBiome biome, Long seed) {
    IChunkProvider provider = world.getChunkProvider();
    if (!(provider instanceof ChunkProviderServer)) {
        return false;
    }
    ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
    IChunkProvider chunkProvider = chunkServer.serverChunkGenerator;

    long pos = ChunkCoordIntPair.chunkXZ2Int(x, z);
    Chunk mcChunk;
    if (chunkServer.chunkExists(x, z)) {
        mcChunk = chunkServer.loadChunk(x, z);
        mcChunk.onChunkUnload();
    }
    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);
    }
    chunkServer.id2ChunkMap.remove(pos);
    mcChunk = chunkProvider.provideChunk(x, z);
    chunkServer.id2ChunkMap.add(pos, mcChunk);
    chunkServer.loadedChunks.add(mcChunk);
    if (mcChunk != null) {
        mcChunk.onChunkLoad();
        mcChunk.populateChunk(chunkProvider, chunkProvider, x, z);
    }
    return true;
}
 
Example 10
Source File: ForgeQueue_All.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Chunk loadChunk(World world, int x, int z, boolean generate) {
    ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
    if (generate) {
        return provider.originalLoadChunk(x, z);
    } else {
        return provider.loadChunk(x, z);
    }
}
 
Example 11
Source File: SpongeQueue_1_11.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Chunk loadChunk(World world, int x, int z, boolean generate) {
    ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
    if (generate) {
        return provider.provideChunk(x, z);
    } else {
        return provider.loadChunk(x, z);
    }
}
 
Example 12
Source File: ForgeQueue_All.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Chunk loadChunk(World world, int x, int z, boolean generate) {
    ChunkProviderServer provider = (ChunkProviderServer) world.getChunkProvider();
    if (generate) {
        return provider.provideChunk(x, z);
    } else {
        return provider.loadChunk(x, z);
    }
}
 
Example 13
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;
    }
}
 
Example 14
Source File: ForgeQueue_All.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean regenerateChunk(World world, int x, int z, BaseBiome biome, Long seed) {
    IChunkProvider provider = world.getChunkProvider();
    if (!(provider instanceof ChunkProviderServer)) {
        return false;
    }
    try {
        ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
        IChunkGenerator gen = chunkServer.chunkGenerator;
        long pos = ChunkPos.chunkXZ2Int(x, z);
        Chunk mcChunk;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            mcChunk.onChunkUnload();
        }
        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.onChunkUnload();
        }
        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);
        }
        chunkServer.id2ChunkMap.remove(pos);
        mcChunk = gen.provideChunk(x, z);
        chunkServer.id2ChunkMap.put(pos, mcChunk);
        if (mcChunk != null) {
            mcChunk.onChunkLoad();
            mcChunk.populateChunk(chunkServer, chunkServer.chunkGenerator);
        }
        if (oldWatchers != null) {
            for (EntityPlayerMP player : oldWatchers) {
                playerManager.addPlayer(player);
            }
        }
        return true;
    } catch (Throwable t) {
        MainUtil.handleError(t);
        return false;
    }
}
 
Example 15
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 = chunkServer.chunkGenerator;
        long pos = ChunkPos.asLong(x, z);
        Chunk mcChunk;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            mcChunk.onChunkUnload();
        }
        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.onChunkUnload();
        }
        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);
        }
        chunkServer.id2ChunkMap.remove(pos);
        mcChunk = gen.provideChunk(x, z);
        chunkServer.id2ChunkMap.put(pos, mcChunk);
        if (mcChunk != null) {
            mcChunk.onChunkLoad();
            mcChunk.populateChunk(chunkServer, chunkServer.chunkGenerator);
        }
        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 16
Source File: SatelliteOreMapping.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
public static int[][] scanChunk(World world, int offsetX, int offsetZ, int radius, int blocksPerPixel, ItemStack block) {
	blocksPerPixel = Math.max(blocksPerPixel, 1);
	int[][] ret = new int[(radius*2)/blocksPerPixel][(radius*2)/blocksPerPixel];

	Chunk chunk = world.getChunkFromChunkCoords(offsetX << 4, offsetZ << 4);
	IChunkProvider provider = world.getChunkProvider();


	for(int z = -radius; z < radius; z+=blocksPerPixel){
		for(int x = -radius; x < radius; x+=blocksPerPixel) {
			int oreCount = 0, otherCount = 0;


			for(int y = world.getHeight(); y > 0; y--) {
				for(int deltaY = 0; deltaY < blocksPerPixel; deltaY++) {
					for(int deltaZ = 0; deltaZ < blocksPerPixel; deltaZ++) {

						BlockPos pos = new BlockPos(x + offsetX, y, z + offsetZ);
						if(world.isAirBlock(pos))
							continue;

						//Note:May not work with tileEntities (GT ores)
						boolean found = false;
						List<ItemStack> drops;
						IBlockState state = world.getBlockState(pos);
						if((drops = state.getBlock().getDrops(world,pos, state, 0)) != null)
							for(ItemStack stack : drops) {
								if(stack.getItem() == block.getItem() && stack.getItemDamage() == block.getItemDamage()) {
									oreCount++;
									found = true;
								}
							}

						if(!found)
							otherCount++;
					}
				}
			}
			oreCount /= Math.pow(blocksPerPixel,2);
			otherCount /= Math.pow(blocksPerPixel,2);

			if(Thread.interrupted())
				return null;


			ret[(x+radius)/blocksPerPixel][(z+radius)/blocksPerPixel] = (int)((oreCount/(float)Math.max(otherCount,1))*0xFFFF);
		}
	}

	return ret;
}
 
Example 17
Source File: SatelliteOreMapping.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
/**
 * Note: array returned will be [radius/blocksPerPixel][radius/blocksPerPixel]
 * @param world
 * @param offsetX
 * @param offsetY
 * @param radius in blocks
 * @param blocksPerPixel number of blocks squared (n*n) that take up one pixel
 * @return array of ore vs other block values
 */
public static int[][] scanChunk(World world, int offsetX, int offsetZ, int radius, int blocksPerPixel) {
	blocksPerPixel = Math.max(blocksPerPixel, 1);
	int[][] ret = new int[(radius*2)/blocksPerPixel][(radius*2)/blocksPerPixel];

	Chunk chunk = world.getChunkFromChunkCoords(offsetX << 4, offsetZ << 4);
	IChunkProvider provider = world.getChunkProvider();

	if(oreList.isEmpty()) {
		String[] strings = OreDictionary.getOreNames();
		for(String str : strings) {
			if(str.startsWith("ore") || str.startsWith("dust") || str.startsWith("gem"))
				oreList.add(OreDictionary.getOreID(str));
		}
	}

	for(int z = -radius; z < radius; z+=blocksPerPixel){
		for(int x = -radius; x < radius; x+=blocksPerPixel) {
			int oreCount = 0, otherCount = 0;


			for(int y = world.getHeight(); y > 0; y--) {
				for(int deltaY = 0; deltaY < blocksPerPixel; deltaY++) {
					for(int deltaZ = 0; deltaZ < blocksPerPixel; deltaZ++) {

						BlockPos pos = new BlockPos(x + offsetX, y, z + offsetZ);
						if(world.isAirBlock(pos))
							continue;
						boolean exists = false;
						out:
							for(int i : oreList) {
								List<ItemStack> itemlist = OreDictionary.getOres(OreDictionary.getOreName(i));

								for(ItemStack item : itemlist) {
									if(item.getItem() == Item.getItemFromBlock(world.getBlockState(pos).getBlock())) {
										exists = true;
										break out;
									}
								}
							}
						if(exists)
							oreCount++;
						else
							otherCount++;
					}
				}
			}
			oreCount /= Math.pow(blocksPerPixel,2);
			otherCount /= Math.pow(blocksPerPixel,2);

			if(Thread.interrupted())
				return null;


			ret[(x+radius)/blocksPerPixel][(z+radius)/blocksPerPixel] = (int)((oreCount/(float)Math.max(otherCount,1))*0xFFFF);
		}
	}

	return ret;
}
 
Example 18
Source File: ForgeQueue_All.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean regenerateChunk(World world, int x, int z, BaseBiome biome, Long seed) {
    IChunkProvider provider = world.getChunkProvider();
    if (!(provider instanceof ChunkProviderServer)) {
        return false;
    }


    try {
        ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
        IChunkGenerator gen = chunkServer.chunkGenerator;
        long pos = ChunkPos.chunkXZ2Int(x, z);
        Chunk mcChunk;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            mcChunk.onChunkUnload();
        }
        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.onChunkUnload();
        }
        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);
        }
        chunkServer.id2ChunkMap.remove(pos);
        mcChunk = gen.provideChunk(x, z);
        chunkServer.id2ChunkMap.put(pos, mcChunk);
        if (mcChunk != null) {
            mcChunk.onChunkLoad();
            mcChunk.populateChunk(chunkServer, chunkServer.chunkGenerator);
        }
        if (oldWatchers != null) {
            for (EntityPlayerMP player : oldWatchers) {
                playerManager.addPlayer(player);
            }
        }
        return true;
    } catch (Throwable t) {
        MainUtil.handleError(t);
        return false;
    }
}