Jump to content

having a block or mob till the ground


marstone

Recommended Posts

  I have been looking around for how to get a mob (right now just a block for testing) to till and plant wheat.  Will have harvest and put in an inventory later.  Just working on the start for now.

 

  Well, I have the code done so it will check the nearby blocks out to 4 in each direction to see if it is dirt or grass.  I can't find how to till the ground, would it just be destroy the block and replace with a farmland?  Sadly, I haven't found the functions for doing that either.  I just don't know where to look for the functions, have looked in the JavaDocs but I don't see the logic in many of the groupings yet.

 

  A snippet would be great or just a function name that I can look up, anything for this poor old guy.  Thanks.

 

Marstone

Link to comment
Share on other sites

@Chibill is right, but I found a more appropriate method. If you look inside the ItemHoe class, you'll find a method to use a hoe on a block. The code looks as follows:

 

            UseHoeEvent event = new UseHoeEvent(par2EntityPlayer, par1ItemStack, par3World, par4, par5, par6); // Create a new event on creating farmland
            if (MinecraftForge.EVENT_BUS.post(event)) // Push the event into the bus, returns false when cancelled
            {
                return false;
            }

            if (event.getResult() == Result.ALLOW) // Event returns true when dirt can be changed to farmland
            {
                par1ItemStack.damageItem(1, par2EntityPlayer); // Do your stuff here
                return true;
            }

 

You'll find this in the onItemUse() method :)

 

I don't know if you can use this for a "non existing" hoe stack (new ItemStack(Item.stoneHoe)), but it's worth a try.

Link to comment
Share on other sites

okay, yeah the x,y,z is known from the search of blocks that can be tilled.  Will give setblock a try.  Thanks for the idea, I am still way to new to this and finding things in JD doesn't come natural to my brain (yet).

 

as for the hoe event, maybe (I even looked at the hoe for how it worked and missed it).  Since it is a block or later a mob I wouldn't have a EntityPlayer to pass to the function.

 

Link to comment
Share on other sites

okay, got that working, using the world placeblock method right now.  Can anyone tell me what the actual block name of the farmland is?  It is item id 60 but would like to program it correctly using "Block.?farmLand?.blockID"  instead of hardcoding the 60 in.

 

When I change my villager from a block to an actual mob, I will try sending the hoe event to see if it will add the animation of the surface breaking like when a player hoes the ground.  Thanks guys, now on to working out more logic, then putting it under a mob.

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.

Announcements



×
×
  • Create New...

Important Information

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