Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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

  • Author
1 minute ago, Draco18s said:

Forge controlled vents

what do you mean
(im scared of this)

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

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.

  • 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 by Feofile

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.

  • 4 months later...
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?

Just a link to smth would be nice cuz I cant find anything on that

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.