Posted December 4, 20195 yr I'm trying to make a new corn crop... I'm following this tutorial: https://shadowfacts.net/tutorials/forge-modding-112/crops/ Closer th the problem, I have next classes: BlockCropCorn extends BlockCrops, ItemCronSeed extends ItemSeeds. Also I have just an item "corn", which is basically an instance of ItemEdible extends ItemFood. In game, everything is ok if I plant corn by setting the block, but when i try to plant it using seeds, everything dies... Everything next will be explained. Crash report: java.lang.NullPointerException: Unexpected error at net.minecraft.item.ItemSeeds.getPlant(ItemSeeds.java:61) at net.minecraft.block.Block.canSustainPlant(Block.java:1931) at net.minecraft.item.ItemSeeds.onItemUse(ItemSeeds.java:34) at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:201) at net.minecraft.client.multiplayer.PlayerControllerMP.processRightClickBlock(PlayerControllerMP.java:509) at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1693) at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:2380) at net.minecraft.client.Minecraft.runTickKeyboard(Minecraft.java:2146) at net.minecraft.client.Minecraft.runTick(Minecraft.java:1934) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1187) at net.minecraft.client.Minecraft.run(Minecraft.java:441) at net.minecraft.client.main.Main.main(Main.java:118) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) at GradleStart.main(GradleStart.java:25) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Client thread Stacktrace: at net.minecraft.item.ItemSeeds.getPlant(ItemSeeds.java:61) at net.minecraft.block.Block.canSustainPlant(Block.java:1931) at net.minecraft.item.ItemSeeds.onItemUse(ItemSeeds.java:34) at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:201) at net.minecraft.client.multiplayer.PlayerControllerMP.processRightClickBlock(PlayerControllerMP.java:509) at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1693) at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:2380) at net.minecraft.client.Minecraft.runTickKeyboard(Minecraft.java:2146) Class for registering all the items(except block items) : public class ItemsRegistry { public static final Map<String, Item> MOD_ITEMS = new HashMap<String, Item>(); static { //MOD_ITEMS.put("heart", new ItemBase("heart")); //MOD_ITEMS.put("bpcookie", new ItemEdible("bpcookie", 2, 2, true, false, true, 10, 100)); MOD_ITEMS.put("cornSeed", new ItemCornSeed()); MOD_ITEMS.put("corn", new ItemEdible("corn", 2, 1, false, false, false, 0, 0)); } @SideOnly(Side.CLIENT) public static void registerItems() { ForgeRegistries.ITEMS.registerAll(MOD_ITEMS.values().toArray(new Item[0])); } public static void registerRender() { for(Item modItem : MOD_ITEMS.values()) { Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(modItem, 0, new ModelResourceLocation(modItem.getRegistryName(), "inventory")); } } } Class for registering all the blocks: public class BlocksRegistry { public static final Map<String, Block> MOD_BLOCKS = new HashMap<String, Block>(); static { //MOD_BLOCKS.put("strangeblock", new BlockBase("strangeblock", Material.IRON)); MOD_BLOCKS.put("cropCorn", new BlockCropCorn()); } public static void registerBlocks() { for(Block block : MOD_BLOCKS.values()) { ForgeRegistries.BLOCKS.register(block); ForgeRegistries.ITEMS.register(new ItemBlock(block).setRegistryName(block.getRegistryName())); } } @SideOnly(Side.CLIENT) public static void registerRender() { for(Block block : MOD_BLOCKS.values()) { Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(), "inventory")); } } } Class BlockCropCorn: public class BlockCropCorn extends BlockCrops{ public BlockCropCorn() { setRegistryName("crop_corn"); setUnlocalizedName("crop_corn"); } @Override protected Item getSeed() { return ItemsRegistry.MOD_ITEMS.get("cornSeed"); } @Override protected Item getCrop() { return ItemsRegistry.MOD_ITEMS.get("corn"); } } Class ItemCornSeed: public class ItemCornSeed extends ItemSeeds{ public ItemCornSeed() { super(BlocksRegistry.MOD_BLOCKS.get("cornCrop"), Blocks.FARMLAND); setRegistryName("corn_seed"); setUnlocalizedName("corn_seed"); } } preInit() in class CommonProxy: public void preInit(FMLPreInitializationEvent event) { ItemsRegistry.registerItems(); BlocksRegistry.registerBlocks(); } I tried many many many things: overriding getPlant() or getPlantType(); replacing getSeed() and getCrop() between ItemCornSeed and BlockCropCorn; replacing blocks and items registry in preInit(). Nothing helps(maybe i did some of these incorrect, idk) And please don't call me the stupidest idiot in the universe, because I don't know Java in details, I don't know how Minecraft works and I started learning how to write mods only 2 days ago..
December 4, 20195 yr 35 minutes ago, Feofile said: static { //MOD_BLOCKS.put("strangeblock", new BlockBase("strangeblock", Material.IRON)); MOD_BLOCKS.put("cropCorn", new BlockCropCorn()); } Don't create RegistryEntries in static initializers, only do so in Forge controlled vents so that instantiation happens at a known and controllable point. 35 minutes ago, Feofile said: @SideOnly(Side.CLIENT) public static void registerItems() { Yes, only register your items on the client side. Nothing could go wrong here... 35 minutes ago, Feofile said: ForgeRegistries.ITEMS.registerAll Speaking of, this is wrong, you should be using the registry events. 35 minutes ago, Feofile said: @Override protected Item getSeed() { return ItemsRegistry.MOD_ITEMS.get("cornSeed"); } Use @ObjectHolder annotations instead. 35 minutes ago, Feofile said: @SideOnly(Side.CLIENT) public static void registerRender() { for(Block block : MOD_BLOCKS.values()) { Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), 0, new ModelResourceLocation(block.getRegistryName(), "inventory")); } } ModelLoader.setCustomModelResourceLocation exists for a reason. Do not use the Model Mesher. If you aren't on 1.12, update. 35 minutes ago, Feofile said: public ItemCornSeed() { super(BlocksRegistry.MOD_BLOCKS.get("cornCrop"), Blocks.FARMLAND); This value is probably null here, because your block hasn't been registered yet. Also, D7 ninja'd me. Edited December 4, 20195 yr by Draco18s 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.
December 4, 20195 yr Author 1 minute ago, Draco18s said: Forge controlled vents what do you mean (im scared of this)
December 4, 20195 yr Author 7 minutes ago, Draco18s said: Don't create RegistryEntries in static initializers, only do so in Forge controlled vents so that instantiation happens at a known and controllable point. I'm really sorry but I have no idea what events does Forge has for mod's things registration..
December 4, 20195 yr https://mcforge.readthedocs.io/en/1.13.x/concepts/registries/#registering-things 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.
December 4, 20195 yr Author I still can't understand where must I call these registry events.. A new class or in one of the Proxy's init methods? Edit: I think I can find all the answers in the tutorial from shadowfacts.. maybe Edited December 4, 20195 yr by Feofile
December 4, 20195 yr 2 hours ago, Feofile said: I still can't understand where must I call these registry events. You don't, you listen for them. See also: https://mcforge.readthedocs.io/en/1.13.x/events/intro/ 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.
April 12, 20205 yr On 12/4/2019 at 5:49 PM, Draco18s said: This value is probably null here, because your block hasn't been registered yet. How do I register the blocks before the items? Also, will doing so hurt some other scripts like ores dropping items?
April 12, 20205 yr Just a link to smth would be nice cuz I cant find anything on that Edited April 12, 20205 yr by SeerBird
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.