Skip to content

Commit

Permalink
feat: Add setBurnTime hook
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Jul 3, 2024
1 parent f91ba37 commit 50b99d7
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
2 changes: 2 additions & 0 deletions common/src/main/java/net/blay09/mods/balm/api/BalmHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,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) {
}
Expand Down
25 changes: 25 additions & 0 deletions forge/src/main/java/net/blay09/mods/balm/forge/ForgeBalmHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,42 @@
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;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.ToolActions;
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<Item, Integer> 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<ConfiguredFeature<?, ?>> holder) {
return !ForgeEventFactory.blockGrowFeature(level, random, pos, holder).getResult().equals(Event.Result.DENY);
Expand Down Expand Up @@ -98,6 +118,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,40 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BoneMealItem;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.*;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.phys.BlockHitResult;
import net.neoforged.neoforge.common.EffectCures;
import net.neoforged.neoforge.common.ItemAbilities;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.common.util.FakePlayer;
import net.neoforged.neoforge.event.EventHooks;
import net.neoforged.neoforge.event.furnace.FurnaceFuelBurnTimeEvent;
import net.neoforged.neoforge.fluids.FluidUtil;
import net.neoforged.neoforge.server.ServerLifecycleHooks;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;

public class NeoForgeBalmHooks implements BalmHooks {

public final Map<Item, Integer> burnTimes = new HashMap<>();

public NeoForgeBalmHooks() {
NeoForge.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<ConfiguredFeature<?, ?>> holder) {
return !EventHooks.fireBlockGrowFeature(level, random, pos, holder).isCanceled();
Expand Down Expand Up @@ -100,6 +116,11 @@ public int getBurnTime(ItemStack itemStack) {
return itemStack.getBurnTime(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) {
EventHooks.firePlayerCraftingEvent(player, crafted, craftMatrix);
Expand Down

0 comments on commit 50b99d7

Please sign in to comment.