Jump to content

Food that can place reed


Kander16

Recommended Posts

Ok,

 

So i wanted to create a new crop that works like a sugar cane (corn).

 

With a sugar cane plant, you collect the sugar cane, but you cannot eat them.

I want to have a corn plant, that gives you the items of it. You can use it for planting another corn, or you could eat it as well.

Now, the problem is that a sugar cane item extends Item, not Itemfood. And i can't get it to work.

Cause when iam trying to plant the corn. It just crashes the whole game.

 

This is my code: http://pastebin.com/V53FNAj1

 

Thanks.

Creator of the Master Chef Mod and many more to come.

 

If I helped you, please click the 'thank you' button.

Link to comment
Share on other sites

Hi

 

I bet your 'crash' is a _NullPointerException_.

The way how you set up the class and (I assume, since you only provided us with one file) your block / item registration works, your block flied is null on run time.

Don't use object variables if you try to do something like this!

 

I'd suggest to directly access your mod blocks within the onItemUse method.

 

Sincerely -pick.

 

PS: you CAN rename class / object variables within your own class, this technique makes code more readable

Since English is not my mother tongue, my sentences may are confusing.

 

I'm coding java for a long time now - just MC and forge stop me sometimes.

Link to comment
Share on other sites

Hi

 

Did you test my previous advice?

 

The crash-report really looks like the above mentioned problem occured.

 

If it helps:

 

//within your onItemUse
//do stoff
world.setBlock(x,y+1,z, ModBlocks.YOURCORN, 0, flag);
//y+1 since you mostly want to place the corn _above_ the clicked block
//ModBlocks.YOURCORN, thats the mod-unique field of the desired block
//0 - I assume this is the first growth stage (or generally: the metadata)
//flag, an integer flag. see World.setBlock(int,int,int,Block,int,int) to get more info about that

//do other stuff like reduce itemstack and so on...

 

 

Sincerely -pick

 

PS: Why didn't you post your new code?

Since English is not my mother tongue, my sentences may are confusing.

 

I'm coding java for a long time now - just MC and forge stop me sometimes.

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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