下面列出了怎么用net.minecraft.world.gen.feature.ConfiguredFeature的API类实例代码及写法,或者点击链接到github查看源代码。
public static void registerOilLake() {
for (Biome biome : Biome.BIOMES) {
if (!biome.getCategory().equals(Biomes.NETHER_WASTES.getCategory()) && !biome.getCategory().equals(Biomes.THE_END.getCategory())) {
biome.addFeature(GenerationStep.Feature.UNDERGROUND_DECORATION, new ConfiguredFeature<>((LakeFeature) Feature.LAKE, new SingleStateFeatureConfig(GalacticraftBlocks.CRUDE_OIL.getDefaultState())));
}
}
}
@Override
public void grow(ServerWorld world, Random random, BlockPos blockPos, BlockState blockState) {
BlockPos upPos = blockPos.up();
BlockState grassBlock = HallowedBlocks.DECEASED_GRASS_BLOCK.getDefaultState();
label48:
for (int i = 0; i < 128; ++i) {
BlockPos randomPos = upPos;
for (int j = 0; j < i / 16; ++j) {
randomPos = randomPos.add(random.nextInt(3) - 1, (random.nextInt(3) - 1) * random.nextInt(3) / 2, random.nextInt(3) - 1);
if (world.getBlockState(randomPos.down()).getBlock() != this || world.getBlockState(randomPos).isFullCube(world, randomPos)) {
continue label48;
}
}
BlockState randomBlockState = world.getBlockState(randomPos);
if (randomBlockState.getBlock() == grassBlock.getBlock() && random.nextInt(10) == 0) {
((Fertilizable) grassBlock.getBlock()).grow(world, random, randomPos, randomBlockState);
}
if (randomBlockState.isAir()) {
BlockState stateToPlace;
if (random.nextInt(8) == 0) {
List<ConfiguredFeature<?, ?>> list = world.getBiomeAccess().getBiome(randomPos).getFlowerFeatures();
if (list.isEmpty()) {
continue;
}
stateToPlace = ((FlowerFeature) ((DecoratedFeatureConfig) (list.get(0)).config).feature.feature).getFlowerToPlace(random, randomPos, list.get(0).config);
} else {
stateToPlace = grassBlock;
}
if (stateToPlace.canPlaceAt(world, randomPos)) {
world.setBlockState(randomPos, stateToPlace, 3);
}
}
}
}
private static Thing simplePlop(ConfiguredFeature feature)
{
return (w, p) -> {
CarpetSettings.skipGenerationChecks=true;
try
{
return feature.generate(w, w.getChunkManager().getChunkGenerator(), w.random, p);
}
finally
{
CarpetSettings.skipGenerationChecks = false;
}
};
}
public static <F extends FeatureConfig, D extends DecoratorConfig> ConfiguredFeature<?, ?> configureFeature(Feature<F> feature, F featureConfig, Decorator<D> decorator, D decoratorConfig) {
Feature<DecoratedFeatureConfig> feature2 = feature instanceof FlowerFeature ? Feature.DECORATED_FLOWER : Feature.DECORATED;
return new ConfiguredFeature(feature2, new DecoratedFeatureConfig(feature.configure(featureConfig), decorator.configure(decoratorConfig)));
}
@Override
protected ConfiguredFeature<BranchedTreeFeatureConfig, ?> createTreeFeature(Random rand, boolean bool) {
return HallowedFeatures.SMALL_DEADWOOD_TREE.configure(HallowedFeatures.SMALL_DEADWOOD_TREE_CONFIG);
}
@Override
protected ConfiguredFeature<MegaTreeFeatureConfig, ?> createLargeTreeFeature(Random var1) {
return HallowedFeatures.LARGE_DEADWOOD_TREE.configure(HallowedFeatures.LARGE_DEADWOOD_TREE_CONFIG);
}