Jump to content

Problems with new crops(corn, from tutorial by shadowfacts)


Recommended Posts

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

Posted (edited)
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
  • Thanks 1

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

Posted

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)

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

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello I'm currently making an Item that thrusts you to viewing direction, and I referenced riptide code of trident for my item. @Override public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) { if(!pLevel.isClientSide() && pUsedHand == InteractionHand.MAIN_HAND && pPlayer.isOnGround()){ Impale(pPlayer, pUsedHand); pPlayer.getCooldowns().addCooldown(this, 40); } return super.use(pLevel, pPlayer, pUsedHand); } public void Impale(Player pPlayer, InteractionHand pUsedHand) { float playerYRot = pPlayer.getYRot(); float xForce = -Mth.sin(playerYRot * ((float)Math.PI / 180F)) * Mth.cos((float)Math.PI / 180F); float yForce = 100.6F; float zForce = Mth.cos(playerYRot * ((float)Math.PI / 180F)) * Mth.cos((float)Math.PI / 180F); float stabilizedForce = Mth.sqrt(xForce * xForce + zForce * zForce); xForce /= stabilizedForce; zForce /= stabilizedForce; pPlayer.push((double)xForce, (double)yForce, (double)zForce); pPlayer.sendSystemMessage(Component.literal(playerYRot + " " + xForce + " " + yForce + " " + zForce + " " + stabilizedForce + "shoo")); } I sure edited a lot from source code but this isn't working somehow? the sendSystemMessage works correctly. It prints value of variables and string, but the force isn't applying to player. how can I make this to work? Thanks.
    • i tried putting a modpack together and cant get this working no matter what i have tried log: https://pastebin.com/uqz1aKiY
    • We have an event for an Entity being struck by lighting, but doesn't look like we have one for Blocks. And unfortunately, looking at it, the LightingBolt entity doesn't have any context on why it was registered, so you wouldn't be able to get the source context. What are you trying to accomplish with this event?
    • Hey guys, I'm trying to use the simple planes mod https://www.curseforge.com/minecraft/mc-mods/simple-planes with a nuclear bombs mod https://www.curseforge.com/minecraft/mc-mods/nuclear-bombs . The simple planes mod has a cargo plane that can drop tnt, and i want it to work with the nuclear bombs. I added this JSON file from chatGPT to the payloads folder in simple planes (because the nukes couldn't even get stored in the plane in the first place), but this only allows the nuke to drop but doesn't explode: https://mclo.gs/3uEQIX2 . This nuke mod requires a redstone signal and then manual activation, which makes this tougher i imagine. If someone could write me a code for the payload folder for simpleplanes, something that even tampers with the nuke mod, or any general suggestions that would be great!  Many Thanks
    • https://paste.ee/p/Qai73Cbt  that is crash file link  
  • Topics

×
×
  • Create New...

Important Information

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