use of net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration in project Tropicraft by Tropicraft.
the class TropicraftTrees method createFruit.
private static AbstractTreeGrower createFruit(Supplier<? extends Block> fruitLeaves, Supplier<Supplier<? extends Block>> fruitSapling) {
return create((server, random, beehive) -> {
WeightedStateProvider leaves = new WeightedStateProvider(SimpleWeightedRandomList.<BlockState>builder().add(TropicraftBlocks.FRUIT_LEAVES.get().defaultBlockState(), 1).add(fruitLeaves.get().defaultBlockState(), 1));
TreeConfiguration config = new TreeConfiguration.TreeConfigurationBuilder(new SimpleStateProvider(Blocks.OAK_LOG.defaultBlockState()), new CitrusTrunkPlacer(6, 3, 0), leaves, new SimpleStateProvider(fruitSapling.get().get().defaultBlockState()), new CitrusFoliagePlacer(ConstantInt.of(0), ConstantInt.of(0)), new TwoLayersFeatureSize(1, 0, 2)).build();
return Feature.TREE.configured(config);
});
}
use of net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration 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.levelgen.feature.configurations.TreeConfiguration in project Tropicraft by Tropicraft.
the class MangroveTreeFeature method place.
@Override
public boolean place(FeaturePlaceContext<TreeConfiguration> pContext) {
WorldGenLevel world = pContext.level();
BlockPos pos = pContext.origin();
TreeConfiguration config = pContext.config();
BlockPos placePos = this.findPlacePos(world, pos, config);
if (placePos == null)
return false;
BlockPos soilPos = placePos.below();
BlockState soilState = world.getBlockState(soilPos);
// Force placement: put dirt under the current position so that the tree always places
boolean replaceSoil = soilState.is(TropicraftTags.Blocks.MUD) || soilState.getFluidState().is(FluidTags.WATER) || soilState.is(Tags.Blocks.SAND) || (world.getBlockState(soilPos.below()).getFluidState().is(FluidTags.WATER));
try {
if (replaceSoil)
world.setBlock(soilPos, Blocks.DIRT.defaultBlockState(), Block.UPDATE_ALL);
return this.backing.place(new FeaturePlaceContext<>(world, pContext.chunkGenerator(), pContext.random(), pos, config));
} finally {
if (replaceSoil)
world.setBlock(soilPos, soilState, Block.UPDATE_ALL);
}
}
Aggregations