Java Code Examples for net.minecraft.world.World.getTopSolidOrLiquidBlock()

The following are Jave code examples for showing how to use getTopSolidOrLiquidBlock() of the net.minecraft.world.World class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: harshencastle   File: WorldGen.java   Source Code and License Vote up 6 votes
private void flowerGenerator(BlockFlower flower, World worldIn, Random random, int chunkX, int chunkZ, float chancesToSpawn)
{
	for(int i = 0; i < chancesToSpawn; i++)
		if(random.nextFloat() < chancesToSpawn)
		{
			int x = chunkX * 16 + random.nextInt(16);
			int z = chunkZ * 16 + random.nextInt(16);
			BlockPos position = worldIn.getTopSolidOrLiquidBlock(new BlockPos(x, 0, z));
			BlockPos blockpos = position.add(random.nextInt(8) - random.nextInt(8), random.nextInt(4) - random.nextInt(4), random.nextInt(8) - random.nextInt(8));
	
	        if (worldIn.isAirBlock(blockpos) && (worldIn.provider.isSurfaceWorld() || blockpos.getY() < 255) && 
	        		flower.canBlockStay(worldIn, blockpos, flower.getDefaultState()))
	        {
	            worldIn.setBlockState(blockpos,flower.getDefaultState(), 2);
	        }
		}

}
 
Example 2
Project: Firma   File: FirmaTree.java   Source Code and License Vote up 5 votes
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
	//System.out.println("Generating "+bs+" at "+chunkX+", "+chunkZ);
	int x = random.nextInt(16);
	int z = random.nextInt(16);
	BlockPos pos = new BlockPos((chunkX*16)+x,0,(chunkZ*16)+z);
	pos = world.getTopSolidOrLiquidBlock(pos);
	//pos = pos.up();
	generate(world, random, pos);
}
 
Example 3
Project: Solar   File: ObeliskDecorator.java   Source Code and License Vote up 5 votes
@Override
void gen(World world, int x, int z, IChunkGenerator generator, IChunkProvider provider) {
	random.setSeed(world.getSeed());
	long good = random.nextLong();
	long succ = random.nextLong();

	good *= x >> 3;
	succ *= z >> 3;
	random.setSeed(good * succ * world.getSeed());
	//Generate
	if(GEN_CONFIG.MONOLITH_CONFIG.OBELISK_DECORATOR.rarity > 0D
			&& GEN_CONFIG.MONOLITH_CONFIG.OBELISK_DECORATOR.rarity / 100D > random.nextDouble()) {
		List<AxisAlignedBB> occupied = Lists.newArrayList();
		for(int i = 0; i < GEN_CONFIG.MONOLITH_CONFIG.OBELISK_DECORATOR.size; i++) {
			BlockPos top = world.getTopSolidOrLiquidBlock(randomVector().add(x, 0, z).toBlockPos());
			int below = random.nextInt(7);
			if(top.getY() > below) {
				top = top.add(0, -below, 0);
			}
			Template obelisk = obelisks.next().load(world);
			Rotation rotation = Rotation.values()[random.nextInt(4)];
			Vector3 vec = Vector3.create(obelisk.getSize()).rotate(rotation);
			AxisAlignedBB obeliskBB = new AxisAlignedBB(top, vec.add(top).toBlockPos()).grow(1);
			if(occupied.stream().noneMatch(bb -> bb.intersects(obeliskBB))) {
				PlacementSettings settings = new PlacementSettings();
				settings.setRotation(rotation);
				settings.setRandom(random);
				obelisk.addBlocksToWorld(world, top, settings);

				occupied.add(obeliskBB);
			}
		}
	}
}
 
Example 4
Project: harshencastle   File: PontusChunkProvider.java   Source Code and License Vote up 4 votes
private void performWorldGenSpawning(World worldIn, EnumCreatureType type, BlockPos pos ,int p_77191_2_, int p_77191_3_, int p_77191_4_, int p_77191_5_, Random randomIn)
  {
  	float amount;
  	switch (type) {
case MONSTER:
	amount = 0.1f;
	break;
default:
	amount = 0.3f;
	break;
}
  	List<SpawnListEntry> enteries = world.getBiome(pos).getSpawnableList(type);
  	SpawnListEntry entry = enteries.get(rand.nextInt(enteries.size()));
  	while (randomIn.nextFloat() < amount)
      {
          int i = entry.minGroupCount + randomIn.nextInt(1 + entry.maxGroupCount - entry.minGroupCount);
          IEntityLivingData ientitylivingdata = null;
          int j = p_77191_2_ + randomIn.nextInt(p_77191_4_);
          int k = p_77191_3_ + randomIn.nextInt(p_77191_5_);
          int l = j;
          int i1 = k;

          for (int j1 = 0; j1 < i; ++j1)
          {
              boolean flag = false;

              for (int k1 = 0; !flag && k1 < 4; ++k1)
              {
                  BlockPos blockpos = worldIn.getTopSolidOrLiquidBlock(new BlockPos(j, 0, k));

                  if (WorldEntitySpawner.canCreatureTypeSpawnAtLocation(EntityLiving.SpawnPlacementType.ON_GROUND, worldIn, blockpos))
                  {
                      EntityLiving entityliving;

                      try
                      {
                          entityliving = entry.newInstance(worldIn);
                      }
                      catch (Exception exception)
                      {
                          exception.printStackTrace();
                          continue;
                      }

                      entityliving.setLocationAndAngles((double)((float)j + 0.5F), (double)blockpos.getY(), (double)((float)k + 0.5F), randomIn.nextFloat() * 360.0F, 0.0F);
                      worldIn.spawnEntity(entityliving);
                      ientitylivingdata = entityliving.onInitialSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityliving)), ientitylivingdata);
                      flag = true;
                  }

                  j += randomIn.nextInt(5) - randomIn.nextInt(5);

                  for (k += randomIn.nextInt(5) - randomIn.nextInt(5); j < p_77191_2_ || j >= p_77191_2_ + p_77191_4_ || k < p_77191_3_ || k >= p_77191_3_ + p_77191_4_; k = i1 + randomIn.nextInt(5) - randomIn.nextInt(5))
                  {
                      j = l + randomIn.nextInt(5) - randomIn.nextInt(5);
                  }
              }
          }
      }
  }
 
Example 5
Project: Geolosys   File: ChunkData.java   Source Code and License Vote up 4 votes
private BlockPos getSamplePos(World world, ChunkPos chunkPos)
{
    return world.getTopSolidOrLiquidBlock(new BlockPos((chunkPos.x << 4) + random.nextInt(16), 0, (chunkPos.z << 4) + random.nextInt(16)));
}
 
Example 6
Project: Solar   File: MonolithStructure.java   Source Code and License Vote up 4 votes
@Override
void gen(World world, int x, int z, IChunkGenerator generator, IChunkProvider provider) {
	random.setSeed(world.getSeed());
	long good = random.nextLong();
	long succ = random.nextLong();

	good *= x >> 2;
	succ *= z >> 2;
	random.setSeed(good * succ ^ world.getSeed());
	//Generate
	if (GEN_CONFIG.MONOLITH_CONFIG.MONOLITH_STRUCTURE.rarity > 0D
			&& GEN_CONFIG.MONOLITH_CONFIG.MONOLITH_STRUCTURE.rarity / 100D > random.nextDouble()) {
		BlockPos origin = new BlockPos(x, 0, z);
		//Gen Monolith
		BlockPos surface = world.getTopSolidOrLiquidBlock(origin.add(8, 0, 8));
		BlockPos pos = origin.add(5, Math.max(surface.getY() - (5 + random.nextInt(3)), 8), 4);
		Structure.MONOLITH_CUBE.generate(world, pos.down(7), new PlacementSettings());
		//Randomize glyphs
		Vector3 start = Vector3.create(pos).add(0,-4,6);
		Arrays.stream(EnumFacing.HORIZONTALS).forEach(facing -> {
			for (int i = 0; i < 6; i++) {
				IBlockState glyph = ModBlocks.MONOLITHIC_GLYPH.getDefaultState().withProperty(State.GLYPH, random.nextInt(16));
				world.setBlockState(start.toBlockPos(), glyph);
				start.offset(facing.getOpposite(), 1);
			}
		});
		//Add loot
		BlockPos loot = pos.down(7).add(1, 1, 1);
		for (int i = 0; i < 6 + random.nextInt(6); i++) {
			if (GEN_CONFIG.MONOLITH_CONFIG.MONOLITH_STRUCTURE.loot / 100D > random.nextDouble()) {
				BlockPos inside = loot.add(random.nextInt(4), 0, random.nextInt(4));
				IBlockState pot = ModBlocks.LARGE_POT.getDefaultState().withProperty(State.POT_VARIANT, random.nextInt(3));
				world.setBlockState(inside, pot);
			}
		}
		//Gen ruin
		if (GEN_CONFIG.MONOLITH_CONFIG.MONOLITH_STRUCTURE.well) {
			Structure.MONOLITH_RUIN.generate(world, pos, new PlacementSettings());
		}
		int size = random.nextInt(GEN_CONFIG.MONOLITH_CONFIG.MONOLITH_STRUCTURE.size / 2);
		size += GEN_CONFIG.MONOLITH_CONFIG.MONOLITH_STRUCTURE.size / 2;
		for (int i = 0; i < size; i++) {
			BlockPos top = world.getTopSolidOrLiquidBlock(randomVector().add(x, 1, z).toBlockPos());
			int below = random.nextInt(3);
			if (top.getY() > below) {
				top = top.add(0, -below, 0);
			}
			world.setBlockState(top, ModBlocks.ASHEN.getDefaultState());
		}
	}
}