Jump to content

Custom Tree Not Growing, throwing "Trying to access unbound value" error 1.19.2


HumanHickory

Recommended Posts

I am attempting to add a tree into the world. All the tree parts are rendering, and are usable, and I can place the sapling but the sapling will not grow either with bone meal or naturally, which is what the bug is.

So first I register all the parts of the Cherry Tree. Those are all working, including the sapling. Here is an example of the sapling and a log. The log is a modded FlammableRotatedPillarBlock that sets the object to flammable = true, sets flammability to 5, sets fire spread speed to 5, and tells it what to do when it's clicked on with an axe (aka stripping the log). 

public static final RegistryObject<Block> CHERRY_LOG = register("cherry_log", () -> new ModFlammableRotatedPillarBlock(BlockBehaviour.Properties.copy(Blocks.OAK_LOG)
            .requiresCorrectToolForDrops()), CreativeModeTab.TAB_BUILDING_BLOCKS);   

public static final RegistryObject<Block> CHERRY_SAPLING = register("cherry_sapling", () -> new SaplingBlock(new CherryTreeGrower(), BlockBehaviour.Properties.copy(Blocks.OAK_SAPLING)),
            CreativeModeTab.TAB_MISC);

 

In another file, I register the cherry tree, and give it the various things a tree needs to grow. 

public class ModConfiguredFeatures {
    public static final DeferredRegister<ConfiguredFeature<?, ?>> CONFIGURED_FEATURES = DeferredRegister.create(Registry.CONFIGURED_FEATURE_REGISTRY, HickoryGardenMod.MODID);

    public static final RegistryObject<ConfiguredFeature<?, ?>> CHERRY =
            CONFIGURED_FEATURES.register("cherry", () ->
                    new ConfiguredFeature<>(Feature.TREE, new TreeConfiguration.TreeConfigurationBuilder(
                            BlockStateProvider.simple(BlockInit.CHERRY_LOG.get()),
                            new StraightTrunkPlacer(5, 6, 3),
                            BlockStateProvider.simple(BlockInit.CHERRY_LEAVES.get()),
                            new BlobFoliagePlacer(ConstantInt.of(2), ConstantInt.of(0), 4),
                            new TwoLayersFeatureSize(1, 0, 2)).build()));
}

Then, I created a CherryTreeGrower class that extends AbstractTreeGrower, using that CHERRY object.

public class CherryTreeGrower extends AbstractTreeGrower {
    @Nullable
    @Override
    protected Holder<? extends ConfiguredFeature<?, ?>> getConfiguredFeature(RandomSource pRandom, boolean pLargeHive) {
        return ModConfiguredFeatures.CHERRY.getHolder().get();
    }
}

 

The Error I get is 

java.lang.IllegalStateException: Trying to access unbound value 'ResourceKey[minecraft:worldgen/configured_feature / hickorygardenmod:cherry]' from registry Registry[ResourceKey[minecraft:root / minecraft:worldgen/configured_feature] (Stable)]

Other than the necessary json files and png files in the resources folder, I don't refer to the cherry tree components anywhere else. Thoughts?

Edited by HumanHickory
Added version
Link to comment
Share on other sites

  • HumanHickory changed the title to Custom Tree Not Growing, throwing "Trying to access unbound value" error 1.19.2

The error message says your configured feature isn't registered. Probably because you haven't called register(Bus) on your DeferrredRegister?

  • Thanks 1

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

 

8 hours ago, warjort said:

The error message says your configured feature isn't registered. Probably because you haven't called register(Bus) on your DeferrredRegister?

 Wow I feel dumb. Yes that was exactly what it was. I'm still new to Java and modding Minecraft so stupid mistakes are in my immediate future. Thank you so much for your help!!

Link to comment
Share on other sites

Hello! I have the exact same problem, but I do not exactly understand what you mean by "calling register(Bus) on your DeferredRegister". Could you please tell me where I need to add that exactly? Much appreciated, thank you very much.

Edited by IAmNatan
Link to comment
Share on other sites

19 minutes ago, IAmNatan said:

Hello! I have the exact same problem, but I do not exactly understand what you mean by "calling register(Bus) on your DeferredRegister". Could you please tell me where I need to add that exactly? Much appreciated, thank you very much.

DeferredRegisters need to be registered, if you look at the examplemod that comes with the MDK, it registers item and block deferred registers. I believe they do it in the mod class constructor.

Link to comment
Share on other sites

Thank you, but I'm still having a little trouble understanding; so sorry, I am a complete beginner to java and I only started a week ago. Here is my code; how should I approach this?

 

package net.natan.natansrealmmod.world.feature;

import net.minecraft.util.valueproviders.ConstantInt;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.WeightedPlacedFeature;
import net.minecraft.world.level.levelgen.feature.configurations.RandomFeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;
import net.minecraft.world.level.levelgen.feature.featuresize.TwoLayersFeatureSize;
import net.minecraft.world.level.levelgen.feature.foliageplacers.BlobFoliagePlacer;
import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider;
import net.minecraft.world.level.levelgen.feature.trunkplacers.StraightTrunkPlacer;
import net.minecraftforge.registries.RegistryObject;
import net.natan.natansrealmmod.NatansRealmMod;
import net.minecraft.core.Registry;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.natan.natansrealmmod.block.ModBlocks;

import java.util.List;


public class ModConfiguredFeatures {
    public static final DeferredRegister<ConfiguredFeature<?, ?>> CONFIGURED_FEATURES =
            DeferredRegister.create(Registry.CONFIGURED_FEATURE_REGISTRY, NatansRealmMod.MOD_ID);


    public static final RegistryObject<ConfiguredFeature<?,?>> BETWIXT =
            CONFIGURED_FEATURES.register("betwixt", () ->
                    new ConfiguredFeature<>(Feature.TREE, new TreeConfiguration.TreeConfigurationBuilder(
                            BlockStateProvider.simple(ModBlocks.BETWIXTLOG.get()),
                            new StraightTrunkPlacer(5, 6, 3),
                            BlockStateProvider.simple(ModBlocks.BETWIXTLEAVES.get()),
                            new BlobFoliagePlacer(ConstantInt.of(2), ConstantInt.of(0), 4),
                            new TwoLayersFeatureSize(1, 0, 2)).build()));

    public static final RegistryObject<ConfiguredFeature<?, ?>> BETWIXT_SPAWN =
            CONFIGURED_FEATURES.register("betwixt_spawn", () -> new ConfiguredFeature<>(Feature.RANDOM_SELECTOR,
                    new RandomFeatureConfiguration(List.of(new WeightedPlacedFeature(
                            ModPlacedFeatures.BETWIXT_CHECKED.getHolder().get(),
                            0.5F)), ModPlacedFeatures.BETWIXT_CHECKED.getHolder().get())));


    public static void register(IEventBus eventBus) {
        CONFIGURED_FEATURES.register(eventBus);
    }
}

I know I'm probably being really stupid-

Link to comment
Share on other sites

If you're a beginner with Java, you're going to have a really hard and probably bad time trying to mod Minecraft. My advice is to learn at least basic Java, then come back to this. Although to be honest, you should probably learn more than just basic Java, basic Java is not enough for some of the code used in Minecraft/Forge.

 

Did you look at the Examplemod that came with the MDK? It shows how to register a DeferredRegister, plus there's not a ton of code in it to weed through to find it, it's a single class.

Link to comment
Share on other sites

  • 1 month later...
On 10/15/2022 at 2:29 PM, IAmNatan said:

Thank you, but I'm still having a little trouble understanding; so sorry, I am a complete beginner to java and I only started a week ago. Here is my code; how should I approach this?

 

package net.natan.natansrealmmod.world.feature;

import net.minecraft.util.valueproviders.ConstantInt;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.WeightedPlacedFeature;
import net.minecraft.world.level.levelgen.feature.configurations.RandomFeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;
import net.minecraft.world.level.levelgen.feature.featuresize.TwoLayersFeatureSize;
import net.minecraft.world.level.levelgen.feature.foliageplacers.BlobFoliagePlacer;
import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider;
import net.minecraft.world.level.levelgen.feature.trunkplacers.StraightTrunkPlacer;
import net.minecraftforge.registries.RegistryObject;
import net.natan.natansrealmmod.NatansRealmMod;
import net.minecraft.core.Registry;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.natan.natansrealmmod.block.ModBlocks;

import java.util.List;


public class ModConfiguredFeatures {
    public static final DeferredRegister<ConfiguredFeature<?, ?>> CONFIGURED_FEATURES =
            DeferredRegister.create(Registry.CONFIGURED_FEATURE_REGISTRY, NatansRealmMod.MOD_ID);


    public static final RegistryObject<ConfiguredFeature<?,?>> BETWIXT =
            CONFIGURED_FEATURES.register("betwixt", () ->
                    new ConfiguredFeature<>(Feature.TREE, new TreeConfiguration.TreeConfigurationBuilder(
                            BlockStateProvider.simple(ModBlocks.BETWIXTLOG.get()),
                            new StraightTrunkPlacer(5, 6, 3),
                            BlockStateProvider.simple(ModBlocks.BETWIXTLEAVES.get()),
                            new BlobFoliagePlacer(ConstantInt.of(2), ConstantInt.of(0), 4),
                            new TwoLayersFeatureSize(1, 0, 2)).build()));

    public static final RegistryObject<ConfiguredFeature<?, ?>> BETWIXT_SPAWN =
            CONFIGURED_FEATURES.register("betwixt_spawn", () -> new ConfiguredFeature<>(Feature.RANDOM_SELECTOR,
                    new RandomFeatureConfiguration(List.of(new WeightedPlacedFeature(
                            ModPlacedFeatures.BETWIXT_CHECKED.getHolder().get(),
                            0.5F)), ModPlacedFeatures.BETWIXT_CHECKED.getHolder().get())));


    public static void register(IEventBus eventBus) {
        CONFIGURED_FEATURES.register(eventBus);
    }
}

I know I'm probably being really stupid-

As I happen to know the context of this code, your problem probably lies within your CONFIGURED_FEATURES Registry. While you create it you probably never really register it. The method at the bottom takes care of that and in the official tutorial it is also called in the main class:

 

public TutorialMod() {
	IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
		
	//... Stuff
	ModConfiguredFeatures.register(modEventBus);
	//... More Stuff

 	MinecraftForge.EVENT_BUS.register(this);
}

This called the "register()" Method in the ModConfiguredFeatures class.

I can't see your main class but you probably forgot to call it in your constructor

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I am getting an error message that my mods and my server are not on the same minecraft version when they clearly are. My server and my mods are on 1.20.1 and the error says that the server is 1.20 even though it's on forge 47.2.30.  
    • .Omg, I'm so freaking blind I didn't notice that, it works now, thank you so much @Xoroshio
    • On the one off the last lines of code you have put && boots.isEmpty() Instead of && !boots.isEmpty() is that a typo?
    • I'm trying to apply effects to the emerald armor but it doesn't work, I read that the onArmorTick() method doesn't work anymore, but I tried with inventoryTick, onInventoryTick and onArmorTick but they don't apply the effect either, I don't know if I'm writing it wrong, so I need help to fix it. This is the code in question: public class ModArmorItem extends ArmorItem{ private static final Map<ArmorMaterial, MobEffectInstance> MATERIAL_TO_EFFECT_MAP = (new ImmutableMap.Builder<ArmorMaterial, MobEffectInstance>()) .put(ModArmorMaterials.EMERALD, new MobEffectInstance( MobEffects.HERO_OF_THE_VILLAGE, 200, 1, false, false, true)) .build(); public ModArmorItem(ArmorMaterial pMaterial, Type pType, Properties pProperties) { super(pMaterial, pType, pProperties); } @Override public void onArmorTick(ItemStack stack, Level world, Player player){ if (!world.isClientSide()) { if (hasFullSuitOfArmorOn(player)) { evaluateArmorEffects(player); } } } private void evaluateArmorEffects(Player player) { for (Map.Entry<ArmorMaterial,MobEffectInstance> entry : MATERIAL_TO_EFFECT_MAP.entrySet()){ ArmorMaterial mapArmorMaterial = entry.getKey(); MobEffectInstance mapStatusEffect = entry.getValue(); if (hasCorrectArmorOn(mapArmorMaterial, player)) { addStatusEffectForMaterial(player, mapArmorMaterial, mapStatusEffect); } } } private void addStatusEffectForMaterial(Player player, ArmorMaterial mapArmorMaterial, MobEffectInstance mapStatusEffect) { boolean hasPlayerEffect = player.hasEffect(mapStatusEffect.getEffect()); if (hasCorrectArmorOn(mapArmorMaterial, player) && !hasPlayerEffect) { player.addEffect(new MobEffectInstance(mapStatusEffect)); } } private boolean hasCorrectArmorOn(ArmorMaterial material, Player player) { for (ItemStack armorStack : player.getInventory().armor){ if (!(armorStack.getItem() instanceof ArmorItem)) { return false; } } ArmorItem helmet = ((ArmorItem)player.getInventory().getArmor(3).getItem()); ArmorItem brestplace = ((ArmorItem)player.getInventory().getArmor(2).getItem()); ArmorItem leggins = ((ArmorItem)player.getInventory().getArmor(1).getItem()); ArmorItem boots = ((ArmorItem)player.getInventory().getArmor(0).getItem()); return helmet.getMaterial() == material && brestplace.getMaterial() == material && leggins.getMaterial() == material && boots.getMaterial() == material; } private boolean hasFullSuitOfArmorOn(Player player){ ItemStack helmet = player.getInventory().getArmor(3); ItemStack breastplace = player.getInventory().getArmor(2); ItemStack leggins = player.getInventory().getArmor(1); ItemStack boots = player.getInventory().getArmor(0); return !helmet.isEmpty() && !breastplace.isEmpty() && !leggins.isEmpty() && boots.isEmpty(); } } And here is the armor   public static final RegistryObject<Item> EMERALD_HELMET = ITEMS.register( "emerald_helmet", () -> new ModArmorItem(ModArmorMaterials.EMERALD, ArmorItem.Type.HELMET, new Item.Properties()) ); public static final RegistryObject<Item> EMERALD_CHESTPLATE = ITEMS.register( "emerald_chestplate", () -> new ModArmorItem(ModArmorMaterials.EMERALD, ArmorItem.Type.CHESTPLATE, new Item.Properties()) ); public static final RegistryObject<Item> EMERALD_LEGGINS = ITEMS.register( "emerald_leggins", () -> new ModArmorItem(ModArmorMaterials.EMERALD, ArmorItem.Type.LEGGINGS, new Item.Properties()) ); public static final RegistryObject<Item> EMERALD_BOOTS = ITEMS.register( "emerald_boots", () -> new ModArmorItem(ModArmorMaterials.EMERALD, ArmorItem.Type.BOOTS, new Item.Properties()) ); I hope you can help me. Thanks.
    • so ive been having this issue for a little bit, and have honestly no clue on how to fix it. I'm using minecraft 1.20.1 for clarification.  Here is the latest log: https://pastebin.com/neMuxELv
  • Topics

×
×
  • Create New...

Important Information

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