Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.4]NullPointerException when using registered custom features

Recommended Posts

Code repository: Here


I registered my custom feature in FeatureRegistry.java and McbbsWiki.java.



public static final DeferredRegister<Feature<?>> FEATURES = DeferredRegister.create(ForgeRegistries.FEATURES, "mcbbswiki");
public static RegistryObject<McbbsWikiLuckyBlockFeature> feature_lucky_block = FEATURES.register("feature_lucky_block", () -> new McbbsWikiLuckyBlockFeature(NoFeatureConfig.field_236558_a_));


McbbsWiki.java (the main class of this mod):

But, when I used

to get the object (in world.biome.McbbsWikiBiomeMaker.java:37), the game throwed a NullPointerException and crashed.


I found out "FeatureRegistry.feature_lucky_block.isPresent()" returned false and "FeatureRegistry.feature_lucky_block.value" is null, but do not know how to solve the problem.


The full logs are shown below.Please help me.

latest.log crash-2021-01-20_15.04.42-fml.txt

Link to post
Share on other sites
48 minutes ago, diesieben07 said:

Show this class: McbbsWikiBiomeMaker.makeMcbbsWikiNormalBiome

Attention:This is a method, not a class.

public static Biome makeMcbbsWikiNormalBiome(){
        MobSpawnInfo.Builder mobSpawnInfo = new MobSpawnInfo.Builder();
        mobSpawnInfo.withSpawner(EntityClassification.CREATURE, new MobSpawnInfo.Spawners(EntityRegistry.entity_small_mcbbswiki_monster.get(), 10, 5, 7));
        mobSpawnInfo.withSpawner(EntityClassification.CREATURE, new MobSpawnInfo.Spawners(EntityRegistry.entity_middle_mcbbswiki_monster.get(), 7, 3, 5));
        mobSpawnInfo.withSpawner(EntityClassification.CREATURE, new MobSpawnInfo.Spawners(EntityRegistry.entity_large_mcbbswiki_monster.get(), 4, 1, 3));
        mobSpawnInfo.withSpawner(EntityClassification.CREATURE, new MobSpawnInfo.Spawners(EntityType.LLAMA, 5, 4, 6));
        BiomeGenerationSettings.Builder biomeGeneSettings = (new BiomeGenerationSettings.Builder()).withSurfaceBuilder(ConfiguredSurfaceBuilders.field_244181_m);

        biomeGeneSettings.withFeature(GenerationStage.Decoration.VEGETAL_DECORATION, FeatureRegistry.feature_lucky_block.get().withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG));
        return (new Biome.Builder())
                .setEffects((new BiomeAmbience.Builder())

See https://github.com/QWERTY770/MCBBS-Wiki-Mod/tree/main/src/main/java/cn/mcbbswiki/qwerty5238/world

Link to post
Share on other sites
23 minutes ago, diesieben07 said:

You cannot access registry entries directly before FMLCommonSetupEvent. Here you are trying to access the features during the biome registry phase, which will not work.

So, how can I do that?

Link to post
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.

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.

  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • trying to override onItemRightClick so i look in the list of overridable functions in Item class and it doesnt exist?
    • hm... when I had a similar issue the discord pointed me towards using baked models. but multiparts does seem way simpler, and with datagen I could even do it proceduraly
    • You don't need a custom baked model for this. Look at the composter model for an example.
    • whenever you find a solution by yourself, you can leave the original question, but add a comment mentioning that you fixed it, and how. so that if anyone comes accross the same problem, they can find your solution and try it without needing to make a new topic. also, I don't see how intellij syncing with github has anything to do with forge
    • you need to create a new class which implements IBakedModel, overwrite getQuads (the one which takes an IModelData) an make it return the quads for your model, the IModelData shouls contain the info on the list and you set the info on the IModelData by overwriting getModelData in your tile entity. you need to sync the data from, the Server tile entity, to the client, which you can do by overwriting getUpdatePacket (Server sends updated data to the client), and onDataPacket  (Client handles an update packet received). then, whenever that data changes you can call World#notifyUpdate, and whenever the client receives an update (so in the end of onDataPacket) you call requestModelUpdate().   for the BakedModel, what I do is: I pass in an existing IBakedModel (that works as a base that I can add quads to) to the constructor, and store it in a field. then I can call IBakedModel#getQuads on the base model, which gives a list of BakedQuads, and add any new quads to it. and you can create your quads by using FaceBakey#bakeQuad, it takes the start and end positions of the quad (in block space, so 0 -> 16), an instance of a BlockPartFace, the sprite you want to use, which you can get from an AtlasTexture, the Direction of that quad, a transform (I just use SimpleModelTransform.IDENTITY), a rotation, which you can just pass null, a boolean that tells wether that face should be shaded or not, and then a throwaway ResourceLocation. and you can decide on all those properties, and on what faces to add, given the IModelData   EDIT: oh, and to register it you can do so through the modelRegistry in the ModelBakeEvent (this event is client-side only (I think)) if you need some examples, I used this repo to learn how to use BakedModels: https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/mbe04_block_dynamic_block_models
  • Topics

  • Who's Online (See full list)

  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.