Better Sapling Growing Code

This commit is contained in:
Frank 2022-06-07 17:46:13 +02:00
parent 5ebf159965
commit 55d243bf13
3 changed files with 41 additions and 14 deletions

View file

@ -1,5 +1,6 @@
package org.betterx.bclib.api.v2.levelgen.features;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.data.BuiltinRegistries;
@ -7,9 +8,12 @@ import net.minecraft.data.worldgen.features.FeatureUtils;
import net.minecraft.data.worldgen.placement.PlacementUtils;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.configurations.RandomFeatureConfiguration;
@ -155,4 +159,24 @@ public class BCLFeature<F extends Feature<FC>, FC extends FeatureConfiguration>
public FC getConfiguration() {
return configuration;
}
public boolean place(ServerLevel level, BlockPos pos, RandomSource random) {
return place(this.getFeature(), level, pos, random);
}
public static boolean place(Feature<?> feature, ServerLevel level, BlockPos pos, RandomSource random) {
if (feature instanceof UserGrowableFeature growable) {
return growable.grow(level, pos, random);
}
FeaturePlaceContext context = new FeaturePlaceContext(
Optional.empty(),
level,
level.getChunkSource().getGenerator(),
random,
pos,
null
);
return feature.place(context);
}
}

View file

@ -0,0 +1,11 @@
package org.betterx.bclib.api.v2.levelgen.features;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.ServerLevelAccessor;
public interface UserGrowableFeature {
boolean grow(ServerLevelAccessor level,
BlockPos pos,
RandomSource random);
}

View file

@ -17,7 +17,6 @@ import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.FeaturePlaceContext;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.phys.shapes.CollisionContext;
@ -27,6 +26,7 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import org.betterx.bclib.api.v2.levelgen.features.BCLFeature;
import org.betterx.bclib.client.models.BasePatterns;
import org.betterx.bclib.client.models.ModelsHelper;
import org.betterx.bclib.client.models.PatternsHelper;
@ -50,8 +50,8 @@ public class FeatureSaplingBlock extends SaplingBlock implements RenderLayerProv
.instabreak()
.sound(SoundType.GRASS)
.randomTicks(),
featureSupplier
);
featureSupplier
);
}
public FeatureSaplingBlock(int light, Function<BlockState, Feature<?>> featureSupplier) {
@ -61,8 +61,8 @@ public class FeatureSaplingBlock extends SaplingBlock implements RenderLayerProv
.instabreak()
.sound(SoundType.GRASS)
.randomTicks(),
featureSupplier
);
featureSupplier
);
}
public FeatureSaplingBlock(BlockBehaviour.Properties properties, Function<BlockState, Feature<?>> featureSupplier) {
@ -97,15 +97,7 @@ public class FeatureSaplingBlock extends SaplingBlock implements RenderLayerProv
@Override
public void advanceTree(ServerLevel world, BlockPos pos, BlockState blockState, RandomSource random) {
FeaturePlaceContext context = new FeaturePlaceContext(
Optional.empty(),
world,
world.getChunkSource().getGenerator(),
random,
pos,
null
);
getFeature(blockState).place(context);
BCLFeature.place(getFeature(blockState), world, pos, random);
}
@Override