From 304717f9a2d60eb197694997b6581ead688a5e15 Mon Sep 17 00:00:00 2001 From: Frank Date: Tue, 11 Jul 2023 22:24:37 +0200 Subject: [PATCH] [Feature] Function in `LootUtil` to test for correct tool --- .../java/org/betterx/bclib/util/LootUtil.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/main/java/org/betterx/bclib/util/LootUtil.java b/src/main/java/org/betterx/bclib/util/LootUtil.java index 83180629..b41a5f75 100644 --- a/src/main/java/org/betterx/bclib/util/LootUtil.java +++ b/src/main/java/org/betterx/bclib/util/LootUtil.java @@ -2,10 +2,16 @@ package org.betterx.bclib.util; import org.betterx.bclib.BCLib; import org.betterx.bclib.interfaces.LootPoolAccessor; +import org.betterx.bclib.interfaces.tools.*; +import org.betterx.bclib.items.tool.BaseShearsItem; +import org.betterx.worlds.together.tag.v3.CommonItemTags; +import org.betterx.worlds.together.tag.v3.ToolTags; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; +import net.minecraft.tags.ItemTags; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.storage.loot.BuiltInLootTables; @@ -72,4 +78,32 @@ public class LootUtil { return false; } + + public static boolean isCorrectTool(ItemLike block, BlockState state, ItemStack tool) { + if (tool == null) return false; + if (state != null && tool.isCorrectToolForDrops(state)) return true; + + if (block instanceof AddMineableAxe) { + if (tool.is(ItemTags.AXES) || tool.is(ToolTags.FABRIC_AXES)) return true; + } + if (block instanceof AddMineablePickaxe) { + if (tool.is(ItemTags.PICKAXES) || tool.is(ToolTags.FABRIC_PICKAXES)) return true; + } + if (block instanceof AddMineableHoe) { + if (tool.is(ItemTags.HOES) || tool.is(ToolTags.FABRIC_HOES)) return true; + } + if (block instanceof AddMineableShovel) { + if (tool.is(ItemTags.SHOVELS) || tool.is(ToolTags.FABRIC_SHOVELS)) return true; + } + if (block instanceof AddMineableSword) { + if (tool.is(ItemTags.SWORDS) || tool.is(ToolTags.FABRIC_SWORDS)) return true; + } + if (block instanceof AddMineableShears) { + if (BaseShearsItem.isShear(tool)) return true; + } + if (block instanceof AddMineableHammer) { + if (tool.is(CommonItemTags.HAMMERS)) return true; + } + return false; + } }