Jump to content

Error Registering Block Entity


Tadpoling

Recommended Posts

Hi,

Im trying to Create a simple block entity, following a guide, and for some reason there's an error registering it(with the deferred register)

Here is my MobRepellentBlockEntity Class

package com.Tadpolling.tutorialmod.block.entity;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;


public class MobRepellentBlockEntity  extends BlockEntity {
    public MobRepellentBlockEntity(BlockEntityType<?> pType, BlockPos pPos, BlockState pState) {
        super(pType, pPos, pState);
    }

}

Here is my ModBlockEntities Class where I have my deferred register

 

package com.Tadpolling.tutorialmod.block.entity;

import com.Tadpolling.tutorialmod.TutorialMod;
import com.Tadpolling.tutorialmod.block.ModBlocks;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

public class ModBlockEntities {
    public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES=
            DeferredRegister.create(ForgeRegistries.BLOCK_ENTITIES, TutorialMod.MOD_ID);
    
    public static final RegistryObject<BlockEntityType<MobRepellentBlockEntity>> MOB_REPPLLENT_BLOCK_ENTITY=
            BLOCK_ENTITIES.register("mob_repellent_block_entity",()->
                    BlockEntityType.Builder.of(MobRepellentBlockEntity::new,
                            ModBlocks.MOB_REPELLENT_BLOCK.get()).build(null));

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

On the Line of the of the "BlockEntityType.Builder.of" function call, it gives me an error on the given parameters of the function 'of' and the error given is:

"Cannot resolve method 'of(<method reference> , Block)'

In case it's relevant the Mob Repellent Block does exist and works(I've tested it). I've looked at a few guides so far and they all do the same thing.

Thank you for your time!

 

Link to comment
Share on other sites

You are probably copying example code from the wrong version of minecraft, things like this can change between versions.

MobRepellentBlockEntity::new passes a reference to your constuctor, which must match the signature of BlockEntityType.BlockEntitySupplier  - the parameter type used by of()

In 1.19 that is (BlockPos, BlockState) - see the create() method of this functional interface.

Your constructor has signature (BlockEntityType, BlockPos, BlockState), which is therefore wrong.

Edited by warjort
  • Like 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

MobRepellentBlockEntity::new is just syntatic sugar.

 

For you it is kind of the same as the lambda expression:

(blockPos, blockState) -> new MobRepellentBlockEntity(xxxx, blockPos, BlockState)

So you can see your problem is you don't have an xxxx to reference, it should not be there.

  • Like 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

Okay so let me start off by saying Your explanation was excellent!

My only issue is that im on Version 1.18.2, and i double and triple checked that the Constructor for a Block Entity requires a BlockEntityType parameter.

So I'm confused as to why it shouldn't be there? Because we need to call the constructor for the class we're inheriting from and all.

And I have no idea if this is important but the guides are both on 1.18 or 1.18.2. 

Link to comment
Share on other sites

Nope, look at BlockEntityType.BlockEntitySupplier it is create(BlockPos, BlockState) in 1.18.2

Some vanilla blocks entities do have a protected constuctor with a block entity type parameter, this is intended for use by subclasses not for actual construction.

  • Like 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

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.



×
×
  • Create New...

Important Information

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