use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.
the class TropicraftTrees method create.
private static AbstractTreeGrower create(FeatureProvider featureProvider) {
return new AbstractTreeGrower() {
@Nullable
@Override
protected ConfiguredFeature<TreeConfiguration, ?> getConfiguredFeature(Random random, boolean beehive) {
return null;
}
@Override
public boolean growTree(ServerLevel world, ChunkGenerator generator, BlockPos pos, BlockState sapling, Random random) {
ConfiguredFeature<?, ?> feature = featureProvider.getFeature(world.getServer(), random, this.hasFlowers(world, pos));
if (feature == null) {
return false;
}
world.setBlock(pos, Blocks.AIR.defaultBlockState(), Block.UPDATE_INVISIBLE);
if (feature.place(world, generator, random, pos)) {
return true;
} else {
world.setBlock(pos, sapling, Block.UPDATE_INVISIBLE);
return false;
}
}
private boolean hasFlowers(LevelAccessor world, BlockPos origin) {
BlockPos min = origin.offset(-2, -1, -2);
BlockPos max = origin.offset(2, 1, 2);
for (BlockPos pos : BlockPos.MutableBlockPos.betweenClosed(min, max)) {
if (world.getBlockState(pos).is(BlockTags.FLOWERS)) {
return true;
}
}
return false;
}
};
}
use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.
the class ReedsFeature method generateTall.
private boolean generateTall(WorldGenLevel world, BlockPos pos, int height, BlockPos.MutableBlockPos mutablePos) {
for (int y = 0; y < height; y++) {
mutablePos.setY(pos.getY() + y);
BlockState state = REEDS.setValue(ReedsBlock.TYPE, y == height - 1 ? ReedsBlock.Type.TOP : ReedsBlock.Type.BOTTOM).setValue(ReedsBlock.WATERLOGGED, world.getBlockState(mutablePos).is(Blocks.WATER));
world.setBlock(mutablePos, state, Constants.BlockFlags.BLOCK_UPDATE);
}
return true;
}
use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.
the class TropicraftFeatureUtil method isSoil.
public static boolean isSoil(final LevelAccessor world, final BlockPos pos) {
final BlockState blockState = world.getBlockState(pos);
final Block block = blockState.getBlock();
return block == Blocks.DIRT || block == Blocks.COARSE_DIRT || block == Blocks.GRASS_BLOCK || block == Blocks.PODZOL;
}
use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.
the class UndergroundSeaPickleFeature method place.
@Override
public boolean place(FeaturePlaceContext<NoneFeatureConfiguration> context) {
WorldGenLevel world = context.level();
Random random = context.random();
BlockPos pos = context.origin();
BlockState surface = world.getBlockState(pos.below());
if (!surface.is(Blocks.STONE) && !surface.is(Blocks.DIRT)) {
return false;
}
if (world.getBlockState(pos).is(Blocks.WATER) && world.getBlockState(pos.above()).is(Blocks.WATER)) {
int count = random.nextInt(random.nextInt(4) + 1) + 1;
if (surface.is(Blocks.DIRT)) {
count = Math.min(count + random.nextInt(2), 4);
}
BlockState pickle = Blocks.SEA_PICKLE.defaultBlockState().setValue(SeaPickleBlock.PICKLES, count);
world.setBlock(pos, pickle, Block.UPDATE_CLIENTS);
return true;
}
return false;
}
use of net.minecraft.world.level.block.state.BlockState in project Tropicraft by Tropicraft.
the class SteepPathProcessor method canPlaceLadderAt.
// Check that there is a solid block behind the ladder at this pos, and return the correct ladder state
// Returns null if placement is not possible
private BlockState canPlaceLadderAt(LevelReader level, BlockPos pos, Direction dir) {
BlockPos check = pos.relative(dir);
BlockState state = level.getBlockState(check);
if (!state.isAir()) {
BlockState ladderState = getLadderState(dir);
if (ladderState.canSurvive(level, pos)) {
return ladderState;
}
}
return null;
}
Aggregations