Posted April 10, 201411 yr Hi! I'm having some trouble producing an item (a bucket) that can milk cows when right-clicked. Here's my current attempt, that is like the code on ItemSmeltedEvent to handle the crafting. FMLCommonHandler.instance().bus().register(new EntityInteract()); public class EntityInteract { @SubscribeEvent public void onEntityInteract(EntityInteractEvent event) { if (event.target instanceof EntityCow && event.entityPlayer.getCurrentEquippedItem() == new ItemStack(FTea.teaCup)) { event.entityPlayer.inventory.addItemStackToInventory(new ItemStack(FTea.milk)); } } }
April 10, 201411 yr you didn't really list what your problem was so I can only guess to the solution. I'm assuming the item doesn't appear in your hand. Instead of adding an itemstack to the player inventory, you should change the item in his hand. Long time Bukkit & Forge Programmer Happy to try and help
April 11, 201411 yr event.entityPlayer.getCurrentEquippedItem() == new ItemStack(FTea.teaCup) This is never true. Learn basic java. Yes. You cannot say if (something == new SomeClass()) Try if (event.target instanceof EntityCow && event.entityPlayer.getCurrentEquippedItem().getItem() == FTea.teaCup) Hope it works. http://i.imgur.com/LWcDco2.png[/img]
April 11, 201411 yr Author Thanks for helping! I had to write this: MinecraftForge.EVENT_BUS.register(new EntityInteract()); instead of this because the event is in MinecraftForge: FMLCommonHandler.instance().bus().register(new EntityInteract()); Also the mistake above was a problem
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.