Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Entities doc for 1.21 is incorrect #175

Closed
Rabbit0w0 opened this issue Oct 10, 2024 · 2 comments · Fixed by #176
Closed

Block Entities doc for 1.21 is incorrect #175

Rabbit0w0 opened this issue Oct 10, 2024 · 2 comments · Fixed by #176

Comments

@Rabbit0w0
Copy link

Rabbit0w0 commented Oct 10, 2024

As title.

Code in doc:

public static final Supplier<BlockEntityType<MyBlockEntity>> MY_BLOCK_ENTITY = BLOCK_ENTITY_TYPES.register(
        "my_block_entity",
        // The block entity type, created using a builder.
        () -> BlockEntityType.Builder.of(
                // The supplier to use for constructing the block entity instances.
                MyBlockEntity::new,
                // A vararg of blocks that can have this block entity.
                // This assumes the existence of the referenced blocks as DeferredBlock<Block>s.
                MyBlocks.MY_BLOCK_1, MyBlocks.MY_BLOCK_2
        )
        // Build using null; vanilla does some datafixer shenanigans with the parameter that we don't need.
        .build(null)
);

but the register method actually accepts Block instead of DeferredBlock

Also, by following the doc to build a example mod, it actually doesn't work with the exception: java.lang.NullPointerException: Trying to access unbound value: ResourceKey[minecraft:block_entity_type / customfurniture:furniture_entity], which is thrown when constructing a new block entity and unboxing Supplier<BlockEntityType<MyBlockEntity>>

mc ver: 1.12.1
neo: 21.1.65

@jananass
Copy link

@Rabbit0w0 I had the exact same issue and just saw that it is caused because you need to register the newly created BLOCK_ENTITY_TYPES to the mod event bus. Like this, by using the starting ModDevGradle example repository.

// The constructor for the mod class is the first code that is run when your mod is loaded.
// FML will recognize some parameter types like IEventBus or ModContainer and pass them in automatically.
public ExtraSync(IEventBus modEventBus, ModContainer modContainer)
{
    // Register the commonSetup method for modloading
    modEventBus.addListener(this::commonSetup);

    // Register the Deferred Register to the mod event bus so blocks get registered
    BLOCKS.register(modEventBus);
    // Register the Deferred Register to the mod event bus so items get registered
    ITEMS.register(modEventBus);
    // Register the Deferred Register to the mod event bus so tabs get registered
    CREATIVE_MODE_TABS.register(modEventBus);
    // Register the Deferred Register to the mod event bus so block entities get registered
    BLOCK_ENTITY_TYPES.register(modEventBus);
    ...
}

Is it possible to add this mention to the documentation?

@ChampionAsh5357
Copy link
Contributor

@Rabbit0w0 I had the exact same issue and just saw that it is caused because you need to register the newly created BLOCK_ENTITY_TYPES to the mod event bus. Like this, by using the starting ModDevGradle example repository.

// The constructor for the mod class is the first code that is run when your mod is loaded.
// FML will recognize some parameter types like IEventBus or ModContainer and pass them in automatically.
public ExtraSync(IEventBus modEventBus, ModContainer modContainer)
{
// Register the commonSetup method for modloading
modEventBus.addListener(this::commonSetup);

// Register the Deferred Register to the mod event bus so blocks get registered
BLOCKS.register(modEventBus);
// Register the Deferred Register to the mod event bus so items get registered
ITEMS.register(modEventBus);
// Register the Deferred Register to the mod event bus so tabs get registered
CREATIVE_MODE_TABS.register(modEventBus);
// Register the Deferred Register to the mod event bus so block entities get registered
BLOCK_ENTITY_TYPES.register(modEventBus);
...

}

Is it possible to add this mention to the documentation?

We do link to the relevant pages for registration using DeferredRegister in the documentation since it should be stated that if you are making a block entity, you have probably already done a similar process for blocks. However, after a quick read, I do think the link should be more explicitly highlight than just a loose mention. I would suggest creating a separate issue for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants