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

The following examples show how to use net.minecraft.world.World#getChunkFromChunkCoords() . 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: CachedGridEntry.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public CachedGridEntry(World world, int gridX, int gridZ, int primerChunkX, int primerChunkZ) {
    this.gridX = gridX;
    this.gridZ = gridZ;
    long worldSeed = world.getSeed();
    this.gridRandom = new XSTR(31 * 31 * gridX + gridZ * 31 + Long.hashCode(worldSeed));

    int gridSizeX = WorldGeneratorImpl.GRID_SIZE_X * 16;
    int gridSizeZ = WorldGeneratorImpl.GRID_SIZE_Z * 16;
    BlockPos blockPos = new BlockPos(gridX * gridSizeX + gridSizeX / 2, world.getActualHeight(), gridZ * gridSizeZ + gridSizeZ / 2);
    Biome currentBiome = world.getBiomeProvider().getBiome(blockPos);
    this.cachedDepositMap = new ArrayList<>(WorldGenRegistry.INSTANCE.getCachedBiomeVeins(world.provider, currentBiome));

    this.worldSeaLevel = world.getSeaLevel();
    this.masterEntry = searchMasterOrNull(world);
    if (masterEntry == null) {
        Chunk primerChunk = world.getChunkFromChunkCoords(primerChunkX, primerChunkZ);
        BlockPos heightSpot = findOptimalSpot(gridX, gridZ, primerChunkX, primerChunkZ);
        int masterHeight = world.getHeight(heightSpot).getY();
        int masterBottomHeight = world.getTopSolidOrLiquidBlock(heightSpot).getY();
        this.masterEntry = primerChunk.getCapability(GTWorldGenCapability.CAPABILITY, null);
        this.masterEntry = new GTWorldGenCapability();
        this.masterEntry.setMaxHeight(masterHeight, masterBottomHeight);
    }

    triggerVeinsGeneration();
}
 
Example 2
Source File: BlockUtils.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static void setTileEntity(World world, int x, int y, int z, TileEntity te) {

    if (te == null)
        return;

    Chunk chunk = world.getChunkFromChunkCoords(x >> 4, z >> 4);
    if (chunk != null) {
        ChunkPosition pos = new ChunkPosition(x & 15, y, z & 15);
        if (chunk.chunkTileEntityMap.containsKey(pos))
            ((TileEntity) chunk.chunkTileEntityMap.get(pos)).invalidate();
        chunk.chunkTileEntityMap.put(pos, te);
        world.addTileEntity(te);
    }
}
 
Example 3
Source File: BlockUtils.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
public static void setBlockSneaky(World world, int x, int y, int z, Block block) {

        Chunk chunk = world.getChunkFromChunkCoords(x >> 4, z >> 4);
        if (chunk != null) {
            ExtendedBlockStorage ebs = chunk.getBlockStorageArray()[y >> 4];
            if (ebs != null)
                ebs.func_150818_a(x & 15, y & 15, z & 15, block);
        }
    }
 
Example 4
Source File: WorldGenTFC.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGen,IChunkProvider chunkProvider)
{
	chunk = world.getChunkFromChunkCoords(chunkX, chunkZ);
	chunkX *= 16;
	chunkZ *= 16;

	map = Core.getMapForWorld(world, new BlockPos(chunkX, 0, chunkZ));
	iMoisture = map.getParams().getIslandMoisture();
}
 
Example 5
Source File: Plot.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public void deleteSignBlocks(SignType signType, World world) {
    if(world.provider.dimensionId != dim)
        return;

    int x1 = getStartX();
    int y1 = getStartY();
    int z1 = getStartZ();
    int x2 = getEndX();
    int y2 = getEndY();
    int z2 = getEndZ();
    int cx1 = x1 >> 4;
    int cz1 = z1 >> 4;
    int cx2 = x2 >> 4;
    int cz2 = z2 >> 4;
    for(int cx = cx1; cx <= cx2; cx++)
        for(int cz = cz1; cz <= cz2; cz++) {
            Chunk chunk = world.getChunkFromChunkCoords(cx, cz);
            if(!chunk.isChunkLoaded)
                chunk = world.getChunkProvider().loadChunk(cx, cz);

            List<int[]> sellSigns = new ArrayList<int[]>(2);
            for(Object obj: chunk.chunkTileEntityMap.values()) {
                if(obj instanceof TileEntitySign) {
                    TileEntitySign sign = (TileEntitySign) obj;
                    if(    sign.xCoord >= x1 && sign.xCoord <= x2
                        && sign.yCoord >= y1 && sign.yCoord <= y2
                        && sign.zCoord >= z1 && sign.zCoord <= z2
                        && signType.isTileValid(sign) )
                            sellSigns.add(new int[]{sign.xCoord, sign.yCoord, sign.zCoord});
                }
            }

            for(int[] sellSign: sellSigns) {
                world.removeTileEntity(sellSign[0], sellSign[1], sellSign[2]);
                world.setBlock(sellSign[0], sellSign[1], sellSign[2], Blocks.air);
            }
        }
}
 
Example 6
Source File: CustomSpawner.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
protected static ChunkPosition getRandomSpawningPointInChunk(World worldObj, int par1, int par2)
{
    Chunk chunk = worldObj.getChunkFromChunkCoords(par1, par2);
    int i = par1 * 16 + worldObj.rand.nextInt(16);
    int j = worldObj.rand.nextInt(chunk == null ? worldObj.getActualHeight() : chunk.getTopFilledSegment() + 16 - 1);
    int k = par2 * 16 + worldObj.rand.nextInt(16);
    return new ChunkPosition(i, j, k);
}
 
Example 7
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 8
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 9
Source File: Core.java    From TFC2 with GNU General Public License v3.0 4 votes vote down vote up
public static int getHeight(World world, int worldX, int worldZ)
{
	Chunk c = world.getChunkFromChunkCoords(worldX >> 4, worldZ >> 4); 
	return c.getHeightValue(worldX & 15, worldZ & 15);
}