Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (โ‹ฎ) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[SOLVED] Create sapling + tree from configured feature json

Featured Replies

Posted

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

  • Author

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions โ†’ Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.