Skip to content

Commit 7e8c850

Browse files
committed
restore tool getMaterialCost intended functionality
1 parent 55cb180 commit 7e8c850

1 file changed

Lines changed: 29 additions & 10 deletions

File tree

src/main/java/baritone/utils/ToolSet.java

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@
2020
import baritone.Baritone;
2121
import net.minecraft.client.player.LocalPlayer;
2222
import net.minecraft.core.Holder;
23-
import net.minecraft.core.component.DataComponents;
23+
import net.minecraft.tags.ItemTags;
24+
import net.minecraft.tags.TagKey;
2425
import net.minecraft.world.effect.MobEffects;
2526
import net.minecraft.world.entity.ai.attributes.Attributes;
27+
import net.minecraft.world.item.Item;
2628
import net.minecraft.world.item.ItemStack;
2729
import net.minecraft.world.item.SwordItem;
28-
import net.minecraft.world.item.component.Tool;
29-
import net.minecraft.world.item.enchantment.*;
30+
import net.minecraft.world.item.enchantment.Enchantment;
31+
import net.minecraft.world.item.enchantment.EnchantmentEffectComponents;
32+
import net.minecraft.world.item.enchantment.Enchantments;
33+
import net.minecraft.world.item.enchantment.ItemEnchantments;
3034
import net.minecraft.world.item.enchantment.effects.EnchantmentAttributeEffect;
3135
import net.minecraft.world.level.block.Block;
3236
import net.minecraft.world.level.block.state.BlockState;
@@ -56,6 +60,20 @@ public class ToolSet {
5660

5761
private final LocalPlayer player;
5862

63+
/**
64+
* Used for evaluating the material cost of a tool.
65+
* see {@link #getMaterialCost(ItemStack)}
66+
* Prefer tools with lower material cost (lower index in this list).
67+
*/
68+
private static final List<TagKey<Item>> materialTagsPriorityList = List.of(
69+
ItemTags.WOODEN_TOOL_MATERIALS,
70+
ItemTags.STONE_TOOL_MATERIALS,
71+
ItemTags.IRON_TOOL_MATERIALS,
72+
ItemTags.GOLD_TOOL_MATERIALS,
73+
ItemTags.DIAMOND_TOOL_MATERIALS,
74+
ItemTags.NETHERITE_TOOL_MATERIALS
75+
);
76+
5977
public ToolSet(LocalPlayer player) {
6078
breakStrengthCache = new HashMap<>();
6179
this.player = player;
@@ -80,17 +98,18 @@ public double getStrVsBlock(BlockState state) {
8098
}
8199

82100
/**
83-
* Evaluate the material cost of a possible tool. The priority matches the
84-
* harvest level order; there is a chance for multiple at the same with modded tools
85-
* but in that case we don't really care.
86-
*
101+
* Evaluate the material cost of a possible tool.
102+
* If all else is equal, we want to prefer the tool with the lowest material cost.
103+
* i.e. we want to prefer a wooden pickaxe over a stone pickaxe, if all else is equal.
87104
* @param itemStack a possibly empty ItemStack
88105
* @return values from 0 up
89106
*/
90107
private int getMaterialCost(ItemStack itemStack) {
91-
Tool toolComponent = itemStack.get(DataComponents.TOOL);
92-
if (toolComponent == null) return -1;
93-
return toolComponent.damagePerBlock(); // todo: i have no idea what "material cost" means anymore
108+
for (int i = 0; i < materialTagsPriorityList.size(); i++) {
109+
final TagKey<Item> tag = materialTagsPriorityList.get(i);
110+
if (itemStack.is(tag)) return i;
111+
}
112+
return -1;
94113
}
95114

96115
public boolean hasSilkTouch(ItemStack stack) {

0 commit comments

Comments
 (0)