Jump to content

[Forge 1.10.2] Can I normally cast from IInventory to IItemHandler?


Recommended Posts

Posted

I know this is a really dumb question but I wondered if I can cast from IInventory to IItemHandler. Because it has some methods that use IInventory instead of the IItemHandler capability system. Like Container#onCraftMatrixChanged, IContainerListener#sendAllWindowProperties.,... I would greatly appreciated your help!

Posted

No.
IItemHandler, and IInventory are both interfaces, that both do similar things, but in the end, they are separate things altogether.
A class can implement both, but often enough, they are not both used.

IF said class makes use of both interfaces, then you can freely cast an instance of that class to either.

However, using both is incredibly redundant, as in the end, they do the same thing, with IItemHandler being the better choice, as it handles much of the logic for you.

 

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Posted
2 minutes ago, Matryoshika said:

No.
IItemHandler, and IInventory are both interfaces, that both do similar things, but in the end, they are separate things altogether.
A class can implement both, but often enough, they are not both used.

IF said class makes use of both interfaces, then you can freely cast an instance of that class to either.

However, using both is incredibly redundant, as in the end, they do the same thing, with IItemHandler being the better choice, as it handles much of the logic for you.

 

I mean how to make  it work wit  Container#onCraftMatrixChanged, IContainerListener#sendAllWindowProperties. They only use IInventory

Posted
4 minutes ago, diesieben07 said:

No, IItemHandler and IInventory are separate interfaces. Why do you need those two methods?

I mean how to make  it work wit  Container#onCraftMatrixChanged, IContainerListener#sendAllWindowProperties. They only use IInventory

Posted
Just now, diesieben07 said:

Yes, I understand that. But why do you need these methods? onCraftMatrixChanged only calls detectAndSendChanges by default and sendAllWindowProperties only makes sense with something that natively implements IInventory.

So what method will I use if I use IItemHandler to update the progress bar?

Posted
4 minutes ago, diesieben07 said:

You call sendProgressBarUpdate which will call updateProgressBar on the client.

I have problem that the item insert/extract doesn't work. Each time I insert, the stack I insert doesn't decrease and when I extract, the stack doesn't take out. Here is my code:

TileSolderingStation: https://pastebin.com/Xzw57H6S

ItemHandlerBase: https://pastebin.com/bdgqDhka

ItemHandlerPersistentCrafting: https://pastebin.com/fEbec0Mv

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.