Jump to content

[1.18.2] Crash when adding custom Tree to Biome


Skyriis

Recommended Posts

Hey Guys,

i've created a custom Tree and would love to spawn it in my Biome. But crashes when clicking on the single player button after adding the Tree to the Biome.

My Code:

public class TensuraTreeFeatures {
  public static final Holder<ConfiguredFeature<TreeConfiguration, ?>> SAKURA = FeatureUtils.register("sakura", Feature.TREE,
        basicTree(TensuraBlocks.SAKURA_LOG, TensuraBlocks.SAKURA_LEAVES));

  public static final Holder<PlacedFeature> SAKURA_CHECKED = PlacementUtils.register("sakura_tree", TensuraTreeFeatures.SAKURA,
        PlacementUtils.filteredByBlockSurvival(TensuraBlocks.SAKURA_SAPLING));



  private static TreeConfiguration basicTree(Block logBlock, Block leavesBlock) {
        return createStraightBlobTree(logBlock, leavesBlock, 4, 2, 0, 2).ignoreVines().build();
  }
  
  private static TreeConfiguration.TreeConfigurationBuilder createStraightBlobTree(Block logBlock, Block leavesBlock, int baseHeight, int p_195150_, int p_195151_, int leavesRadius) {
        return new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(logBlock),
            new StraightTrunkPlacer(baseHeight, p_195150_, p_195151_), BlockStateProvider.simple(leavesBlock),
            new BlobFoliagePlacer(ConstantInt.of(leavesRadius), ConstantInt.of(0), 3),
            new TwoLayersFeatureSize(1, 0, 1));
  }
}

 

 

Link to comment
Share on other sites

How do i register those?

i've tried to register them like that:

class FeatureRegistry {
    static void register(final DeferredRegister<Feature<?>> registry) { 
        registry.register("sakura_tree", () -> new ConfiguredFeature<>(Feature.TREE, basicTree(TensuraBlocks.SAKURA_LOG, TensuraBlocks.SAKURA_LEAVES)));
    }
  
    private static TreeConfiguration basicTree(Block logBlock, Block leavesBlock) {
        return createStraightBlobTree(logBlock, leavesBlock, 4, 2, 0, 2).ignoreVines().build();
    }

    private static TreeConfiguration.TreeConfigurationBuilder createStraightBlobTree(Block logBlock, Block leavesBlock, int baseHeight, int p_195150_, int p_195151_, int leavesRadius) {
        return new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(logBlock),
            new StraightTrunkPlacer(baseHeight, p_195150_, p_195151_), BlockStateProvider.simple(leavesBlock),
            new BlobFoliagePlacer(ConstantInt.of(leavesRadius), ConstantInt.of(0), 3),
            new TwoLayersFeatureSize(1, 0, 1));
    }
}

but ConfiguredFeature isn't a Featue. Do i need to use an other registy instead of ForgeRegistries.FEATURES?

Link to comment
Share on other sites

i'm still running into a small problem with my object holder.

java.lang.IllegalStateException: The ObjectHolder annotation cannot apply to a field that does not map to a registry. Ensure the registry was created during the RegistryEvent.NewRegistry event. (found : net.minecraft.world.level.levelgen.feature.ConfiguredFeature at com.borniuus.tensura.world.gen.TensuraFeatures.SAKURA_FOREST_TREES)
@ObjectHolder(Tensura.MOD_ID)
public class TensuraFeatures {
    @ObjectHolder("sakura_forest_trees")
    public static final ConfiguredFeature<RandomFeatureConfiguration, Feature<RandomFeatureConfiguration>> SAKURA_FOREST_TREES = null;
}

//registered using
registry.register("sakura_forest_trees", () -> new ConfiguredFeature<>(Feature.RANDOM_SELECTOR, new RandomFeatureConfiguration(List.of(
            new WeightedPlacedFeature(Holder.direct(TensuraPlacements.SAKURA_TREE_LARGE_CHECKED), 0.15F)
        ), Holder.direct(TensuraPlacements.SAKURA_TREE_CHECKED))));

 

Link to comment
Share on other sites

ConfiguredFeature:

Spoiler
public class FeatureRegistry {
    private static final BeehiveDecorator BEEHIVE = new BeehiveDecorator(0.05F);
    public static RegistryObject<ConfiguredFeature<?, ?>> SAKURA_TREE, SAKURA_TREE_HIVE, SAKURA_TREE_LARGE, SAKURA_TREE_LARGE_HIVE, SAKURA_FOREST;

    static void register(final DeferredRegister<ConfiguredFeature<?, ?>> registry) {
        SAKURA_TREE = registry.register("sakura_tree", () -> new ConfiguredFeature<>(Feature.TREE, basicTree(TensuraBlocks.SAKURA_LOG, TensuraBlocks.SAKURA_LEAVES)));
        SAKURA_TREE_HIVE = registry.register("sakura_tree_hive", () -> new ConfiguredFeature<>(Feature.TREE, basicTreeWithHive(TensuraBlocks.SAKURA_LOG, TensuraBlocks.SAKURA_LEAVES)));
        SAKURA_TREE_LARGE = registry.register("sakura_tree_large", () -> new ConfiguredFeature<>(Feature.TREE, largeTree(TensuraBlocks.SAKURA_LOG, TensuraBlocks.SAKURA_LEAVES)));
        SAKURA_TREE_LARGE_HIVE = registry.register("sakura_tree_large_hive", () -> new ConfiguredFeature<>(Feature.TREE, largeTreeWithHive(TensuraBlocks.SAKURA_LOG, TensuraBlocks.SAKURA_LEAVES)));

        SAKURA_FOREST = registry.register("sakura_forest_trees", () -> new ConfiguredFeature<>(Feature.RANDOM_SELECTOR, new RandomFeatureConfiguration(List.of(
            new WeightedPlacedFeature(Holder.direct(PlacementRegistry.SAKURA_TREE_LARGE_CHECKED.get()), 0.15F)
        ), Holder.direct(PlacementRegistry.SAKURA_TREE_CHECKED.get()))));
    }

    private static TreeConfiguration largeTree(Block logBlock, Block leavesBlock) {
        return largeTree(logBlock, leavesBlock, 3, 11, 0, 4).build();
    }

    private static TreeConfiguration largeTreeWithHive(Block logBlock, Block leavesBlock) {
        return largeTree(logBlock, leavesBlock, 3, 11, 0, 4).decorators(List.of(BEEHIVE)).build();
    }

    private static TreeConfiguration basicTree(Block logBlock, Block leavesBlock) {
        return createStraightBlobTree(logBlock, leavesBlock, 4, 2, 0, 2).ignoreVines().build();
    }

    private static TreeConfiguration basicTreeWithHive(Block logBlock, Block leavesBlock) {
        return createStraightBlobTree(logBlock, leavesBlock, 4, 2, 0, 2).ignoreVines().decorators(List.of(BEEHIVE)).build();
    }

    private static TreeConfiguration.TreeConfigurationBuilder createStraightBlobTree(Block logBlock, Block leavesBlock, int baseHeight, int p_195150_, int p_195151_, int leavesRadius) {
        return new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(logBlock),
            new StraightTrunkPlacer(baseHeight, p_195150_, p_195151_), BlockStateProvider.simple(leavesBlock),
            new BlobFoliagePlacer(ConstantInt.of(leavesRadius), ConstantInt.of(0), 3),
            new TwoLayersFeatureSize(1, 0, 1));
    }

    private static TreeConfiguration.TreeConfigurationBuilder largeTree(Block logBlock, Block leavesBlock, int baseHeight, int p_195150_, int p_195151_, int leavesRadius) {
        return new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(logBlock),
            new FancyTrunkPlacer(baseHeight, p_195150_, p_195151_), BlockStateProvider.simple(leavesBlock),
            new FancyFoliagePlacer(ConstantInt.of(leavesRadius), ConstantInt.of(4), 4),
            new TwoLayersFeatureSize(0, 0, 0, OptionalInt.of(4))).ignoreVines();
    }
}

 

PlacedFeatures:

Spoiler
public class PlacementRegistry {
    public static RegistryObject<PlacedFeature> SAKURA_TREE_CHECKED, SAKURA_TREE_LARGE_CHECKED, SAKURA_FOREST_CHECKED;

    static void register(DeferredRegister<PlacedFeature> registry) {
        SAKURA_TREE_CHECKED = registry.register("sakura_tree_checked", () -> new PlacedFeature(Holder.direct(FeatureRegistry.SAKURA_TREE.get()),
            List.of(PlacementUtils.filteredByBlockSurvival(TensuraBlocks.SAKURA_SAPLING))));
        SAKURA_TREE_LARGE_CHECKED = registry.register("sakura_tree_large_checked", () -> new PlacedFeature(Holder.direct(FeatureRegistry.SAKURA_TREE_LARGE.get()),
            List.of(PlacementUtils.filteredByBlockSurvival(TensuraBlocks.SAKURA_SAPLING))));
        SAKURA_FOREST_CHECKED = registry.register("sakura_forest_trees_checked", () -> new PlacedFeature(Holder.direct(FeatureRegistry.SAKURA_TREE_LARGE.get()),
            List.of(CountPlacement.of(16), InSquarePlacement.spread(), TREE_THRESHOLD, PlacementUtils.HEIGHTMAP_OCEAN_FLOOR)));
    }
}

Biome Registry:

Spoiler
class BiomeRegistry {
    static void register(DeferredRegister<Biome> registry) {
        registry.register("sakura_forest", SakuraForestBiome::create).getKey();
    }
}
public class SakuraForestBiome {
    public static Biome create() {
        BiomeGenerationSettingsHelper generationSettingsHelper = new BiomeGenerationSettingsHelper()
            //Add Caves and Canyons
            .addCarver(GenerationStep.Carving.AIR, Carvers.CAVE)
            .addCarver(GenerationStep.Carving.AIR, Carvers.CAVE_EXTRA_UNDERGROUND)
            .addCarver(GenerationStep.Carving.AIR, Carvers.CANYON)
            //Add underground lava lakes
            .addFeature(GenerationStep.Decoration.LAKES, MiscOverworldPlacements.LAKE_LAVA_UNDERGROUND)
            //Add underground crystal formations
            .apply(BiomeDefaultFeatures::addDefaultCrystalFormations)
            //Add Monster Room Structure
            .apply(BiomeDefaultFeatures::addDefaultMonsterRoom)
            //Apply default underground variety
            .apply(BiomeDefaultFeatures::addDefaultUndergroundVariety)
            //Apply default surface freezing
            .apply(BiomeDefaultFeatures::addSurfaceFreezing)
            //Add Trees
            .addFeature(GenerationStep.Decoration.VEGETAL_DECORATION, Holder.direct(PlacementRegistry.SAKURA_FOREST_CHECKED.get()))
            //Apply mossy stones to surface
            .apply(BiomeDefaultFeatures::addMossyStoneBlock)
            //Add flowers to surface
            .apply(BiomeDefaultFeatures::addForestFlowers)
            //Add grass to surface
            .apply(BiomeDefaultFeatures::addForestGrass)
            //Add Mushrooms to surface
            .apply(BiomeDefaultFeatures::addDefaultMushrooms)
            //Add decoration plants to surface
            .apply(BiomeDefaultFeatures::addDefaultExtraVegetation)
            //Add default ores
            .apply(BiomeDefaultFeatures::addDefaultOres, BiomeDefaultFeatures::addDefaultSoftDisks);

        MobSpawnHelper mobSpawnHelper = new MobSpawnHelper()
            //Add default animals
            .apply(BiomeDefaultFeatures::farmAnimals)
            //Add default cave entities and mobs
            .apply(BiomeDefaultFeatures::commonSpawns)
            //Allow wolves to spawn
            .addSpawn(MobCategory.CREATURE, EntityType.WOLF, 5, 4, 4);

        return BiomeBuilder.forest(generationSettingsHelper, mobSpawnHelper).build();
    }
}

 

 

Full crash report: https://pastebin.com/EJaHMYFR

Link to comment
Share on other sites

My DeferredRegister fields are in a seperate class. 

public class TensuraRegistry {
    private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, Tensura.MOD_ID);
    private static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, Tensura.MOD_ID);
    private static final DeferredRegister<SoundEvent> SOUND_EVENTS = DeferredRegister.create(ForgeRegistries.SOUND_EVENTS, Tensura.MOD_ID);
    private static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITIES, Tensura.MOD_ID);
    private static final DeferredRegister<Motive> MOTIVE = DeferredRegister.create(ForgeRegistries.PAINTING_TYPES, Tensura.MOD_ID);
    private static final DeferredRegister<Biome> BIOMES = DeferredRegister.create(ForgeRegistries.BIOMES, Tensura.MOD_ID);
    private static final DeferredRegister<ConfiguredFeature<?, ?>> CONFIGURED_FEATURES = DeferredRegister.create(Registry.CONFIGURED_FEATURE_REGISTRY, Tensura.MOD_ID);
    private static final DeferredRegister<PlacedFeature> PLACED_FEATURE = DeferredRegister.create(Registry.PLACED_FEATURE_REGISTRY, Tensura.MOD_ID);

    public static void register(IEventBus modEventBus) {
        BlockRegistry.register(ITEMS, BLOCKS); //Register Blocks with their BlockItems
        ItemRegistry.register(ITEMS); //Register Items to our Registry
        BlockEntityTypeRegistry.register(ITEMS, BLOCKS, BLOCK_ENTITY_TYPES); //Registers Block Entities including their Blocks and Items
        SoundEventRegistry.register(SOUND_EVENTS); //Register Sound Events
        MotiveRegistry.register(MOTIVE); //Register Motives for custom paintings
        ConfiguredFeatureRegistry.register(CONFIGURED_FEATURES);
        PlacedFeatureRegistry.register(PLACED_FEATURE);
        BiomeRegistry.register(BIOMES); //Register Biomes

        // Add our Registries to Forge
        BLOCKS.register(modEventBus);
        ITEMS.register(modEventBus);
        BLOCK_ENTITY_TYPES.register(modEventBus);
        SOUND_EVENTS.register(modEventBus);
        MOTIVE.register(modEventBus);
        BIOMES.register(modEventBus);
        CONFIGURED_FEATURES.register(modEventBus);
        PLACED_FEATURE.register(modEventBus);
    }
}

 

Edited by Skyriis
Link to comment
Share on other sites

 ConfiguredFeature:

Spoiler
public class FeatureRegistry {
    private static final DeferredRegister<ConfiguredFeature<?, ?>> registry = DeferredRegister.create(Registry.CONFIGURED_FEATURE_REGISTRY, Tensura.MOD_ID);
    private static final BeehiveDecorator BEEHIVE = new BeehiveDecorator(0.05F);
    public static RegistryObject<ConfiguredFeature<?, ?>> SAKURA_TREE, SAKURA_TREE_HIVE, SAKURA_TREE_LARGE, SAKURA_TREE_LARGE_HIVE, SAKURA_FOREST;

    static void register(final IEventBus modBus) {
        SAKURA_TREE = registry.register("sakura_tree", () -> new ConfiguredFeature<>(Feature.TREE, basicTree(TensuraBlocks.SAKURA_LOG, TensuraBlocks.SAKURA_LEAVES)));
        SAKURA_TREE_HIVE = registry.register("sakura_tree_hive", () -> new ConfiguredFeature<>(Feature.TREE, basicTreeWithHive(TensuraBlocks.SAKURA_LOG, TensuraBlocks.SAKURA_LEAVES)));
        SAKURA_TREE_LARGE = registry.register("sakura_tree_large", () -> new ConfiguredFeature<>(Feature.TREE, largeTree(TensuraBlocks.SAKURA_LOG, TensuraBlocks.SAKURA_LEAVES)));
        SAKURA_TREE_LARGE_HIVE = registry.register("sakura_tree_large_hive", () -> new ConfiguredFeature<>(Feature.TREE, largeTreeWithHive(TensuraBlocks.SAKURA_LOG, TensuraBlocks.SAKURA_LEAVES)));

        SAKURA_FOREST = registry.register("sakura_forest_trees", () -> new ConfiguredFeature<>(Feature.RANDOM_SELECTOR, new RandomFeatureConfiguration(List.of(
            new WeightedPlacedFeature(Holder.direct(PlacementRegistry.SAKURA_TREE_LARGE_CHECKED.get()), 0.15F)
        ), Holder.direct(PlacementRegistry.SAKURA_TREE_CHECKED.get()))));
      
        registry.register(modBus);
    }

    private static TreeConfiguration largeTree(Block logBlock, Block leavesBlock) {
        return largeTree(logBlock, leavesBlock, 3, 11, 0, 4).build();
    }

    private static TreeConfiguration largeTreeWithHive(Block logBlock, Block leavesBlock) {
        return largeTree(logBlock, leavesBlock, 3, 11, 0, 4).decorators(List.of(BEEHIVE)).build();
    }

    private static TreeConfiguration basicTree(Block logBlock, Block leavesBlock) {
        return createStraightBlobTree(logBlock, leavesBlock, 4, 2, 0, 2).ignoreVines().build();
    }

    private static TreeConfiguration basicTreeWithHive(Block logBlock, Block leavesBlock) {
        return createStraightBlobTree(logBlock, leavesBlock, 4, 2, 0, 2).ignoreVines().decorators(List.of(BEEHIVE)).build();
    }

    private static TreeConfiguration.TreeConfigurationBuilder createStraightBlobTree(Block logBlock, Block leavesBlock, int baseHeight, int p_195150_, int p_195151_, int leavesRadius) {
        return new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(logBlock),
            new StraightTrunkPlacer(baseHeight, p_195150_, p_195151_), BlockStateProvider.simple(leavesBlock),
            new BlobFoliagePlacer(ConstantInt.of(leavesRadius), ConstantInt.of(0), 3),
            new TwoLayersFeatureSize(1, 0, 1));
    }

    private static TreeConfiguration.TreeConfigurationBuilder largeTree(Block logBlock, Block leavesBlock, int baseHeight, int p_195150_, int p_195151_, int leavesRadius) {
        return new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(logBlock),
            new FancyTrunkPlacer(baseHeight, p_195150_, p_195151_), BlockStateProvider.simple(leavesBlock),
            new FancyFoliagePlacer(ConstantInt.of(leavesRadius), ConstantInt.of(4), 4),
            new TwoLayersFeatureSize(0, 0, 0, OptionalInt.of(4))).ignoreVines();
    }
}

 

PlacedFeatures:

Spoiler
public class PlacementRegistry {
    private static final DeferredRegister<PlacedFeature> registry = DeferredRegister.create(Registry.PLACED_FEATURE_REGISTRY, Tensura.MOD_ID);
    public static RegistryObject<PlacedFeature> SAKURA_TREE_CHECKED, SAKURA_TREE_LARGE_CHECKED, SAKURA_FOREST_CHECKED;

    static void register(final IEventBus modBus) {
        SAKURA_TREE_CHECKED = registry.register("sakura_tree_checked", () -> new PlacedFeature(Holder.direct(FeatureRegistry.SAKURA_TREE.get()),
            List.of(PlacementUtils.filteredByBlockSurvival(TensuraBlocks.SAKURA_SAPLING))));
        SAKURA_TREE_LARGE_CHECKED = registry.register("sakura_tree_large_checked", () -> new PlacedFeature(Holder.direct(FeatureRegistry.SAKURA_TREE_LARGE.get()),
            List.of(PlacementUtils.filteredByBlockSurvival(TensuraBlocks.SAKURA_SAPLING))));
        SAKURA_FOREST_CHECKED = registry.register("sakura_forest_trees_checked", () -> new PlacedFeature(Holder.direct(FeatureRegistry.SAKURA_TREE_LARGE.get()),
            List.of(CountPlacement.of(16), InSquarePlacement.spread(), TREE_THRESHOLD, PlacementUtils.HEIGHTMAP_OCEAN_FLOOR)));
      
        registry.register(modBus);
    }
}

 

Biome Registry:

Spoiler
class BiomeRegistry {
    private static final DeferredRegister<Biome> registry = DeferredRegister.create(ForgeRegistries.BIOMES, Tensura.MOD_ID);
  
    static void register(final IEventBus modBus) {
        registry.register("sakura_forest", SakuraForestBiome::create);
        registry.register(modBus);
    }
}

 

Link to comment
Share on other sites

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.