TechReborn / Energy

An Energy API
MIT License
78 stars 13 forks source link

Remove "count == 1" assertions #17

Closed Technici4n closed 2 years ago

Technici4n commented 2 years ago

We should remove these assertions from SimpleBatteryItem, they are not particularly useful and can cause crashes when such items are stacked accidentally (for example by megane for rendering purposes).

Ayutac commented 2 years ago

I want to point out that assert is not used in that class, it is a simple check.

when such items are stacked accidentally

shouldn't that simply not happen? What is megane doing that it might? Anyway, if it can be so common, I suggest a return and a logging before that, so the MC instance doesn't crash. Simple removal won't do...

Technici4n commented 2 years ago

"Assertions" are the general pattern, in this case it's a hard crash if the count is not exactly 1: https://github.com/TechReborn/Energy/blob/master/src/main/java/team/reborn/energy/api/base/SimpleBatteryItem.java#L54

Ayutac commented 2 years ago

generally that exception could be caught

Technici4n commented 2 years ago

Yes, but it's annoying, and the exception isn't very useful anyway.

Technici4n commented 2 years ago

Trust me, I wrote that code :P