Modern Industrialization

Modern Industrialization

9M Downloads

Please dont randomly add Exceptions to vanilla methods without a singature

Smartin-b opened this issue ยท 6 comments

commented

throw new UnsupportedOperationException("Cannot repair Diesel Jetpack");

Ingredient.Empty is fully valid way of declaring this item cant be repaired. Throwing an Exception here can cause issues in other mods.

commented

This code was written a long time ago, so I don't remember the details. I think there were other issues with returning an empty ingredient (maybe because an empty ingredient will accept empty stacks?). I think the reasoning was that because of the durability being 0, nothing should ever even attempt to repair this armor.

commented

@Smartin-b Can you link the code that attempted to call this method?

commented

ArmorMaterial#repairIngredient still shouldn't throw an exception...

commented

This can be avoided by checking if the item has the MAX_DAMAGE or DAMAGE component before trying to get a non-existent repair ingredient. For example:

item.components().has(DataComponents.DAMAGE)
commented

It throws an exception because even calling the method indicates that a check is missing, as @Swedz pointed out. Not amazing I agree but a good way to detect logic errors in other mods IMO.