use of net.minecraft.world.level.levelgen.feature.ConfiguredFeature in project Tropicraft by Tropicraft.
the class TropicraftTrees method create.
private static AbstractTreeGrower create(String id) {
ResourceKey<ConfiguredFeature<?, ?>> key = ResourceKey.create(Registry.CONFIGURED_FEATURE_REGISTRY, new ResourceLocation(net.tropicraft.Constants.MODID, id));
return create((server, random, beehive) -> {
RegistryAccess registries = server.registryAccess();
Registry<ConfiguredFeature<?, ?>> features = registries.registryOrThrow(Registry.CONFIGURED_FEATURE_REGISTRY);
return features.get(key);
});
}
use of net.minecraft.world.level.levelgen.feature.ConfiguredFeature in project Tropicraft by Tropicraft.
the class TropicalFertilizerItem method useOn.
@Override
public InteractionResult useOn(UseOnContext context) {
BlockState state = context.getLevel().getBlockState(context.getClickedPos());
if (state.getBlock() == Blocks.GRASS_BLOCK) {
if (!context.getLevel().isClientSide) {
// Logic from GrassBlock#grow, with probability for grass significantly reduced
BlockPos blockpos = context.getClickedPos().above();
BlockState blockstate = Blocks.GRASS.defaultBlockState();
Level world = context.getLevel();
Random rand = world.getRandom();
for (int i = 0; i < 128; ++i) {
BlockPos blockpos1 = blockpos;
int j = 0;
while (true) {
if (j >= i / 16) {
BlockState blockstate2 = world.getBlockState(blockpos1);
if (blockstate2.getBlock() == blockstate.getBlock() && rand.nextInt(10) == 0) {
if (world instanceof ServerLevel) {
((BonemealableBlock) blockstate.getBlock()).performBonemeal((ServerLevel) world, rand, blockpos1, blockstate2);
}
}
if (!blockstate2.isAir()) {
break;
}
BlockState blockstate1;
if (rand.nextInt(8) > 0) {
// Modification here, == changed to > to invert chances
List<ConfiguredFeature<?, ?>> list = world.getBiome(blockpos1).getGenerationSettings().getFlowerFeatures();
if (list.isEmpty()) {
break;
}
// TODO this is so ugly and hacky, pls
ConfiguredFeature<?, ?> pFlowerFeature = list.get(0);
AbstractFlowerFeature<FeatureConfiguration> abstractflowerfeature = (AbstractFlowerFeature) pFlowerFeature.feature;
blockstate1 = abstractflowerfeature.getRandomFlower(rand, blockpos1, pFlowerFeature.config());
} else {
blockstate1 = blockstate;
}
if (blockstate1.canSurvive(world, blockpos1)) {
world.setBlockAndUpdate(blockpos1, blockstate1);
}
break;
}
blockpos1 = blockpos1.offset(rand.nextInt(3) - 1, (rand.nextInt(3) - 1) * rand.nextInt(3) / 2, rand.nextInt(3) - 1);
if (world.getBlockState(blockpos1.below()).getBlock() != Blocks.GRASS_BLOCK || world.getBlockState(blockpos1).isCollisionShapeFullBlock(world, blockpos1)) {
break;
}
++j;
}
}
}
return InteractionResult.SUCCESS;
}
return super.useOn(context);
}
Aggregations