Added ItemDecorator Map#8794
Conversation
|
This is not a good way to go about doing this. Render code should not be present or relevant to the server (which capabilities are), Capabilities also add other complexity when present that is additional overhead that is strictly not necessary in a render context (the cost of getCap is significant to be running every frame). |
|
diesieben07 wrote in #8048
Which is why this thing was designed as a capability. Getting the capability, once initialized, is just an array lookup through the ICapabilityProvider in CapabilityDispatcher until one returns the cap you want. Also during normal gameplay only 9 ItemStacks will be usually visible, so the impact in normal gameplay is more likely around/below 0.25ms on each frame |
676545f to
384c930
Compare
marchermans
left a comment
There was a problem hiding this comment.
This is a flatout no.
Capabilities are not a great idea to handle rendering, especially on itemstacks where they are already a problem.
Redesign this to be an event please.
|
What kind of an event? Just for my own knowledge: Why is rendering with capabilities on itemstacks such a big problem? |
|
Because capabilities are not designed for it and they are not supposed to be Client only. But i can ask internally if we might want to add support for it. |
|
PR's for events that fire on stack rendering have historically been automatically denied, so it may only be accepted as an extension to the client item interface |
|
The ItemDecorations have been moved to the IClientItemExtension. Notable changes: |
|
Just make the method default and return |
|
Nevermind, I see the intention is to be able to add to other items, which would require an existing mutable list to be accessible. |
|
You could, however, get around the binary break by adding two methods - one Then |
|
That is true, but would mean that mod authors that already implement this interface might not be aware of this change. I've also considered a throw in dev scenario, but that would only throw if someone tries to add a a decorator in dev which might not happen. Logging the default impl with warning might be an option, but also has the problem of only being fixed if someone reports it to the mod author, which is hard to do as there is no context to which item a decorator was tried to be added. |
|
The List should probably not live in |
|
diesieben sniped me a little here: |
|
They could extend |
|
That would still make it a breaking change because you would need to enforce the use of |
|
It's a breaking change, but there was not Recommended Build yet and with this interface being kinda new I doubt many people will be effected by this break. The generic change in initializeClient is not necessary, and anyone can create their own implementation of |
|
The |
Performance tests:How I acquired the data
Time MeasurementsJEI
Creative Menu
My ConclusionPerformance is not a big problem, if not too many decorators are used. Most of the code execution time is coming from rendering and not the overhead of this feature, hence modders should be careful what they do with this feature, but providing this feature is not too big of a problem. Further actionsI'm going to fix the things mentioned by diesieben and add javadocs where necessary. With the data provided, I await a decision regarding Map or field in Item |
This is a retry of #8070 and #8079
So beforehand I'll reply to some of the comments of those PRs, if applicable:
DieSieben07 on #8079
To solve this, there is a helper method in ForgeHooksClient to add an IItemDecorator to the ItemStack, during AttachCapabilitiesEvent, so no one has to check if the cap is present and add a provider themselves if it isn't.
ChampionAsh on #8079
I don't think a positioning system is necessary, as the blitOffset (height) is given to the renderer and everyone can render at a height they want. A positioning System would require the rendering of the durability bar and the count to be made an IItemDecorator as well and as soon as every ItemStack needs this capability, a field in the ItemStack will always be faster.
If this is intended I can change that system to not use a capability, but some kind of positioned List
Performance:
Test done on a full chest gui (63 Slots in total) and all slots filled with the same item
With 2 IItemDecorations:
gui needed on average 4.2 ms or ca. 0.066ms per item
Without IItemDecorations:
gui needed on average 2.7ms or ca. 0.042ms per item