Jump to content

Recommended Posts

Posted (edited)

I'm new modding, so I've simply made a single block + item with no texture, following Mcjty's 1.14 tutorial. The game seems to load normally; however, when I use the /give command to give the item to the player, the game seems to crash. The crash log was quite unhelpful -- though I've attached it to this post, of course, it essentially just says "unexpected error occurred". Since the crash only occurs when the game has to interact with the item, I assume I've made some obvious and common mistake registering it, or else Eclipse or Gradle somehow aren't building Minecraft quite properly.

 

Here is what I think the relevant code might be:

 

Main mod class:

Spoiler

@Mod("coloredtorches")
public class ColoredTorches {
    public static final String modid = "coloredtorches";
    public static IProxy proxy = DistExecutor.runForDist(() -> () -> new ClientProxy(), () -> () -> new ServerProxy());
    public static ModSetup setup = new ModSetup();
    public ColoredTorches() {
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
    }

    private void setup(final FMLCommonSetupEvent event) {

    }
    @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {
        @SubscribeEvent
        public static void onBlocksRegistry(final RegistryEvent.Register<Block> event) {
             event.getRegistry().register(new FirstBlock());
        }

        @SubscribeEvent
        public static void onItemsRegistry(final RegistryEvent.Register<Item> event) {
             event.getRegistry().register(new BlockItem(ModBlocks.FIRSTBLOCK, new Item.Properties()).setRegistryName("firstblock"));         
        }
    }

}

 

FirstBlock.java

Spoiler

public class FirstBlock extends Block {

    public FirstBlock() {
        super(Properties.create(Material.IRON)
                .sound(SoundType.METAL)
                .hardnessAndResistance(2.0f)
                .lightValue(14)
        );
        setRegistryName("firstblock");
    }
}

 

ModBlocks.java

Spoiler

public class ModBlocks {
    @ObjectHolder("mytutorial:firstblock")
    public static FirstBlock FIRSTBLOCK;
}

 

Thank you kindly for any advice.

crash-2019-07-08_20.26.20-client.txt

Edited by freelancepoliceman
Posted

instead of event.getRegistry().register(new BlockItem(ModBlocks.FIRSTBLOCK, new Item.Properties()).setRegistryName("firstblock")); use event.getRegistry().register(new BlockItem(ModBlocks.FIRSTBLOCK, new Item.Properties()).setRegistryName(ModBlocks.FIRSTBLOCK.getRegistryName()));

This eliminates the chance of getting the registry name wrong.

 

Change your ModBlocks class from

public class ModBlocks {
    @ObjectHolder("mytutorial:firstblock")
    public static FirstBlock FIRSTBLOCK;
}

to

@ObjectHolder(ColoredTorches.modid)
public class ModBlocks {
    public static final FirstBlock FIRSTBLOCK = null;
}

 

You're game is currently crashing because ModBlocks.FIRSTBLOCK is null. It is null because you've hardcoded the name of the block to "mytutorial:firstblock" when it should be "coloredtorches:firstblock". This means that the field never gets filled with your block, and you're item block tries to use a null block in getTranslationKey, causing a crash. Putting @ObjectHolder on your class with your modid means that you don't need to hardcode each name above each field, instead the name of the object is gotten with yourModId + ":" + nameOfField.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
Quote

java.lang.NullPointerException: Unexpected error
    at net.minecraft.item.BlockItem.getTranslationKey(BlockItem.java:181) ~[forge-1.14.3-27.0.25_mapped_snapshot_20190621-1.14.2-recomp.jar:?] {}

https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
3 hours ago, Cadiboo said:

instead of event.getRegistry().register(new BlockItem(ModBlocks.FIRSTBLOCK, new Item.Properties()).setRegistryName("firstblock")); use event.getRegistry().register(new BlockItem(ModBlocks.FIRSTBLOCK, new Item.Properties()).setRegistryName(ModBlocks.FIRSTBLOCK.getRegistryName()));

This eliminates the chance of getting the registry name wrong.

 

Change your ModBlocks class from


public class ModBlocks {
    @ObjectHolder("mytutorial:firstblock")
    public static FirstBlock FIRSTBLOCK;
}

to


@ObjectHolder(ColoredTorches.modid)
public class ModBlocks {
    public static final FirstBlock FIRSTBLOCK = null;
}

 

You're game is currently crashing because ModBlocks.FIRSTBLOCK is null. It is null because you've hardcoded the name of the block to "mytutorial:firstblock" when it should be "coloredtorches:firstblock". This means that the field never gets filled with your block, and you're item block tries to use a null block in getTranslationKey, causing a crash. Putting @ObjectHolder on your class with your modid means that you don't need to hardcode each name above each field, instead the name of the object is gotten with yourModId + ":" + nameOfField.

 

Gah. I’m an idiot, and apparently can’t read. Thank you so much — and I’ll take your advice into account.

 

I noticed the harcoding too. I was trying to follow the tutorial I saw, which I imagine hardcoded to more clearly explain what was going on. I thought I could make the code more elegant if I could just get it to work, which, obviously, proved to my embarassment. I suppose I just copied and pasted code without being careful enough to change it. I apologize for being a moron. 

 

Thank you, again. 

Edited by freelancepoliceman

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.