Posted July 9, 20196 yr 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 July 9, 20196 yr by freelancepoliceman
July 9, 20196 yr 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 Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.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)
July 9, 20196 yr 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.
July 9, 20196 yr Author 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 July 9, 20196 yr 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.