From c7094dfc619c76f20d5a3141bca469f7eed86268 Mon Sep 17 00:00:00 2001 From: Justin Parsell Date: Thu, 25 Feb 2021 02:09:01 -0500 Subject: [PATCH] beginings of trees --- src/main/java/net/parsell/cherry/Cherry.java | 3 +- .../cherry/common/features/CherryTree.java | 33 +++++++++++++ .../parsell/cherry/core/CherryFeatures.java | 47 +++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/parsell/cherry/common/features/CherryTree.java create mode 100644 src/main/java/net/parsell/cherry/core/CherryFeatures.java diff --git a/src/main/java/net/parsell/cherry/Cherry.java b/src/main/java/net/parsell/cherry/Cherry.java index e18d59b..957621a 100644 --- a/src/main/java/net/parsell/cherry/Cherry.java +++ b/src/main/java/net/parsell/cherry/Cherry.java @@ -2,7 +2,6 @@ package net.parsell.cherry; import net.fabricmc.api.ModInitializer; import net.parsell.cherry.core.*; - public class Cherry implements ModInitializer { @Override @@ -14,5 +13,7 @@ public class Cherry implements ModInitializer { System.out.println("Cherry Initilizating..."); CherryBlocks.init(); CherryItems.init(); + CherryFeatures.init(); + } } diff --git a/src/main/java/net/parsell/cherry/common/features/CherryTree.java b/src/main/java/net/parsell/cherry/common/features/CherryTree.java new file mode 100644 index 0000000..fc2ae71 --- /dev/null +++ b/src/main/java/net/parsell/cherry/common/features/CherryTree.java @@ -0,0 +1,33 @@ +package net.parsell.cherry.common.features; + +import java.util.Random; + +import com.mojang.serialization.Codec; + +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import net.minecraft.world.Heightmap; +import net.minecraft.world.StructureWorldAccess; +import net.minecraft.world.gen.chunk.ChunkGenerator; +import net.minecraft.world.gen.feature.DefaultFeatureConfig; +import net.minecraft.world.gen.feature.Feature; +import net.parsell.cherry.core.CherryBlocks; + +public class CherryTree extends Feature { + public CherryTree(Codec config) { + super(config); + } + + @Override + public boolean generate(StructureWorldAccess world, ChunkGenerator generator, Random random, BlockPos pos, DefaultFeatureConfig config) { + BlockPos topPos = world.getTopPosition(Heightmap.Type.WORLD_SURFACE, pos); + Direction offset = Direction.NORTH; + + for (int y = 1; y <= 15; y++) { + offset = offset.rotateYClockwise(); + world.setBlockState(topPos.up(y).offset(offset), CherryBlocks.CHERRYLOG.getDefaultState(), 3); + } + + return true; + } +} \ No newline at end of file diff --git a/src/main/java/net/parsell/cherry/core/CherryFeatures.java b/src/main/java/net/parsell/cherry/core/CherryFeatures.java new file mode 100644 index 0000000..4dd2476 --- /dev/null +++ b/src/main/java/net/parsell/cherry/core/CherryFeatures.java @@ -0,0 +1,47 @@ +package net.parsell.cherry.core; + +import net.fabricmc.fabric.api.biome.v1.BiomeModifications; +import net.fabricmc.fabric.api.biome.v1.BiomeSelectors; +import net.minecraft.block.BlockState; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.BuiltinRegistries; +import net.minecraft.util.registry.Registry; +import net.minecraft.util.registry.RegistryKey; +import net.minecraft.world.gen.GenerationStep; +import net.minecraft.world.gen.UniformIntDistribution; +import net.minecraft.world.gen.feature.ConfiguredFeature; +import net.minecraft.world.gen.feature.Feature; +import net.minecraft.world.gen.feature.TreeFeature; +import net.minecraft.world.gen.feature.TreeFeatureConfig; +import net.minecraft.world.gen.feature.size.TwoLayersFeatureSize; +import net.minecraft.world.gen.foliage.BlobFoliagePlacer; +import net.minecraft.world.gen.stateprovider.SimpleBlockStateProvider; +import net.minecraft.world.gen.trunk.StraightTrunkPlacer; + + +public class CherryFeatures { + private static final BlockState CHERRYLOG_STATE = CherryBlocks.CHERRYLOG.getDefaultState(); + private static final BlockState CHERRYLEAVES_STATE = CherryBlocks.CHERRYLEAVES.getDefaultState(); + + // Create the features + private static final Feature CHERRY_TREE_1 = new TreeFeature(TreeFeatureConfig.CODEC); + + // Configure the features + public static final ConfiguredFeature CHERRY_TREE_1_C = CHERRY_TREE_1.configure((new TreeFeatureConfig.Builder(new SimpleBlockStateProvider(CherryFeatures.CHERRYLOG_STATE), new SimpleBlockStateProvider(CherryFeatures.CHERRYLEAVES_STATE), new BlobFoliagePlacer(UniformIntDistribution.of(2), UniformIntDistribution.of(0), 3), new StraightTrunkPlacer(4, 2, 0), new TwoLayersFeatureSize(1, 0, 1))).ignoreVines().build()); + + private static void addFeatures(){ + // Register the features + Registry.register(Registry.FEATURE, new Identifier("cherry", "cherry_tree"), CHERRY_TREE_1); + + // Register the configured features + RegistryKey> cherryTree1 = RegistryKey.of(Registry.CONFIGURED_FEATURE_WORLDGEN, new Identifier("cherry", "cherry_tree_1")); + Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, cherryTree1.getValue(), CHERRY_TREE_1_C); + + // Modify the biomes + BiomeModifications.addFeature(BiomeSelectors.all(), GenerationStep.Feature.VEGETAL_DECORATION, cherryTree1); + } + + public static void init(){ + addFeatures(); + } +} \ No newline at end of file