diff --git a/fabric/src/main/java/net/blay09/mods/balm/fabric/FabricBalmHooks.java b/fabric/src/main/java/net/blay09/mods/balm/fabric/FabricBalmHooks.java index ff117f0f..6e2ea555 100644 --- a/fabric/src/main/java/net/blay09/mods/balm/fabric/FabricBalmHooks.java +++ b/fabric/src/main/java/net/blay09/mods/balm/fabric/FabricBalmHooks.java @@ -103,6 +103,11 @@ public int getBurnTime(ItemStack itemStack) { return burnTime != null ? burnTime : 0; } + @Override + public void setBurnTime(ItemStack itemStack, int burnTime) { + FuelRegistry.INSTANCE.add(itemStack.getItem(), burnTime); + } + @Override public void firePlayerCraftingEvent(Player player, ItemStack crafted, Container craftMatrix) { } diff --git a/forge/src/main/java/net/blay09/mods/balm/forge/ForgeBalmHooks.java b/forge/src/main/java/net/blay09/mods/balm/forge/ForgeBalmHooks.java index 31241a0a..d4f2791b 100644 --- a/forge/src/main/java/net/blay09/mods/balm/forge/ForgeBalmHooks.java +++ b/forge/src/main/java/net/blay09/mods/balm/forge/ForgeBalmHooks.java @@ -15,6 +15,7 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.BoneMealItem; import net.minecraft.world.item.DyeColor; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.Level; @@ -23,16 +24,35 @@ import net.minecraft.world.phys.BlockHitResult; import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.ForgeMod; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.ToolActions; import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.event.ForgeEventFactory; +import net.minecraftforge.event.furnace.FurnaceFuelBurnTimeEvent; import net.minecraftforge.eventbus.api.Event; import net.minecraftforge.fluids.FluidUtil; import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.server.ServerLifecycleHooks; import org.jetbrains.annotations.Nullable; +import java.util.HashMap; +import java.util.Map; + public class ForgeBalmHooks implements BalmHooks { + + public final Map burnTimes = new HashMap<>(); + + public ForgeBalmHooks() { + MinecraftForge.EVENT_BUS.addListener(this::furnaceFuelBurnTime); + } + + private void furnaceFuelBurnTime(FurnaceFuelBurnTimeEvent event) { + final var found = burnTimes.get(event.getItemStack().getItem()); + if (found != null) { + event.setBurnTime(found); + } + } + @Override public boolean blockGrowFeature(Level level, RandomSource random, BlockPos pos, @Nullable Holder> holder) { return !ForgeEventFactory.blockGrowFeature(level, random, pos, holder).getResult().equals(Event.Result.DENY); @@ -96,6 +116,11 @@ public int getBurnTime(ItemStack itemStack) { return ForgeHooks.getBurnTime(itemStack, RecipeType.SMELTING); } + @Override + public void setBurnTime(ItemStack itemStack, int burnTime) { + burnTimes.put(itemStack.getItem(), burnTime); + } + @Override public void firePlayerCraftingEvent(Player player, ItemStack crafted, Container craftMatrix) { ForgeEventFactory.firePlayerCraftingEvent(player, crafted, craftMatrix); diff --git a/shared/src/main/java/net/blay09/mods/balm/api/BalmHooks.java b/shared/src/main/java/net/blay09/mods/balm/api/BalmHooks.java index f024c4b9..289e95ea 100644 --- a/shared/src/main/java/net/blay09/mods/balm/api/BalmHooks.java +++ b/shared/src/main/java/net/blay09/mods/balm/api/BalmHooks.java @@ -56,6 +56,8 @@ default CompoundTag getPersistentData(Player player) { int getBurnTime(ItemStack itemStack); + void setBurnTime(ItemStack itemStack, int burnTime); + void firePlayerCraftingEvent(Player player, ItemStack crafted, Container craftMatrix); boolean useFluidTank(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult);