use of net.minecraft.world.level.block.grower.AbstractTreeGrower 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;
}
};
}
Aggregations