Jump to content

[1.10.2] Capabilities mean I don't need to implement ISidedInventory anymore?


Starless

Recommended Posts

My Block should implement ISidedInventory, but there's this new thing called Capabilities. Do I need to use both or choose one? Are Capabilities like an object that handle all that's related to that thing for you? (getStackInSlot, getInventorySize, decrStackSize, etc).

 

If not, what are they good for?

Link to comment
Share on other sites

Capabilities are a solution to the horrible "god object" TileEntites (and the like) that implement 20 interfaces to support everyone and their brother's energy API.

 

Instead of implementing interfaces directly, you ask the TileEntity (or other ICapabilityProvider): "hey, you got this capability?" and they can respond however they like.

Forge comes with a built-in capability: IItemHandler which is the replacement for IInventory and friends.

 

so, I still have to implement ISidedInventory. Now I just need to implement a Capability for it too.

Link to comment
Share on other sites

Hmm. I have to implement a different IItemHandler for each side then? (each side that matters for automation, that is).

 

I would have to have 3 separate inventories, so that would be 3 IItemHandlers. I could have an abstract base class for them, and override just what I need for make the sides work. Still, this seems like a lot of extra steps compared to just implementing ISidedInventory....

 

I have a feeling Forge gets more and more complicated as time passes by, which is very unusual. Generally, frameworks get simpler with time, hiding away plumbing stuff in the form of elegant abstractions. Take Java's new lambdas for example. No longer you need an anonymous class, just a lambda expression. With Forge, some things seem to go the other way around. It is as if we had lambdas, but now we have to implement a separate class on a separate file. not even anonymous classes will do anymore. Now we have to really get our hands in there.

Link to comment
Share on other sites

I assume IStackHandler lets me put whatever item I want in whatever slot I want, correct? IStackHandler would then work as the base class for the 3 different inventories I need to make my tile entity work. It can only accept certain types of items in a certain inventory, it cannot accept any items on another inventory, only the tile entity itself can put items there... there's a few more details that I need, but I think it's safe to assume IStackHandler is just "a chest" of sorts right?

Link to comment
Share on other sites

True, but its still a simple system, especially the conversion from the old to the new.

 

it's not that complicated, but it was perfectly good the way it was, and it just added extra steps to something that could be done easily. maybe the idea behind capabilities is the right way to go, and their implementation just need better a designing. Like when networking used to be so complicated and then became this beautiful elegant system it is now. Capabilities might get there too.

Link to comment
Share on other sites

Like when networking used to be so complicated and then became this beautiful elegant system it is now. Capabilities might get there too.

 

width=786 height=438dLfPsSw.png?1 [/img]

 

Try reading corpo code. As of now Forge API is very clear and Caps are way better than IEEP. 8)

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

maybe the idea behind capabilities is the right way to go, and their implementation just need better a designing. ... Capabilities might get there too.

So, what you mean to say is:

I don't know what this new thing is and I haven't taken the time to sit down and understand its design so i'm going to complain that the new thing is bad because it scares me!

Fixed that for you.

 

Either way, the vanilla ISided stuff is bad because it lets someone reach into your pants and rifle through your pockets and you don't even know there is anyone else on earth.

The new system {IItemHandler} is cleaned up and makes sure you KNOW when your pockets are being stolen from.

 

As for the Capability system itself how the HELL is it bad?

Its LITERALLY two functions:

'You has dis?'

'Gimmie dis!!'

 

The code literally changes from:

if (te instanceof ISidedHandler)
   ISidedHandler inv = (ISidedHandler)te;

To:

if (te.hasCapability(ITEM_HANDLER, null))
  IItemHandler inv = te.getCapability(ITEM_HANDLER, null);

OOOOHHHH so complicated!

Seriously, don't bitch about something just because you don't understand it.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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