Java Code Examples for net.minecraft.world.IWorld#isAir()

The following examples show how to use net.minecraft.world.IWorld#isAir() . 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: SpiderLairFeature.java    From the-hallow with MIT License 6 votes vote down vote up
@Override
public boolean generate(IWorld iWorld, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random random, BlockPos pos, DefaultFeatureConfig defaultFeatureConfig) {
	if (iWorld.getBlockState(pos.down()).getBlock() == HallowedBlocks.DECEASED_GRASS_BLOCK) {
		setSpawner(iWorld, pos, EntityType.SPIDER);
		
		for (int i = 0; i < 64; ++i) {
			BlockPos pos_2 = pos.add(random.nextInt(6) - random.nextInt(6), random.nextInt(3) - random.nextInt(3), random.nextInt(6) - random.nextInt(6));
			if (iWorld.isAir(pos_2) || iWorld.getBlockState(pos_2).getBlock() == HallowedBlocks.DECEASED_GRASS_BLOCK) {
				iWorld.setBlockState(pos_2, Blocks.COBWEB.getDefaultState(), 2);
			}
		}
		
		BlockPos chestPos = pos.add(random.nextInt(4) - random.nextInt(4), 0, random.nextInt(4) - random.nextInt(4));
		iWorld.setBlockState(chestPos, StructurePiece.method_14916(iWorld, chestPos, Blocks.CHEST.getDefaultState()), 2);
		LootableContainerBlockEntity.setLootTable(iWorld, random, chestPos, TheHallow.id("chests/spider_lair"));
		
		return true;
	} else {
		return false;
	}
}
 
Example 2
Source File: HallowedCactusFeature.java    From the-hallow with MIT License 6 votes vote down vote up
@Override
public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> generator, Random random, BlockPos pos, DefaultFeatureConfig config) {
	for (int i = 0; i < 10; i++) {
		BlockPos pos2 = pos.add(random.nextInt(8) - random.nextInt(8), random.nextInt(4) - random.nextInt(4), random.nextInt(8) - random.nextInt(8));
		if (world.isAir(pos2)) {
			int height = 1 + random.nextInt(random.nextInt(3) + 1);
			
			for (int j = 0; j < height; j++) {
				if (HallowedBlocks.RESTLESS_CACTUS.getDefaultState().canPlaceAt(world, pos2)) {
					world.setBlockState(pos2.up(j), HallowedBlocks.RESTLESS_CACTUS.getDefaultState(), 2);
				}
			}
		}
	}
	
	return true;
}
 
Example 3
Source File: DeaderBushFeature.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> generator, Random random, BlockPos pos, DefaultFeatureConfig config) {
	for (BlockState state1 = world.getBlockState(pos); (state1.isAir() || state1.matches(BlockTags.LEAVES)) && pos.getY() > 0; state1 = world.getBlockState(pos)) {
		pos = pos.down();
	}
	
	for (int int_1 = 0; int_1 < 4; ++int_1) {
		BlockPos pos2 = pos.add(random.nextInt(8) - random.nextInt(8), random.nextInt(4) - random.nextInt(4), random.nextInt(8) - random.nextInt(8));
		if (world.isAir(pos2) && state.canPlaceAt(world, pos2)) {
			world.setBlockState(pos2, state, 2);
		}
	}
	
	return true;
}
 
Example 4
Source File: DeceasedWildCropFeature.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random random, BlockPos blockPos, DefaultFeatureConfig defaultFeatureConfig) {
	int numCrop = 0;
	
	for (int i = 0; i < 64; ++i) {
		BlockPos randomBlockPos = blockPos.add(random.nextInt(8) - random.nextInt(8), random.nextInt(4) - random.nextInt(4), random.nextInt(8) - random.nextInt(8));
		if (world.isAir(randomBlockPos) && world.getBlockState(randomBlockPos.down()).getBlock() == HallowedBlocks.DECEASED_GRASS_BLOCK) {
			world.setBlockState(randomBlockPos, this.crop, 2);
			++numCrop;
		}
	}
	
	return numCrop > 0;
}
 
Example 5
Source File: RandomizedWildCropFeature.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> chunkGenerator, Random random, BlockPos blockPos, DefaultFeatureConfig defaultFeatureConfig) {
	int numCrop = 0;

	for (int i = 0; i < 64; ++i) {
		BlockPos randomBlockPos = blockPos.add(random.nextInt(8) - random.nextInt(8), random.nextInt(4) - random.nextInt(4), random.nextInt(8) - random.nextInt(8));
		if (world.isAir(randomBlockPos) && world.getBlockState(randomBlockPos.down()).getBlock() == HallowedBlocks.DECEASED_GRASS_BLOCK) {
			world.setBlockState(randomBlockPos, this.choiceSelector.getSelection(random, randomBlockPos), 2);
			++numCrop;
		}
	}

	return numCrop > 0;
}
 
Example 6
Source File: WitchWellFeature.java    From the-hallow with MIT License 4 votes vote down vote up
@Override
public boolean generate(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> gen, Random random, BlockPos pos, DefaultFeatureConfig config) {
	pos = pos.up();
	while (world.isAir(pos) && pos.getY() > 2) {
		pos = pos.down();
	}
	
	if (!CAN_GENERATE.test(world.getBlockState(pos))) {
		return false;
	}
	
	// Check for solid ground
	for (int x = -2; x <= 2; ++x) {
		for (int z = -2; z <= 2; ++z) {
			if (world.isAir(pos.add(x, -1, z)) && world.isAir(pos.add(x, -2, z))) {
				return false;
			}
		}
	}
	
	//System.out.println("Generating at " + pos);
	
	// Below-ground layer
	for (int y = -1; y <= 0; ++y) {
		for (int x = -2; x <= 2; ++x) {
			for (int z = -2; z <= 2; ++z) {
				world.setBlockState(pos.add(x, y, z), this.wall, 2);
			}
		}
	}
	
	// Fluid
	world.setBlockState(pos, this.fluid, 2);
	for (Direction direction : Direction.Type.HORIZONTAL) {
		world.setBlockState(pos.offset(direction), this.fluid, 2);
	}
	
	// Above-ground layer
	for (int x = -2; x <= 2; ++x) {
		for (int z = -2; z <= 2; ++z) {
			if (x == -2 || x == 2 || z == -2 || z == 2) {
				world.setBlockState(pos.add(x, 1, z), this.wall, 2);
			}
		}
	}
	
	// Slabs in the above-ground layer
	world.setBlockState(pos.add(2, 1, 0), this.slab, 2);
	world.setBlockState(pos.add(-2, 1, 0), this.slab, 2);
	world.setBlockState(pos.add(0, 1, 2), this.slab, 2);
	world.setBlockState(pos.add(0, 1, -2), this.slab, 2);
	
	// Witched pumpkin
	int pumpkinX = random.nextBoolean() ? -2 : 2;
	int pumpkinZ = random.nextBoolean() ? -2 : 2;
	Direction pumpkinFacing = Direction.fromHorizontal(random.nextInt(4));
	world.setBlockState(pos.add(pumpkinX, 2, pumpkinZ), getPumpkin(pumpkinFacing), 2);
	world.setBlockState(pos.add(0, 3, 0), this.lantern, 2);
	
	// Roof
	for (int x = -1; x <= 1; ++x) {
		for (int z = -1; z <= 1; ++z) {
			if (x == 0 && z == 0) {
				world.setBlockState(pos.add(x, 4, z), this.wall, 2);
			} else {
				world.setBlockState(pos.add(x, 4, z), this.slab, 2);
			}
		}
	}
	
	// Pillars
	for (int y = 1; y <= 3; ++y) {
		world.setBlockState(pos.add(-1, y, -1), this.wall, 2);
		world.setBlockState(pos.add(-1, y, 1), this.wall, 2);
		world.setBlockState(pos.add(1, y, -1), this.wall, 2);
		world.setBlockState(pos.add(1, y, 1), this.wall, 2);
	}
	
	return true;
}