#Weird behavior when naming blocks in lang file.

13 messages · Page 1 of 1 (latest)

placid wave
#

When creating custom blocks, I have to assign them a name in the lang file using "item.mod_id.cutom_block": "Custom Block", instead of "block.mod_id.custom_block"... Why is this? Is this an issue? Should I change the way I register blocks? I am creating my mod for 1.21.7.

primal burrow
#

call the useBlockDescriptionPrefix method on your Item.Properties (moj) when registering the item
(useBlockPrefixedTranslationKey and Item.Settings in yarn)

primal burrow
#

which part?

placid wave
#

Pretty much all of it

#

Would it help if I shared my repository?

primal burrow
#

ok, show the part where youre registering the block items

placid wave
#

import...

import java.util.function.Function;

public class ModBlocks {

    public static final String MOD_ID = "calcium";

    public static final Block ANDESITE_BRICKS = register("andesite_bricks", Block::new, Block.Settings.create().mapColor(MapColor.STONE_GRAY).instrument(NoteBlockInstrument.BASEDRUM).requiresTool().strength(1.5F, 6.0F), true);

    public static final Block ENDER_GROWTH = register("ender_growth", EndPlantBlock::new, AbstractBlock.Settings.create().mapColor(MapColor.DARK_GREEN).replaceable().noCollision().breakInstantly().sounds(BlockSoundGroup.GRASS).offset(AbstractBlock.OffsetType.XYZ).burnable().pistonBehavior(PistonBehavior.DESTROY), true);

    public static void initialize() {

        ItemGroupEvents.modifyEntriesEvent(ItemGroups.NATURAL).register((itemgroup) -> {
            itemgroup.add(ENDER_GROWTH);
        });

        ItemGroupEvents.modifyEntriesEvent(ItemGroups.BUILDING_BLOCKS).register((itemgroup) -> {
            itemgroup.add(ANDESITE_BRICKS);
        });

    }

    private static Block register(String name, Function<AbstractBlock.Settings, Block> blockFactory, AbstractBlock.Settings settings, boolean registerItem) {

        RegistryKey<Block> blockKey = keyOfBlock(name);
        Block block = blockFactory.apply(settings.registryKey(blockKey));

        if (registerItem) {
            RegistryKey<Item> itemKey = keyOfItem(name);
            BlockItem blockItem = new BlockItem(block, new Item.Settings().registryKey(itemKey));
            Registry.register(Registries.ITEM, itemKey, blockItem);
        }

        return Registry.register(Registries.BLOCK, blockKey, block);
    }

    private static RegistryKey<Block> keyOfBlock(String name) {
        return RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(MOD_ID, name));
    }

    private static RegistryKey<Item> keyOfItem(String name) {
        return RegistryKey.of(RegistryKeys.ITEM, Identifier.of(MOD_ID, name));
    }

}```
primal burrow
#

but here where you make the item settings and call registryKey on it, you just need to call useBlockPrefixedTranslationKey aswell

placid wave
#

that worked, thank you

#

do you know why I had to do this? Is this a 1.21.5-1.21.7 thing?