Posted July 17, 201312 yr 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
July 17, 201312 yr if you can get the blocks x y amd z you can use worldObj.setblock(x,y.z.Id); and then maybe set the block above to what ever in code a seed does.
July 17, 201312 yr @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.
July 17, 201312 yr Author 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.
July 18, 201312 yr Author 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.
July 18, 201312 yr Author yea, found the name. it is tilledfield. Block.tilledField.blockID instead of 60. Now on to collecting items dropped when breaking the crops.
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.