Add ItemType#getBurnDuration() (#12604)

This commit is contained in:
Strokkur24
2025-06-21 07:54:29 +02:00
committed by GitHub
parent 3750927a06
commit d61a51e81e
2 changed files with 22 additions and 0 deletions

View File

@@ -3021,9 +3021,18 @@ public interface ItemType extends Keyed, Translatable, net.kyori.adventure.trans
* Checks if this item type can be used as fuel in a Furnace
*
* @return true if this item type can be used as fuel.
* @see #getBurnDuration()
*/
boolean isFuel();
/**
* Retrieve the item's burn duration in a Furnace
*
* @return the burn duration, in ticks or 0 if the item is not fuel
* @see #isFuel()
*/
int getBurnDuration();
/**
* Checks whether this item type is compostable (can be inserted into a
* composter).

View File

@@ -15,6 +15,7 @@ import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.level.block.ComposterBlock;
import net.minecraft.world.level.block.entity.FuelValues;
import org.bukkit.Material;
import org.bukkit.Registry;
import org.bukkit.World;
@@ -155,6 +156,18 @@ public class CraftItemType<M extends ItemMeta> extends HolderableBase<Item> impl
return MinecraftServer.getServer().fuelValues().isFuel(new net.minecraft.world.item.ItemStack(this.getHandle()));
}
@Override
public int getBurnDuration() {
FuelValues fuelValues = MinecraftServer.getServer().fuelValues();
net.minecraft.world.item.ItemStack stack = new net.minecraft.world.item.ItemStack(this.getHandle());
if (!fuelValues.isFuel(stack)) {
return 0;
}
return fuelValues.burnDuration(stack);
}
@Override
public boolean isCompostable() {
return ComposterBlock.COMPOSTABLES.containsKey(this.getHandle());