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

The following examples show how to use net.minecraft.world.World#getHeight() . 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: WorldGenUnderVine.java    From TofuCraftReload with MIT License 5 votes vote down vote up
public boolean generate(World worldIn, Random rand, BlockPos position)
{
    for (int i = 0; i < 64; ++i)
    {
        BlockPos blockpos = position.add(rand.nextInt(8) - rand.nextInt(8), rand.nextInt(4) - rand.nextInt(4), rand.nextInt(8) - rand.nextInt(8));

        if (worldIn.isAirBlock(blockpos) && (!worldIn.provider.isNether() || blockpos.getY() < worldIn.getHeight() - 1) && this.block.canBlockStay(worldIn, blockpos))
        {
            worldIn.setBlockState(blockpos, this.block.getDefaultState(), 2);

            if(worldIn.isAirBlock(blockpos.down()) && rand.nextFloat()< 0.8F) {
                worldIn.setBlockState(blockpos.down(), this.block.getDefaultState(), 2);
                if(worldIn.isAirBlock(blockpos.down(2)) && rand.nextFloat()< 0.6F) {
                    worldIn.setBlockState(blockpos.down(2), this.block.getDefaultState(), 2);
                    if(worldIn.isAirBlock(blockpos.down(3)) && rand.nextFloat()< 0.45F) {
                        worldIn.setBlockState(blockpos.down(3), this.block.getDefaultState(), 2);
                        if(worldIn.isAirBlock(blockpos.down(4)) && rand.nextFloat()< 0.25F) {
                            worldIn.setBlockState(blockpos.down(4), this.block.getDefaultState(), 2);
                            worldIn.neighborChanged(blockpos.down(4),this.block,position);
                        }
                        worldIn.neighborChanged(blockpos.down(3),this.block,position);
                    }
                    worldIn.neighborChanged(blockpos.down(2),this.block,position);
                }
                worldIn.neighborChanged(blockpos.down(),this.block,position);
            }
            worldIn.neighborChanged(blockpos,this.block,position);
        }
    }

    return true;
}
 
Example 2
Source File: BiomeCragCliffs.java    From Traverse-Legacy-1-12-2 with MIT License 5 votes vote down vote up
@Override
public void decorate(World worldIn, Random rand, BlockPos pos) {
	if (!TraverseConfig.disallowBoulders && net.minecraftforge.event.terraingen.TerrainGen.decorate(worldIn, rand, pos, DecorateBiomeEvent.Decorate.EventType.ROCK)) {
		int genChance = rand.nextInt(9);
		if (genChance == 0) {
			int k6 = rand.nextInt(16) + 8;
			int l = rand.nextInt(16) + 8;
			BlockPos blockpos = worldIn.getHeight(pos.add(k6, 0, l));
			BOULDER_FEATURE.generate(worldIn, rand, blockpos);
		}
	}
	super.decorate(worldIn, rand, pos);
}
 
Example 3
Source File: BiomeAridHighland.java    From Traverse-Legacy-1-12-2 with MIT License 5 votes vote down vote up
@Override
public void decorate(World worldIn, Random rand, BlockPos pos) {
	if (net.minecraftforge.event.terraingen.TerrainGen.decorate(worldIn, rand, pos, DecorateBiomeEvent.Decorate.EventType.TREE)) {
		if (rand.nextInt(5) == 0) {
			int k6 = rand.nextInt(16) + 8;
			int l = rand.nextInt(16) + 8;
			BlockPos blockpos = worldIn.getHeight(pos.add(k6, 0, l));
			OAK_SHRUB_FEATURE.generate(worldIn, rand, blockpos);
		}
	}

	super.decorate(worldIn, rand, pos);
}
 
Example 4
Source File: PositionUtils.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the given position scaled by the given scale factors, and clamped to within the world border
 * of the destination world, with the given margin to the border.
 */
public static Vec3d getScaledClampedPosition(Vec3d pos, @Nullable World world, double scaleX, double scaleY, double scaleZ, int margin)
{
    // The world border in other dimensions than the Overworld gets always
    // reset to the default 60M blocks when the dimensions loads.
    // The client side WorldBorder is synced on world load, so the
    // border _appears_ to be where the Overworld border is,
    // but on the server side the border is actually at 60M blocks,
    // unless the border has been changed using the commands,
    // because the border change listener will then update the border
    // size from the Overworld border to the other dimensions (see WorldServerMulti),
    // however that change only persists as long as the dimension stays loaded.

    // So we are just getting the border size from the Overworld for now...
    world = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(0);

    int worldLimit = 30000000 - margin;
    // Note: getActualHeight() could be better (at least for the Nether), but it would return 128 for the End too...
    int worldHeight = world != null ? world.getHeight() : 256;
    double posX = MathHelper.clamp(pos.x * scaleX, -worldLimit, worldLimit);
    double posY = MathHelper.clamp(pos.y * scaleY, 0, worldHeight);
    double posZ = MathHelper.clamp(pos.z * scaleZ, -worldLimit, worldLimit);

    if (world != null)
    {
        WorldBorder border = world.getWorldBorder();
        margin = Math.min(margin, (int)(border.getDiameter() / 2));

        posX = MathHelper.clamp(pos.x * scaleX, border.minX() + margin, border.maxX() - margin);
        posZ = MathHelper.clamp(pos.z * scaleZ, border.minZ() + margin, border.maxZ() - margin);
        //System.out.printf("border size: %.2f posX: %.4f posY: %.4f posZ: %.4f\n", border.getDiameter(), posX, posY, posZ);
        //System.out.printf("border: %s (%s)\n", border.getClass().getName(), border);
    }

    return new Vec3d(posX, posY, posZ);
}
 
Example 5
Source File: BiomeHandler.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
public static void changeBiome(World world, int biomeId, BlockPos pos) {
	Chunk chunk = world.getChunkFromBlockCoords(pos);

	Biome biome = world.getBiome(pos);
	Biome biomeTo = Biome.getBiome(biomeId);
	
	if(biome == biomeTo)
		return;
	
	int y = 60;
	if(biome.topBlock != biomeTo.topBlock) {
		BlockPos yy = world.getHeight(pos);
		
		while(!world.getBlockState(yy.down()).isOpaqueCube() && yy.getY() > 0)
			yy = yy.down();
		
		if(world.getBlockState(yy.down()) == biome.topBlock)
			world.setBlockState(yy.down(), biomeTo.topBlock);
	}

	byte[] biomeArr = chunk.getBiomeArray();
	try {
		biomeArr[(pos.getX() & 15) + (pos.getZ() & 15)*16] = (byte)biomeId;
	} catch (IndexOutOfBoundsException e) {
		e.printStackTrace();
	}

	PacketHandler.sendToNearby(new PacketBiomeIDChange(chunk, world, new HashedBlockPosition(pos)), world.provider.getDimension(), pos, 256);
}
 
Example 6
Source File: BiomeAridHighland.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void decorate(World worldIn, Random rand, BlockPos pos) {
	if (net.minecraftforge.event.terraingen.TerrainGen.decorate(worldIn, rand, pos, DecorateBiomeEvent.Decorate.EventType.TREE)) {
		if (rand.nextInt(5) == 0) {
			int k6 = rand.nextInt(16) + 8;
			int l = rand.nextInt(16) + 8;
			BlockPos blockpos = worldIn.getHeight(pos.add(k6, 0, l));
			OAK_SHRUB_FEATURE.generate(worldIn, rand, blockpos);
		}
	}

	super.decorate(worldIn, rand, pos);
}
 
Example 7
Source File: BiomeWoodlands.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void decorate(World worldIn, Random rand, BlockPos pos) {
	if (net.minecraftforge.event.terraingen.TerrainGen.decorate(worldIn, rand, pos, net.minecraftforge.event.terraingen.DecorateBiomeEvent.Decorate.EventType.TREE)) {
		int genChance = rand.nextInt(5);
		if (genChance == 0) {
			int k6 = rand.nextInt(16) + 8;
			int l = rand.nextInt(16) + 8;
			BlockPos blockpos = worldIn.getHeight(pos.add(k6, 0, l));
			FALLEN_TREE_FEATURE.generate(worldIn, rand, blockpos);
		}
	}
	super.decorate(worldIn, rand, pos);
}
 
Example 8
Source File: BiomeCliffs.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void decorate(World worldIn, Random rand, BlockPos pos) {
    if (!TraverseConfig.disallowBoulders && net.minecraftforge.event.terraingen.TerrainGen.decorate(worldIn, rand, pos, DecorateBiomeEvent.Decorate.EventType.ROCK)) {
        int genChance = rand.nextInt(9);
        if (genChance == 0) {
            int k6 = rand.nextInt(16) + 8;
            int l = rand.nextInt(16) + 8;
            BlockPos blockpos = worldIn.getHeight(pos.add(k6, 0, l));
            COBBLESTONE_BOULDER_FEATURE.generate(worldIn, rand, blockpos);
        }
    }
    super.decorate(worldIn, rand, pos);
}
 
Example 9
Source File: BiomeTofuHills.java    From TofuCraftReload with MIT License 5 votes vote down vote up
@Override
    public void decorate(World worldIn, Random randomIn, BlockPos pos)
    {
        super.decorate(worldIn, randomIn, pos);
        
        BlockPos.MutableBlockPos mutable = new BlockPos.MutableBlockPos();
        for (int k = 0; k < 1; ++k)
        {
            int x = pos.getX() + randomIn.nextInt(16) + 8;
            int z = pos.getZ() + randomIn.nextInt(16) + 8;

            int y = worldIn.getHeight(x, z) - 1;
            
            mutable.setPos(x, y, z);
//            TOO LAG
//            if (y > 80 && worldIn.getBlockState(mutable).getBlock() == BlockLoader.tofuTerrain)
//            {
//                if (worldIn.getBlockState(mutable.east()).getBlock() == BlockLoader.tofuTerrain
//                        && worldIn.getBlockState(mutable.south()).getBlock() == BlockLoader.tofuTerrain
//                        && worldIn.getBlockState(mutable.west()).getBlock() == BlockLoader.tofuTerrain
//                        && worldIn.getBlockState(mutable.north()).getBlock() == BlockLoader.tofuTerrain)
//                {
//                    int h = randomIn.nextInt(3) + 3;
//                    for (int i = 0; i < h; i++)
//                    {
//                        worldIn.setBlockState(new BlockPos(mutable.setPos(x, y + i, z)), BlockLoader.SOYMILK.getDefaultState(), 2);
//                    }
//                }
//            }
        }

    }
 
Example 10
Source File: WorldGenMapleTree.java    From Sakura_mod with MIT License 4 votes vote down vote up
public boolean generate(World worldIn, Random rand, BlockPos position) {
      int i = rand.nextInt(3) + this.minTreeHeight;
      boolean flag = true;

      if (position.getY() >= 1 && position.getY() + i + 1 <= worldIn.getHeight()) {
          for (int j = position.getY(); j <= position.getY() + 1 + i; ++j) {
              int k = 1;

              if (j == position.getY()) {
                  k = 0;
              }

              if (j >= position.getY() + 1 + i - 2) {
                  k = 2;
              }

              BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();

              for (int l = position.getX() - k; l <= position.getX() + k && flag; ++l) {
                  for (int i1 = position.getZ() - k; i1 <= position.getZ() + k && flag; ++i1) {
                      if (j >= 0 && j < worldIn.getHeight()) {
                          if (!this.isReplaceable(worldIn, blockpos$mutableblockpos.setPos(l, j, i1))) {
                              flag = false;
                          }
                      } else {
                          flag = false;
                      }
                  }
              }
          }

          if (!flag) {
              return false;
          }
	IBlockState state = worldIn.getBlockState(position.down());

	if (state.getBlock().canSustainPlant(state, worldIn, position.down(), net.minecraft.util.EnumFacing.UP, (net.minecraft.block.BlockSapling) Blocks.SAPLING) && position.getY() < worldIn.getHeight() - i - 1) {
	    state.getBlock().onPlantGrow(state, worldIn, position.down(), position);

	    for (int i3 = position.getY() - 3 + i; i3 <= position.getY() + i; ++i3) {
	        int i4 = i3 - (position.getY() + i);
	        int j1 = 1 - i4 / 2;

	        for (int k1 = position.getX() - j1; k1 <= position.getX() + j1; ++k1) {
	            int l1 = k1 - position.getX();

	            for (int i2 = position.getZ() - j1; i2 <= position.getZ() + j1; ++i2) {
	                int j2 = i2 - position.getZ();

	                if (Math.abs(l1) != j1 || Math.abs(j2) != j1 || rand.nextInt(2) != 0 && i4 != 0) {
	                    BlockPos blockpos = new BlockPos(k1, i3, i2);
	                    state = worldIn.getBlockState(blockpos);

	                    if (state.getBlock().isAir(state, worldIn, blockpos) || state.getBlock().isLeaves(state, worldIn, blockpos) || state.getMaterial() == Material.VINE) {
	                        this.setBlockAndNotifyAdequately(worldIn, blockpos, this.metaLeaves);
	                    }
	                }
	            }
	        }
	    }

	    for (int j3 = 0; j3 < i; ++j3) {
	        BlockPos upN = position.up(j3);
	        state = worldIn.getBlockState(upN);

	        if (state.getBlock().isAir(state, worldIn, upN) || state.getBlock().isLeaves(state, worldIn, upN) || state.getMaterial() == Material.VINE) {
	            this.setBlockAndNotifyAdequately(worldIn, position.up(j3), this.metaWood);

	            if (this.generateSap && j3 == 1) {
	                if (worldIn.getBlockState(position.add(0, j3, 0))==this.metaWood) {
	                    this.addSapLog(worldIn, position.add(0, j3, 0));
	                }

	            }
	        }
	    }
	    fallenLeaves(worldIn, position,4,2,4, this.metaFallenLeaves);
	    
	    return true;
	}
	return false;
      }
return false;
  }
 
Example 11
Source File: WorldGenSakuraTree.java    From Sakura_mod with MIT License 4 votes vote down vote up
public boolean generate(World worldIn, Random rand, BlockPos position) {
      int i = rand.nextInt(3) + this.minTreeHeight;
      boolean flag = true;

      if (position.getY() >= 1 && position.getY() + i + 1 <= worldIn.getHeight()) {
          for (int j = position.getY(); j <= position.getY() + 1 + i; ++j) {
              int k = 1;

              if (j == position.getY()) {
                  k = 0;
              }

              if (j >= position.getY() + 1 + i - 2) {
                  k = 2;
              }

              BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();

              for (int l = position.getX() - k; l <= position.getX() + k && flag; ++l) {
                  for (int i1 = position.getZ() - k; i1 <= position.getZ() + k && flag; ++i1) {
                      if (j >= 0 && j < worldIn.getHeight()) {
                          if (!this.isReplaceable(worldIn, blockpos$mutableblockpos.setPos(l, j, i1))) {
                              flag = false;
                          }
                      } else {
                          flag = false;
                      }
                  }
              }
          }

          if (!flag) {
              return false;
          }
	IBlockState state = worldIn.getBlockState(position.down());

	if (state.getBlock().canSustainPlant(state, worldIn, position.down(), net.minecraft.util.EnumFacing.UP, (net.minecraft.block.BlockSapling) Blocks.SAPLING) && position.getY() < worldIn.getHeight() - i - 1) {
	    state.getBlock().onPlantGrow(state, worldIn, position.down(), position);

	    for (int i3 = position.getY() - 3 + i; i3 <= position.getY() + i; ++i3) {
	        int i4 = i3 - (position.getY() + i);
	        int j1 = 1 - i4 / 2;

	        for (int k1 = position.getX() - j1; k1 <= position.getX() + j1; ++k1) {
	            int l1 = k1 - position.getX();

	            for (int i2 = position.getZ() - j1; i2 <= position.getZ() + j1; ++i2) {
	                int j2 = i2 - position.getZ();

	                if (Math.abs(l1) != j1 || Math.abs(j2) != j1 || rand.nextInt(2) != 0 && i4 != 0) {
	                    BlockPos blockpos = new BlockPos(k1, i3, i2);
	                    state = worldIn.getBlockState(blockpos);

	                    if (state.getBlock().isAir(state, worldIn, blockpos) || state.getBlock().isLeaves(state, worldIn, blockpos) || state.getMaterial() == Material.VINE) {
	                        this.setBlockAndNotifyAdequately(worldIn, blockpos, this.metaLeaves);
	                    }
	                }
	            }
	        }
	    }

	    for (int j3 = 0; j3 < i; ++j3) {
	        BlockPos upN = position.up(j3);
	        state = worldIn.getBlockState(upN);

	        if (state.getBlock().isAir(state, worldIn, upN) || state.getBlock().isLeaves(state, worldIn, upN) || state.getMaterial() == Material.VINE) {
	            this.setBlockAndNotifyAdequately(worldIn, position.up(j3), this.metaWood);

	        }
	    }

	    return true;
	}
	return false;
      }
return false;
  }
 
Example 12
Source File: WorldGenMapleTreeGreen.java    From Sakura_mod with MIT License 4 votes vote down vote up
public boolean generate(World worldIn, Random rand, BlockPos position) {
      int i = rand.nextInt(3) + this.minTreeHeight;
      boolean flag = true;

      if (position.getY() >= 1 && position.getY() + i + 1 <= worldIn.getHeight()) {
          for (int j = position.getY(); j <= position.getY() + 1 + i; ++j) {
              int k = 1;

              if (j == position.getY()) {
                  k = 0;
              }

              if (j >= position.getY() + 1 + i - 2) {
                  k = 2;
              }

              BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();

              for (int l = position.getX() - k; l <= position.getX() + k && flag; ++l) {
                  for (int i1 = position.getZ() - k; i1 <= position.getZ() + k && flag; ++i1) {
                      if (j >= 0 && j < worldIn.getHeight()) {
                          if (!this.isReplaceable(worldIn, blockpos$mutableblockpos.setPos(l, j, i1))) {
                              flag = false;
                          }
                      } else {
                          flag = false;
                      }
                  }
              }
          }

          if (!flag) {
              return false;
          }
	IBlockState state = worldIn.getBlockState(position.down());

	if (state.getBlock().canSustainPlant(state, worldIn, position.down(), net.minecraft.util.EnumFacing.UP, (net.minecraft.block.BlockSapling) Blocks.SAPLING) && position.getY() < worldIn.getHeight() - i - 1) {
	    state.getBlock().onPlantGrow(state, worldIn, position.down(), position);

	    for (int i3 = position.getY() - 3 + i; i3 <= position.getY() + i; ++i3) {
	        int i4 = i3 - (position.getY() + i);
	        int j1 = 1 - i4 / 2;

	        for (int k1 = position.getX() - j1; k1 <= position.getX() + j1; ++k1) {
	            int l1 = k1 - position.getX();

	            for (int i2 = position.getZ() - j1; i2 <= position.getZ() + j1; ++i2) {
	                int j2 = i2 - position.getZ();

	                if (Math.abs(l1) != j1 || Math.abs(j2) != j1 || rand.nextInt(2) != 0 && i4 != 0) {
	                    BlockPos blockpos = new BlockPos(k1, i3, i2);
	                    state = worldIn.getBlockState(blockpos);

	                    if (state.getBlock().isAir(state, worldIn, blockpos) || state.getBlock().isLeaves(state, worldIn, blockpos) || state.getMaterial() == Material.VINE) {
	                        this.setBlockAndNotifyAdequately(worldIn, blockpos, this.metaLeaves);
	                      BlockPos fruitBlockPos = new BlockPos(k1, i3 - 1, i2);
	                      BlockPos blockBelowFruitPos = new BlockPos(k1, i3 - 2, i2);
	                      if (worldIn.isAirBlock(fruitBlockPos)) 
	                          if (worldIn.isAirBlock(blockBelowFruitPos) && i3 > 2) 
	                              if (rand.nextInt(4) == 0) 
	                                  this.setBlockAndNotifyAdequately(worldIn,fruitBlockPos, BlockLoader.CHESTNUTBURR.getDefaultState());
	                    }
	                }
	            }
	        }
	    }

	    for (int j3 = 0; j3 < i; ++j3) {
	        BlockPos upN = position.up(j3);
	        state = worldIn.getBlockState(upN);

	        if (state.getBlock().isAir(state, worldIn, upN) || this.isBurr(state, worldIn, upN) || state.getBlock().isLeaves(state, worldIn, upN) || state.getMaterial() == Material.VINE) {
	            this.setBlockAndNotifyAdequately(worldIn, position.up(j3), this.metaWood);

	            if (this.generateSap && j3 == 1) {
	                if (worldIn.getBlockState(position.add(0, j3, 0))==this.metaWood) {
	                    this.addSapLog(worldIn, position.add(0, j3, 0));
	                }

	            }
	        }
	    }
	    fallenLeaves(worldIn, position,4,2,4, this.metaFallenLeaves);
	    
	    return true;
	}
	return false;
      }
return false;
  }
 
Example 13
Source File: BlockNattoBed.java    From TofuCraftReload with MIT License 4 votes vote down vote up
public static boolean isValidPlaceForDriedTofu(World world, BlockPos pos) {

        return world.getBiomeForCoordsBody(pos).getTemperature(pos) < 0.15F
                && world.getHeight(pos.getX(), pos.getZ()) - 10 < pos.getY()
                && world.isAirBlock(pos.up());
    }
 
Example 14
Source File: BlockBarrel.java    From TofuCraftReload with MIT License 4 votes vote down vote up
public static boolean isValidPlaceForDriedTofu(World world, BlockPos pos) {

        return world.getBiomeForCoordsBody(pos).getTemperature(pos) < 0.15F
                && world.getHeight(pos.getX(), pos.getZ()) - 10 < pos.getY()
                && world.isAirBlock(pos.up());
    }
 
Example 15
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 16
Source File: BlockTofu.java    From TofuCraftReload with MIT License 4 votes vote down vote up
public static boolean isValidPlaceForDriedTofu(World world, BlockPos pos) {

        return world.getBiomeForCoordsBody(pos).getTemperature(pos) < 0.15F
                && world.getHeight(pos.getX(), pos.getZ()) - 10 < pos.getY()
                && world.isAirBlock(pos.up());
    }
 
Example 17
Source File: MapGenLander.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@SubscribeEvent
public void populateChunkPostEvent(PopulateChunkEvent.Post event) {
	World worldIn = event.getWorld();
	BlockPos position = new BlockPos(16*event.getChunkX() + 3,0, 16*event.getChunkZ() + 11);

	if(DimensionManager.getInstance().getDimensionProperties(worldIn.provider.getDimension()).getName().equals("Luna") && position.getX() == 67 && position.getZ() == 2347) {

		position = worldIn.getHeight(position).down();
		
		worldIn.setBlockState(position.add(0, 0, 3), Blocks.STONE_SLAB.getDefaultState().withProperty(BlockSlab.HALF, EnumBlockHalf.TOP));
		worldIn.setBlockState(position.add(0, 0, -3), Blocks.STONE_SLAB.getDefaultState().withProperty(BlockSlab.HALF, EnumBlockHalf.TOP));
		worldIn.setBlockState(position.add(3, 0, 0), Blocks.STONE_SLAB.getDefaultState().withProperty(BlockSlab.HALF, EnumBlockHalf.TOP));
		worldIn.setBlockState(position.add(-3, 0, 0), Blocks.STONE_SLAB.getDefaultState().withProperty(BlockSlab.HALF, EnumBlockHalf.TOP));
		
		position = position.up();

		worldIn.setBlockState(position, AdvancedRocketryBlocks.blockEngine.getDefaultState());
		worldIn.setBlockState(position.add(0, 0, 3), Blocks.IRON_BARS.getDefaultState());
		worldIn.setBlockState(position.add(0, 0, -3), Blocks.IRON_BARS.getDefaultState());
		worldIn.setBlockState(position.add(3, 0, 0), Blocks.IRON_BARS.getDefaultState());
		worldIn.setBlockState(position.add(-3, 0, 0), Blocks.IRON_BARS.getDefaultState());

		position = position.up();
		worldIn.setBlockState(position.add(0, 0, 3), Blocks.IRON_BARS.getDefaultState());
		worldIn.setBlockState(position.add(0, 0, -3), Blocks.IRON_BARS.getDefaultState());
		worldIn.setBlockState(position.add(3, 0, 0), Blocks.IRON_BARS.getDefaultState());
		worldIn.setBlockState(position.add(-3, 0, 0), Blocks.IRON_BARS.getDefaultState());

		for(int x = -1; x <= 1; x++ ) {
			worldIn.setBlockState(position.add(-2, 0, x), Blocks.GOLD_BLOCK.getDefaultState());
			worldIn.setBlockState(position.add(2, 0, x), Blocks.GOLD_BLOCK.getDefaultState());
			worldIn.setBlockState(position.add(x, 0, -2), Blocks.GOLD_BLOCK.getDefaultState());
			worldIn.setBlockState(position.add(x, 0, 2), Blocks.GOLD_BLOCK.getDefaultState());
			for(int z = -1; z <= 1; z++) {
				worldIn.setBlockState(position.add(x, 0, z), Blocks.IRON_BLOCK.getDefaultState());
			}
		}

		position = position.up();
		worldIn.setBlockState(position.add(0, 0, 3), Blocks.IRON_BARS.getDefaultState());
		worldIn.setBlockState(position.add(0, 0, -3), Blocks.IRON_BARS.getDefaultState());
		worldIn.setBlockState(position.add(3, 0, 0), Blocks.IRON_BARS.getDefaultState());
		worldIn.setBlockState(position.add(-3, 0, 0), Blocks.IRON_BARS.getDefaultState());

		for(int x = -1; x <= 1; x++ ) {
			worldIn.setBlockState(position.add(-2, 0, x), Blocks.GOLD_BLOCK.getDefaultState());
			worldIn.setBlockState(position.add(2, 0, x), Blocks.GOLD_BLOCK.getDefaultState());
			worldIn.setBlockState(position.add(x, 0, -2), Blocks.GOLD_BLOCK.getDefaultState());
			worldIn.setBlockState(position.add(x, 0, 2), Blocks.GOLD_BLOCK.getDefaultState());
		}

		worldIn.setBlockState(position.add(0, 0, 1), Blocks.IRON_BLOCK.getDefaultState());
		worldIn.setBlockState(position.add(1, 0, 0), Blocks.IRON_BLOCK.getDefaultState());
		worldIn.setBlockState(position.add(0, 0, -1), Blocks.IRON_BLOCK.getDefaultState());
		worldIn.setBlockState(position.add(-1, 0, 0), Blocks.IRON_BLOCK.getDefaultState());

		position = worldIn.getHeight(position.add(10,0,15));

		for(int x = 0; x <= 4; x++ ) 
			worldIn.setBlockState(position.add(0,x,0), Blocks.IRON_BARS.getDefaultState());

		worldIn.setBlockState(position.add(1,4,0), Blocks.IRON_BARS.getDefaultState());
		worldIn.setBlockState(position.add(2,4,0), Blocks.IRON_BARS.getDefaultState());
	}
}
 
Example 18
Source File: WorldGenApricotTrees.java    From TofuCraftReload with MIT License 4 votes vote down vote up
public boolean generate(World worldIn, Random rand, BlockPos position) {
    int i = rand.nextInt(3) + 4;
    boolean flag = true;

    if (position.getY() >= 1 && position.getY() + i + 1 <= worldIn.getHeight()) {
        for (int j = position.getY(); j <= position.getY() + 1 + i; ++j) {
            int k = 1;

            if (j == position.getY()) {
                k = 0;
            }

            if (j >= position.getY() + 1 + i - 2) {
                k = 2;
            }

            BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();

            for (int l = position.getX() - k; l <= position.getX() + k && flag; ++l) {
                for (int i1 = position.getZ() - k; i1 <= position.getZ() + k && flag; ++i1) {
                    if (j >= 0 && j < worldIn.getHeight()) {
                        if (!this.isReplaceable(worldIn, blockpos$mutableblockpos.setPos(l, j, i1))) {
                            flag = false;
                        }
                    } else {
                        flag = false;
                    }
                }
            }
        }

        if (!flag) {
            return false;
        } else {
            IBlockState state = worldIn.getBlockState(position.down());

            if (state.getBlock().canSustainPlant(state, worldIn, position.down(), net.minecraft.util.EnumFacing.UP, BlockLoader.APRICOT_SAPLING) && position.getY() < worldIn.getHeight() - i - 1) {
                state.getBlock().onPlantGrow(state, worldIn, position.down(), position);

                for (int i3 = position.getY() - 3 + i; i3 <= position.getY() + i; ++i3) {
                    int i4 = i3 - (position.getY() + i);
                    int j1 = 1 - i4 / 2;

                    for (int k1 = position.getX() - j1; k1 <= position.getX() + j1; ++k1) {
                        int l1 = k1 - position.getX();

                        for (int i2 = position.getZ() - j1; i2 <= position.getZ() + j1; ++i2) {
                            int j2 = i2 - position.getZ();

                            if (Math.abs(l1) != j1 || Math.abs(j2) != j1 || rand.nextInt(2) != 0 && i4 != 0) {
                                BlockPos blockpos = new BlockPos(k1, i3, i2);
                                state = worldIn.getBlockState(blockpos);

                                if (state.getBlock().isAir(state, worldIn, blockpos) || state.getBlock().isLeaves(state, worldIn, blockpos) || state.getMaterial() == Material.VINE) {
                                    this.setBlockAndNotifyAdequately(worldIn, blockpos, BlockLoader.APRICOT_LEAVE.getDefaultState());
                                }
                            }
                        }
                    }
                }
                for (int j3 = 0; j3 < i; ++j3) {
                    BlockPos upN = position.up(j3);
                    state = worldIn.getBlockState(upN);

                    if (state.getBlock().isAir(state, worldIn, upN) || state.getBlock().isLeaves(state, worldIn, upN) || state.getMaterial() == Material.VINE) {
                        this.setBlockAndNotifyAdequately(worldIn, position.up(j3), Blocks.LOG.getDefaultState());

                    }
                }

                return true;
            } else {
                return false;
            }
        }
    } else {
        return false;
    }
}
 
Example 19
Source File: WorldGenTofuTrees.java    From TofuCraftReload with MIT License 4 votes vote down vote up
public boolean generate(World worldIn, Random rand, BlockPos position)
{
    int i = rand.nextInt(3) + 4;
    boolean flag = true;

    if (position.getY() >= 1 && position.getY() + i + 1 <= worldIn.getHeight())
    {
        for (int j = position.getY(); j <= position.getY() + 1 + i; ++j)
        {
            int k = 1;

            if (j == position.getY())
            {
                k = 0;
            }

            if (j >= position.getY() + 1 + i - 2)
            {
                k = 2;
            }

            BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos();

            for (int l = position.getX() - k; l <= position.getX() + k && flag; ++l)
            {
                for (int i1 = position.getZ() - k; i1 <= position.getZ() + k && flag; ++i1)
                {
                    if (j >= 0 && j < worldIn.getHeight())
                    {
                        if (!this.isReplaceable(worldIn,blockpos$mutableblockpos.setPos(l, j, i1)))
                        {
                            flag = false;
                        }
                    }
                    else
                    {
                        flag = false;
                    }
                }
            }
        }

        if (!flag)
        {
            return false;
        }
        else
        {
            IBlockState state = worldIn.getBlockState(position.down());
            int j1;
            if (state.getBlock().canSustainPlant(state, worldIn, position.down(), net.minecraft.util.EnumFacing.UP, BlockLoader.TOFU_SAPLING) && position.getY() < worldIn.getHeight() - i - 1)
            {
                state.getBlock().onPlantGrow(state, worldIn, position.down(), position);

                for (int i3 = position.getY() - 3 + i; i3 <= position.getY() + i; ++i3)
                {
                    j1 = i / 3;

                    for (int k1 = position.getX() - j1; k1 <= position.getX() + j1; ++k1)
                    {
                        for (int i2 = position.getZ() - j1; i2 <= position.getZ() + j1; ++i2)
                        {
                            BlockPos blockpos = new BlockPos(k1, i3, i2);
                            state = worldIn.getBlockState(blockpos);

                            if (state.getBlock().isAir(state, worldIn, blockpos) || state.getBlock().isLeaves(state, worldIn, blockpos) || state.getMaterial() == Material.VINE)
                            {
                                this.setBlockAndNotifyAdequately(worldIn, blockpos, BlockLoader.TOFU_LEAVE.getDefaultState());
                            }
                        }
                    }
                }
                
                for (int j3 = 0; j3 < i; ++j3)
                {
                    BlockPos upN = position.up(j3);
                    state = worldIn.getBlockState(upN);

                    if (state.getBlock().isAir(state, worldIn, upN) || state.getBlock().isLeaves(state, worldIn, upN) || state.getMaterial() == Material.VINE)
                    {
                        this.setBlockAndNotifyAdequately(worldIn, position.up(j3), BlockLoader.ISHITOFU.getDefaultState());

                    }
                }

                return true;
            }
            else
            {
                return false;
            }
        }
    }
    else
    {
        return false;
    }
}
 
Example 20
Source File: WorldGenFallenTree.java    From Traverse-Legacy-1-12-2 with MIT License 4 votes vote down vote up
public boolean generate(World worldIn, Random rand, BlockPos position) {
    int num = rand.nextInt(5);
    EnumFacing orientation;
    if (num == 0) {
        orientation = EnumFacing.EAST;
        stateWood = stateWood.withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.X);
    } else if (num == 1) {
        orientation = EnumFacing.WEST;
        stateWood = stateWood.withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.X);
    } else if (num == 1) {
        orientation = EnumFacing.SOUTH;
        stateWood = stateWood.withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.Z);
    } else {
        orientation = EnumFacing.NORTH;
        stateWood = stateWood.withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.Z);
    }
    int i = rand.nextInt(2) + this.minTreeLength;
    boolean flag = true;

    if (position.getY() >= 1 && position.getY() + i + 1 <= worldIn.getHeight()) {
        for (int j = position.getY(); j <= position.getY() + 1 + i; ++j) {
            int k = 1;

            if (j == position.getY()) {
                k = 0;
            }

            if (j >= position.getY() + 1 + i - 2) {
                k = 2;
            }

            BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos();

            for (int l = position.getX() - k; l <= position.getX() + k && flag; ++l) {
                for (int i1 = position.getZ() - k; i1 <= position.getZ() + k && flag; ++i1) {
                    if (j >= 0 && j < worldIn.getHeight()) {
                        if (!this.isReplaceable(worldIn, mutablePos.setPos(l, j, i1))) {
                            flag = false;
                        }
                    } else {
                        flag = false;
                    }
                }
            }
        }

        if (!flag) {
            return false;
        } else {
            IBlockState state = worldIn.getBlockState(position.down());

            if (state.getBlock().canSustainPlant(state, worldIn, position.down(), net.minecraft.util.EnumFacing.UP, (net.minecraft.block.BlockSapling) Blocks.SAPLING) && position.getY() < worldIn.getHeight() - i - 1) {
                state.getBlock().onPlantGrow(state, worldIn, position.down(), position);

                for (int j3 = 0; j3 < i; ++j3) {
                    BlockPos offsetPos = position.offset(orientation, j3);
                    state = worldIn.getBlockState(offsetPos);

                    if (state.getBlock().isAir(state, worldIn, offsetPos) || state.getBlock().isLeaves(state, worldIn, offsetPos) || state.getMaterial() == Material.VINE) {
                        this.setBlockAndNotifyAdequately(worldIn, position.offset(orientation, j3), this.stateWood);
                    }
                }
                return true;
            } else {
                return false;
            }
        }
    } else {
        return false;
    }
}