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.

Featured Replies

Posted

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!

 

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

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.

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.

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.

  • Author

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. 

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.

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.

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.