Denyol Posted February 5, 2017 Posted February 5, 2017 Hello, I'm having a lot of trouble finding information on adding and IItemHandler capability to an Item, for an TileEntity it has methods like hasCapability however I can't find a method like that in an Item, all items have is "initCapabilities", and I have honestly no clue what to return or do to add an inventory to an item. So if anyone could please point me to any information that could tell me how capabilities work on items and how to implement an inventory. Thank you. Quote
Draco18s Posted February 5, 2017 Posted February 5, 2017 Items don't have Capabilities, ItemStacks do. Quote 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.
Denyol Posted February 5, 2017 Author Posted February 5, 2017 On 2/5/2017 at 5:04 AM, Draco18s said: Items don't have Capabilities, ItemStacks do. Expand So how would I add an inventory to my custom item? Quote
RealTheUnderTaker11 Posted February 5, 2017 Posted February 5, 2017 (edited) The ItemStack is what has the hasCapability, and I have never set up an item that holds inventory, but since they don't have sides I wouldn't think you would need to override the hasCapability and getCapability. Have you tried setting up the capability handler and seeing what happens? Like I said I've never tested it before though. I could be completely wrong about this. Edited February 5, 2017 by RealTheUnderTaker11 Quote My IGN is TheUnderTaker11, but when I tried to sign up for this site it would not send the email... So yea now I have to use this account.
Denyol Posted February 5, 2017 Author Posted February 5, 2017 On 2/5/2017 at 5:07 AM, RealTheUnderTaker11 said: The ItemStack is what has the hasCapability, and I have never set up an item that holds inventory, but since they don't have sides I wouldn't think you would need to override the hasCapability and getCapability. Have you tried setting up the capability handler and seeing what happens? Like I said I've never tested it before though. I could be completely wrong about this. Expand I have no idea what or how to set up a capability handler, and the docs are confusing and badly explain things. Quote
Draco18s Posted February 5, 2017 Posted February 5, 2017 On 2/5/2017 at 5:05 AM, Denyol said: So how would I add an inventory to my custom item? Expand There's an AddCapabilities event. Register a listener for the ItemStack one, and when it fires, add an ItemHandler capability to it. Quote 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.
RealTheUnderTaker11 Posted February 5, 2017 Posted February 5, 2017 (edited) On 2/5/2017 at 5:09 AM, Denyol said: I have no idea what or how to set up a capability handler, and the docs are confusing and badly explain things. Expand Then you should of asked that in the first place, I used this to make a capability handler for players/Entity's. It should be something very similar for ItemStacks. I don't know how it will work for ItemHandlers though since those are already a thing in forge EDIT: Yea what Draco said too. Edited February 5, 2017 by RealTheUnderTaker11 Quote My IGN is TheUnderTaker11, but when I tried to sign up for this site it would not send the email... So yea now I have to use this account.
Denyol Posted February 5, 2017 Author Posted February 5, 2017 (edited) On 2/5/2017 at 5:11 AM, Draco18s said: There's an AddCapabilities event. Register a listener for the ItemStack one, and when it fires, add an ItemHandler capability to it. Expand Very well easier said than done, as I said earlier I have no idea how to use the capabilities system, do you mind providing a code example? Edited February 5, 2017 by Denyol Quote
Denyol Posted February 5, 2017 Author Posted February 5, 2017 On 2/5/2017 at 5:11 AM, RealTheUnderTaker11 said: Then you should of asked that in the first place, I used this to make a capability handler for players/Entity's. It should be something very similar for ItemStacks. I don't know how it will work for ItemHandlers though since those are already a thing in forge EDIT: Yea what Draco said too. Expand That link is for custom capabilities, I just want the forge IItemHandler Quote
Choonster Posted February 5, 2017 Posted February 5, 2017 (edited) Only use AttachCapabilitiesEvent to attach capabilities to external objects. For your own Items, override Item#initCapabilities to return a new instance of an ICapabilityProvider implementation that provides the capability instance. Your ICapabilityProvider should store the IItemHandler instance, implement ICapabilityProvider#hasCapability to return true if the Capability argument is CapabilityItemHandler.ITEM_HANDLER_CAPABILITY and implement ICapabilityProvider#getCapability to return the IItemHandler instance if the Capability argument is CapabilityItemHandler.ITEM_HANDLER_CAPABILITY. Edited February 5, 2017 by Choonster 1 1 Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
Denyol Posted February 5, 2017 Author Posted February 5, 2017 On 2/5/2017 at 5:36 AM, Choonster said: Only use AttachCapabilitiesEvent to attach capabilities to external objects. For your own Items, override Item#initCapabilities to return a new instance of an ICapabilityProvider implementation that provides the capability instance. Your ICapabilityProvider should store the IItemHandler instance, implement ICapabilityProvider#hasCapability to return true if the Capability argument is CapabilityItemHandler.ITEM_HANDLER_CAPABILITY and implement ICapabilityProvider#getCapability to return the IItemHandler instance if the Capability argument is CapabilityItemHandler.ITEM_HANDLER_CAPABILITY. Expand Thankyou Quote
Recommended Posts
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.