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

The following examples show how to use net.minecraft.world.IWorld#setBlockState() . 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: BarrowFeature.java    From the-hallow with MIT License 6 votes vote down vote up
private void generateBarrowColumn(IWorld world, Random rand, int lowY, int heightOffset, BlockPos.Mutable pos, SurfaceConfig surfaceConfig) {
	int upperY = lowY + heightOffset;
	
	for (int y = upperY; y >= lowY; --y) {
		pos.setY(y);
		if (y == upperY) {
			world.setBlockState(pos, surfaceConfig.getTopMaterial(), 19);
		} else if (y > upperY - 3) {
			world.setBlockState(pos, surfaceConfig.getUnderMaterial(), 19);
		} else if (y == lowY + 2 && rand.nextInt(32) == 0) {
			if (rand.nextInt(3) == 0) {
				setLootChest(world, pos, LOOT_TABLE, rand);
			} else {
				setSpawner(world, pos, BARROW_WIGHT);
			}
		} else {
			world.setBlockState(pos, y <= lowY + 1 ? STONE : AIR, 19);
		}
	}
}
 
Example 4
Source File: PumpkinPieBlock.java    From the-hallow with MIT License 6 votes vote down vote up
private ActionResult tryEat(IWorld iWorld, BlockPos pos, BlockState state, PlayerEntity player) {
	if (!player.canConsume(false)) {
		return ActionResult.PASS;
	}
	float saturation = 0.1F;
	TrinketComponent trinketPlayer = TrinketsApi.getTrinketComponent(player);
	ItemStack mainHandStack = trinketPlayer.getStack("hand:ring");
	ItemStack offHandStack = trinketPlayer.getStack("offhand:ring");
	if (mainHandStack.getItem().equals(HallowedItems.PUMPKIN_RING) || offHandStack.getItem().equals(HallowedItems.PUMPKIN_RING)) {
		saturation = 0.3F;
	}
	player.getHungerManager().add(2, saturation);
	int bites = state.get(BITES);
	if (bites > 1) {
		iWorld.setBlockState(pos, state.with(BITES, bites - 1), 3);
	} else {
		iWorld.removeBlock(pos, false);
	}
	return ActionResult.SUCCESS;
}
 
Example 5
Source File: IForgeBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Re-colors this block in the world.
 *
 * @param state   The current state
 * @param world   The world
 * @param pos     Block position
 * @param facing  ??? (this method has no usages)
 * @param color   Color to recolor to.
 * @return if the block was affected
 */
@SuppressWarnings("unchecked")
default boolean recolorBlock(BlockState state, IWorld world, BlockPos pos, Direction facing, DyeColor color) {
	for (Property<?> prop : state.getProperties()) {
		if (prop.getName().equals("color") && prop.getType() == DyeColor.class) {
			DyeColor current = (DyeColor) state.get(prop);

			if (current != color && prop.getValues().contains(color)) {
				world.setBlockState(pos, state.with(((Property<DyeColor>) prop), color), 3);
				return true;
			}
		}
	}

	return false;
}
 
Example 6
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 7
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 8
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 9
Source File: FeatureUtils.java    From the-hallow with MIT License 5 votes vote down vote up
default void setSpawner(IWorld world, BlockPos pos, EntityType<?> entity) {
	world.setBlockState(pos, Blocks.SPAWNER.getDefaultState(), 2);
	BlockEntity be = world.getBlockEntity(pos);
	if (be instanceof MobSpawnerBlockEntity) {
		((MobSpawnerBlockEntity) be).getLogic().setEntityId(entity);
	}
}
 
Example 10
Source File: FeatureUtils.java    From the-hallow with MIT License 5 votes vote down vote up
default void setLootChest(IWorld world, BlockPos pos, Identifier lootTable, Random rand) {
	world.setBlockState(pos, Blocks.CHEST.getDefaultState(), 2);
	
	BlockEntity entity = world.getBlockEntity(pos);
	if (entity instanceof ChestBlockEntity) {
		((ChestBlockEntity) entity).setLootTable(lootTable, rand.nextLong());
	}
}
 
Example 11
Source File: WitchWaterBubbleColumnBlock.java    From the-hallow with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction dir, BlockState state2, IWorld world, BlockPos pos, BlockPos pos2) {
	if (!state.canPlaceAt(world, pos)) {
		return HallowedBlocks.WITCH_WATER_BLOCK.getDefaultState();
	} else {
		if (dir == Direction.DOWN) {
			world.setBlockState(pos, HallowedBlocks.WITCH_WATER_BUBBLE_COLUMN.getDefaultState().with(DRAG, calculateDrag(world, pos2)), 2);
		} else if (dir == Direction.UP && state2.getBlock() != HallowedBlocks.WITCH_WATER_BUBBLE_COLUMN && isStillWater(world, pos2)) {
			world.getBlockTickScheduler().schedule(pos, this, this.getTickRate(world));
		}
		world.getFluidTickScheduler().schedule(pos, HallowedFluids.WITCH_WATER, HallowedFluids.WITCH_WATER.getTickRate(world));
		return super.getStateForNeighborUpdate(state, dir, state2, world, pos, pos2);
	}
}
 
Example 12
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;
}
 
Example 13
Source File: HallowedOreFeature.java    From the-hallow with MIT License 4 votes vote down vote up
protected boolean generateVeinPart(IWorld world, Random random, HallowedOreFeatureConfig oreFeatureConfig, double positiveX, double negativeX, double positiveZ, double negativeZ, double double_5, double double_6, int startX, int yPosition, int startZ, int xSize, int int_5) {
	int stonesPlaced = 0;
	BitSet bitSet = new BitSet(xSize * int_5 * xSize);
	Mutable blockPos = new Mutable();
	double[] doubles_1 = new double[oreFeatureConfig.size * 4];
	
	int counter;
	double currentX;
	double currentY;
	double currentZ;
	double double_15;
	for (counter = 0; counter < oreFeatureConfig.size; ++counter) {
		float progress = (float) counter / (float) oreFeatureConfig.size;
		currentX = MathHelper.lerp(progress, positiveX, negativeX);
		currentY = MathHelper.lerp(progress, double_5, double_6);
		currentZ = MathHelper.lerp(progress, positiveZ, negativeZ);
		double_15 = random.nextDouble() * (double) oreFeatureConfig.size / 16.0D;
		double double_11 = ((double) (MathHelper.sin(3.1415927F * progress) + 1.0F) * double_15 + 1.0D) / 2.0D;
		doubles_1[counter * 4 + 0] = currentX;
		doubles_1[counter * 4 + 1] = currentY;
		doubles_1[counter * 4 + 2] = currentZ;
		doubles_1[counter * 4 + 3] = double_11;
	}
	
	for (counter = 0; counter < oreFeatureConfig.size - 1; ++counter) {
		if (doubles_1[counter * 4 + 3] > 0.0D) {
			for (int int_9 = counter + 1; int_9 < oreFeatureConfig.size; ++int_9) {
				if (doubles_1[int_9 * 4 + 3] > 0.0D) {
					currentX = doubles_1[counter * 4 + 0] - doubles_1[int_9 * 4 + 0];
					currentY = doubles_1[counter * 4 + 1] - doubles_1[int_9 * 4 + 1];
					currentZ = doubles_1[counter * 4 + 2] - doubles_1[int_9 * 4 + 2];
					double_15 = doubles_1[counter * 4 + 3] - doubles_1[int_9 * 4 + 3];
					if (double_15 * double_15 > currentX * currentX + currentY * currentY + currentZ * currentZ) {
						if (double_15 > 0.0D) {
							doubles_1[int_9 * 4 + 3] = -1.0D;
						} else {
							doubles_1[counter * 4 + 3] = -1.0D;
						}
					}
				}
			}
		}
	}
	
	for (counter = 0; counter < oreFeatureConfig.size; ++counter) {
		double double_16 = doubles_1[counter * 4 + 3];
		if (double_16 >= 0.0D) {
			double double_17 = doubles_1[counter * 4 + 0];
			double double_18 = doubles_1[counter * 4 + 1];
			double double_19 = doubles_1[counter * 4 + 2];
			int int_11 = Math.max(MathHelper.floor(double_17 - double_16), startX);
			int int_12 = Math.max(MathHelper.floor(double_18 - double_16), yPosition);
			int int_13 = Math.max(MathHelper.floor(double_19 - double_16), startZ);
			int int_14 = Math.max(MathHelper.floor(double_17 + double_16), int_11);
			int int_15 = Math.max(MathHelper.floor(double_18 + double_16), int_12);
			int int_16 = Math.max(MathHelper.floor(double_19 + double_16), int_13);
			
			for (int x = int_11; x <= int_14; ++x) {
				double double_20 = ((double) x + 0.5D - double_17) / double_16;
				if (double_20 * double_20 < 1.0D) {
					for (int y = int_12; y <= int_15; ++y) {
						double double_21 = ((double) y + 0.5D - double_18) / double_16;
						if (double_20 * double_20 + double_21 * double_21 < 1.0D) {
							for (int z = int_13; z <= int_16; ++z) {
								double double_22 = ((double) z + 0.5D - double_19) / double_16;
								if (double_20 * double_20 + double_21 * double_21 + double_22 * double_22 < 1.0D) {
									int int_20 = x - startX + (y - yPosition) * xSize + (z - startZ) * xSize * int_5;
									if (!bitSet.get(int_20)) {
										bitSet.set(int_20);
										blockPos.set(x, y, z);
										if (world.getBlockState(blockPos).getBlock() == HallowedBlocks.TAINTED_STONE) {
											world.setBlockState(blockPos, oreFeatureConfig.state, 2);
											++stonesPlaced;
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	
	return stonesPlaced > 0;
}
 
Example 14
Source File: WitchWaterBubbleColumnBlock.java    From the-hallow with MIT License 4 votes vote down vote up
public static void update(IWorld world, BlockPos pos, boolean bool) {
	if (isStillWater(world, pos)) {
		world.setBlockState(pos, HallowedBlocks.WITCH_WATER_BUBBLE_COLUMN.getDefaultState().with(DRAG, bool), 2);
	}
}
 
Example 15
Source File: WitchWaterBubbleColumnBlock.java    From the-hallow with MIT License 4 votes vote down vote up
@Override
public Fluid tryDrainFluid(IWorld world, BlockPos pos, BlockState state) {
	world.setBlockState(pos, Blocks.AIR.getDefaultState(), 11);
	return HallowedFluids.WITCH_WATER;
}
 
Example 16
Source File: IForgeBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Called when a plant grows on this block.
 * This does not use ForgeDirection, because large/huge trees can be located in non-representable direction,
 * so the source location is specified.
 * Currently this just changes the block to dirt if it was grass.
 *
 * <p>Note: This happens DURING the generation, the generation may not be complete when this is called.
 *
 * @param state  The current state
 * @param world  Current world
 * @param pos    Block position in world
 * @param source Source plant's position in world
 */
default void onPlantGrow(BlockState state, IWorld world, BlockPos pos, BlockPos source) {
	if (Block.isNaturalDirt(getBlock())) {
		world.setBlockState(pos, Blocks.DIRT.getDefaultState(), 2);
	}
}