user28175778
user28175778

Reputation: 1

Minecraft Fabric 1.21.3 adding ExperienceDroppingBlock

I am new to Minecraft modding and still trying to learn. I am currently following tutorials and I get on fine understanding the concepts as I have programmed plenty in C and C# in the past. My problem however is that there is no tutorial or much of any documentation on 1.21.3, which I am trying to learn. I go step by step in the tutorial, first making the mod run in 1.21.1 and then see how to alter the code to work for 1.21.3. I have been stopped entirely by trying to add a simple block with ExperienceDroppingBlock(UniformIntProvider). I essentially want to be able to set a range of items that can be dropped by breaking the block and also make it drop xp.

Here is the original method for registering a block:

private static Block registerBlock(String name, Block block) {
        registerBlockItem(name, block);
        return Registry.register(Registries.BLOCK, Identifier.of(FirstMod.MOD_ID, name), block);
    }

    private static void registerBlockItem(String name, Block block) {
        Registry.register(Registries.ITEM, Identifier.of(FirstMod.MOD_ID, name), new BlockItem(block, new Item.Settings()));
    }

And here is how it is supposed to look in 1.21.3:

private static Block registerBlock(String name, Function<AbstractBlock.Settings, Block> factory, AbstractBlock.Settings settings) {
        final Identifier identifier = Identifier.of(TutorialMod.MOD_ID, name);
        final RegistryKey<Block> registryKey = RegistryKey.of(RegistryKeys.BLOCK, identifier);

        final Block block = Blocks.register(registryKey, factory, settings);
        Items.register(block);
        return block;
    }

It seems to me that Blocks.register won't allow you to add that property anymore/I don't know how to.

The orignal way to add the block was as follows:

public static final Block BLOCK_NAME = registerBlock("block_name",
            new ExperienceDroppingBlock(UniformIntProvider.create(2, 5),
                    AbstractBlock.Settings.create().strength(3f).requiresTool()));

Now it's like this:

public static final Block BLOCK_NAME = registerBlock("block_name", Block::new,
            Block.Settings.create().strength(3f).requiresTool());

I tried for a long time, to conclude that Block::new is necessary and you cannot have ExperienceDroppingBlock(UniformIntProvider) in the same Blocks.register as Block::new ('factory' in the method).

I apologise if this is a very simple answer and I've missed something obvious. Like I said, I am new to this and am still trying to learn java as I go.

Upvotes: 0

Views: 167

Answers (0)

Related Questions