Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Add FurnaceBurnEvent.setBurnTime(short burnTime)

Open nossr50 opened this issue 3 years ago • 6 comments

This also deprecates setBurnTime(int burnTime) and fixes its implementation as well Fixes #8178

nossr50 avatar Jul 23 '22 22:07 nossr50

Is there a better way? There's no way to write short literals in java right? So you'd now have to do

furnace.setBurnTime((short) 40);

just to avoid it using the deprecated integer method. maybe just throw exception if its too big to be converted to a short?

Machine-Maker avatar Jul 26 '22 04:07 Machine-Maker

Even if the int variant wasn't there you need to either cast to a short or put the number into a short variable to use the method (more specifically, narrowing conversions are not allowed in a method invocation context, and int literals are, well, int literals). Maybe put a @Range annotation on the int parameter? I think clamping the value is a reasonable approach, exceptions are nasty

emilyy-dev avatar Jul 26 '22 05:07 emilyy-dev

Even if the int variant wasn't there you need to either cast to a short or put the number into a short variable to use the method

Oh I figured in the absence of another method that took an int, it'd accept a regular int in a short parameter.

Machine-Maker avatar Jul 26 '22 05:07 Machine-Maker

I don't see the issue with having to cast to short since it's new API and not a change of an existing signature.

nossr50 avatar Aug 07 '22 21:08 nossr50

Casting is actively annoying and, when you have a method that does not require casting, it's very easy to miss and forget. Others might think differently but those are my two cents.

emilyy-dev avatar Aug 07 '22 23:08 emilyy-dev

I'd also be in favour of just limiting the setBurnTime(int) method to Short.MAX_VALUE like done right now for backwards compat. The getter is returning an integer. As pointed out by emily, the @Range annotation could be added to actively inform developers about the constraint on the values even without reading through javadocs.

A new method that requires developers to add rather ugly casts for little to no benefit seems overkill for a problem this small.

lynxplay avatar Nov 12 '22 18:11 lynxplay