Jump to content

Recommended Posts

Posted (edited)

Hello,

in older Forge versions, I created a tree using my own TreeGrower:

public static ConfiguredFeature<BaseTreeFeatureConfig, ?> tree_rubber = Feature.TREE.configured(
	new BaseTreeFeatureConfig.Builder(
		new SimpleBlockStateProvider(ModBlocks.rubber_log.get().defaultBlockState()),
		new SimpleBlockStateProvider(ModBlocks.rubber_leaves.get().defaultBlockState()),
		new BlobFoliagePlacer(
			/* radius: */ FeatureSpread.of(
				2, //base
				0  //spread
			),
			/* offset: */ FeatureSpread.of(
				0, //base
				0  //spread
			),
			/* height: */ 3
		),
		new StraightTrunkPlacer(
			4, //baseHeight
			2, //heightRandA
			0  //heightRandB
		),
		new TwoLayerFeature(
			1, //limit
			0, //lowerSize
			1  //upperSize
		)
).ignoreVines().build()

and the sapling for this tree could be created using

BLOCKS.register("rubber_sapling",
	() -> new SaplingBlock(
		new RubberTree(),
		AbstractBlock.Properties.of(Material.PLANT)
			.randomTicks()
			.noCollission()
			.instabreak()
			.sound(SoundType.GRASS)
	)
);

 

With 1.16.4, I can simply create this tree from a configured feature json. Let's call this file "data/[mymod]/world/configured_feature/rubber.json":

{
  "config": {
    "max_water_depth": 0,
    "ignore_vines": true,
    "heightmap": "OCEAN_FLOOR",
    "minimum_size": {
      "limit": 1,
      "lower_size": 0,
      "upper_size": 1,
      "type": "minecraft:two_layers_feature_size"
    },
    "decorators": [],
    "trunk_provider": {
      "state": {
        "Properties": {
          "axis": "y"
        },
        "Name": "bigmachines:rubber_log"
      },
      "type": "minecraft:simple_state_provider"
    },
    "leaves_provider": {
      "state": {
        "Properties": {
          "persistent": "false",
          "distance": "7"
        },
        "Name": "minecraft:rubber_leaves"
      },
      "type": "minecraft:simple_state_provider"
    },
    "foliage_placer": {
      "radius": 2,
      "offset": 0,
      "height": 3,
      "type": "minecraft:blob_foliage_placer"
    },
    "trunk_placer": {
      "base_height": 4,
      "height_rand_a": 2,
      "height_rand_b": 0,
      "type": "minecraft:straight_trunk_placer"
    }
  },
  "type": "minecraft:tree"
}

Which should do basically the same thing.

My question is how do I register a sapling for this tree?

Edited by scrouthtv
formatted code
Posted

Someone on discord told me to overwrite the `Tree` class:

```

public class DynamicTree extends Tree {
    final ResourceLocation configuredFeatureId;
    private ConfiguredFeature<BaseTreeFeatureConfig,?> treeFeature;

    public DynamicTree(ResourceLocation configuredFeatureId) {
        this.configuredFeatureId = configuredFeatureId;
    }

    @Nullable
    @Override
    protected ConfiguredFeature<BaseTreeFeatureConfig, ?> getTreeFeature(Random randomIn, boolean largeHive) {
        return treeFeature;
    }

    @Override
    @SuppressWarnings("unchecked")
    public boolean attemptGrowTree(ServerWorld world, ChunkGenerator chunkGenerator, BlockPos pos, BlockState state, Random rand) {
        MutableRegistry<ConfiguredFeature<?, ?>> registry = world.func_241828_r().getRegistry(Registry.CONFIGURED_FEATURE_KEY);
        ConfiguredFeature<?, ?> feature = registry.getOrDefault(configuredFeatureId);
        if(feature != null && feature.config instanceof BaseTreeFeatureConfig) {
            this.treeFeature = (ConfiguredFeature<BaseTreeFeatureConfig, ?>)feature;
        } else {
            this.treeFeature = null;
            return false;
        }
        return super.attemptGrowTree(world, chunkGenerator, pos, state, rand);
    }
}

```

  • scrouthtv changed the title to [SOLVED] Create sapling + tree from configured feature json

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.