Posted November 7, 20204 yr I'm tinkering with some stuff while trying to learn modding, I made a class for a Block that extends net.minecraft.Block, but I get an error when registering it This is the block class: public class ExplodingBlock extends Block { public ExplodingBlock(Properties props) { super(props); this.setDefaultState( this.stateContainer.getBaseState() .with(CHARGE, 0) ); Minecraft.getInstance().player.sendChatMessage("Block Placed with CHARGE: 0"); } static final IntegerProperty CHARGE = IntegerProperty.create("charge", 0, 5); @Override protected void fillStateContainer(StateContainer.Builder<Block, BlockState> container) { super.fillStateContainer(container); container.add(new Property[]{CHARGE}); } public ActionResultType onBlockActivated(BlockState blockState, World world, BlockPos blockPos, PlayerEntity player, Hand hand, BlockRayTraceResult rayRes) { world.setBlockState(blockPos, blockState.with(CHARGE, (Integer)blockState.get(CHARGE) + 1)); Minecraft.getInstance().player.sendChatMessage("Block Placed with CHARGE: " + (Integer)blockState.get(CHARGE)); return ActionResultType.SUCCESS; } } And this is the code for registering it: public static final RegistryObject<ExplodingBlock> EXPLODING_BLOCK = register("exploding_block", () -> new ExplodingBlock(AbstractBlock.Properties.create(Material.TNT) .hardnessAndResistance(3, 10) .sound(SoundType.STONE)) ); I am registering other blocks that use simply RegistryObject<Block>, and the supplier is a new Block(), and they work. The code also worked when I changed the registering to Use of the Block class instead of the inheriting ExplondingBlock class, but without the functionally I wanted, of course. I get the following error in the minecraft window after loading: Tutorial Mod (tutorial) encountered an error during the load_registries event phase Tutorial Mod (tutorial) encountered an error during the error event phase java.lang.NullPointerException: Registry Object not present: tutorial:exploding_block Edited November 7, 20204 yr by kiou.23 forgot to add the error message
November 7, 20204 yr Minecraft.getInstance().player.sendChatMessage("Block Placed with CHARGE: " + (Integer)blockState.get(CHARGE)); This will crash on server https://mcforge.readthedocs.io/en/latest/concepts/sides/, use the player provided instead. You need to show more of your code
November 7, 20204 yr Author 2 hours ago, poopoodice said: Minecraft.getInstance().player.sendChatMessage("Block Placed with CHARGE: " + (Integer)blockState.get(CHARGE)); This will crash on server https://mcforge.readthedocs.io/en/latest/concepts/sides/, use the player provided instead. You need to show more of your code I was running Client, and I just added that for debugging purposes, is it still the cause of the error? and what other part of the code I should add? There isn't much else, the problem I thought would be in the ExplodingBlock class
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.