mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-14 01:04:24 +00:00
Add IRecipeType parameter to burn time hooks (#7771)
This commit is contained in:
1 parent
df53db351e
commit
f9b894ecbf
7 files changed
+77
-8
No files matched your search
@@ -63,6 +63,7 @@ import net.minecraft.entity.ai.attributes.AttributeModifierMap;
|
||||
import net.minecraft.entity.ai.attributes.GlobalEntityTypeAttributes;
|
||||
import net.minecraft.fluid.*;
|
||||
import net.minecraft.inventory.EquipmentSlotType;
|
||||
import net.minecraft.item.crafting.IRecipeType;
|
||||
import net.minecraft.loot.LootContext;
|
||||
import net.minecraft.loot.LootTable;
|
||||
import net.minecraft.loot.LootTableManager;
|
||||
@@ -1244,10 +1245,16 @@ public class ForgeHooks
|
||||
|
||||
private static final Map<IRegistryDelegate<Item>, Integer> VANILLA_BURNS = new HashMap<>();
|
||||
|
||||
@Deprecated // use variant with IRecipeType
|
||||
public static int getBurnTime(ItemStack stack)
|
||||
{
|
||||
return getBurnTime(stack, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the burn time of this itemstack.
|
||||
*/
|
||||
public static int getBurnTime(ItemStack stack)
|
||||
public static int getBurnTime(ItemStack stack, @Nullable IRecipeType<?> recipeType)
|
||||
{
|
||||
if (stack.isEmpty())
|
||||
{
|
||||
@@ -1256,8 +1263,8 @@ public class ForgeHooks
|
||||
else
|
||||
{
|
||||
Item item = stack.getItem();
|
||||
int ret = stack.getBurnTime();
|
||||
return ForgeEventFactory.getItemBurnTime(stack, ret == -1 ? VANILLA_BURNS.getOrDefault(item.delegate, 0) : ret);
|
||||
int ret = stack.getBurnTime(recipeType);
|
||||
return ForgeEventFactory.getItemBurnTime(stack, ret == -1 ? VANILLA_BURNS.getOrDefault(item.delegate, 0) : ret, recipeType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ import net.minecraft.item.AxeItem;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.item.crafting.IRecipeType;
|
||||
import net.minecraft.nbt.CompoundNBT;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -759,7 +760,13 @@ public interface IForgeItem
|
||||
* it not act as a fuel. Return -1 to let the default vanilla logic
|
||||
* decide.
|
||||
*/
|
||||
default int getBurnTime(ItemStack itemStack)
|
||||
default int getBurnTime(ItemStack itemStack, @Nullable IRecipeType<?> recipeType)
|
||||
{
|
||||
return getBurnTime(itemStack);
|
||||
}
|
||||
|
||||
@Deprecated // use variant with IRecipeType
|
||||
default int getBurnTime(ItemStack stack)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.Set;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.monster.EndermanEntity;
|
||||
import net.minecraft.item.crafting.IRecipeType;
|
||||
import net.minecraft.util.CachedBlockInfo;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
@@ -83,9 +84,15 @@ public interface IForgeItemStack extends ICapabilitySerializable<CompoundNBT>
|
||||
* it not act as a fuel. Return -1 to let the default vanilla logic
|
||||
* decide.
|
||||
*/
|
||||
default int getBurnTime(@Nullable IRecipeType<?> recipeType)
|
||||
{
|
||||
return getStack().getItem().getBurnTime(getStack(), recipeType);
|
||||
}
|
||||
|
||||
@Deprecated // use variant with IRecipeType
|
||||
default int getBurnTime()
|
||||
{
|
||||
return getStack().getItem().getBurnTime(getStack());
|
||||
return getBurnTime(null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,6 +57,7 @@ import net.minecraft.entity.projectile.ThrowableEntity;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUseContext;
|
||||
import net.minecraft.item.crafting.IRecipeType;
|
||||
import net.minecraft.loot.LootTable;
|
||||
import net.minecraft.loot.LootTableManager;
|
||||
import net.minecraft.resources.IFutureReloadListener;
|
||||
@@ -221,9 +222,15 @@ public class ForgeEventFactory
|
||||
return event.getResult();
|
||||
}
|
||||
|
||||
@Deprecated // use version with IRecipeType
|
||||
public static int getItemBurnTime(@Nonnull ItemStack itemStack, int burnTime)
|
||||
{
|
||||
FurnaceFuelBurnTimeEvent event = new FurnaceFuelBurnTimeEvent(itemStack, burnTime);
|
||||
return getItemBurnTime(itemStack, burnTime, null);
|
||||
}
|
||||
|
||||
public static int getItemBurnTime(@Nonnull ItemStack itemStack, int burnTime, @Nullable IRecipeType<?> recipeType)
|
||||
{
|
||||
FurnaceFuelBurnTimeEvent event = new FurnaceFuelBurnTimeEvent(itemStack, burnTime, recipeType);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getBurnTime();
|
||||
}
|
||||
|
||||
@@ -20,9 +20,11 @@
|
||||
package net.minecraftforge.event.furnace;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipeType;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
@@ -46,12 +48,21 @@ public class FurnaceFuelBurnTimeEvent extends Event
|
||||
{
|
||||
@Nonnull
|
||||
private final ItemStack itemStack;
|
||||
@Nullable
|
||||
private final IRecipeType<?> recipeType;
|
||||
private int burnTime;
|
||||
|
||||
@Deprecated // use version with IRecipeType
|
||||
public FurnaceFuelBurnTimeEvent(@Nonnull ItemStack itemStack, int burnTime)
|
||||
{
|
||||
this(itemStack, burnTime, null);
|
||||
}
|
||||
|
||||
public FurnaceFuelBurnTimeEvent(@Nonnull ItemStack itemStack, int burnTime, @Nullable IRecipeType<?> recipeType)
|
||||
{
|
||||
this.itemStack = itemStack;
|
||||
this.burnTime = burnTime;
|
||||
this.recipeType = recipeType;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,6 +74,16 @@ public class FurnaceFuelBurnTimeEvent extends Event
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Get the recipe type for which to obtain the burn time, if known.
|
||||
*/
|
||||
@Nullable
|
||||
public IRecipeType<?> getRecipeType()
|
||||
{
|
||||
return recipeType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the burn time for the given ItemStack.
|
||||
* Setting it to 0 will prevent the item from being used as fuel, overriding vanilla's decision.
|
||||
|
||||
Reference in new issue
Block a user