restore tool getMaterialCost intended functionality

This commit is contained in:
rfresh2
2024-10-30 17:49:03 -07:00
parent 55cb180755
commit 7e8c8501a7

View File

@@ -20,13 +20,17 @@ package baritone.utils;
import baritone.Baritone;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponents;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.component.Tool;
import net.minecraft.world.item.enchantment.*;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentEffectComponents;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.item.enchantment.ItemEnchantments;
import net.minecraft.world.item.enchantment.effects.EnchantmentAttributeEffect;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
@@ -56,6 +60,20 @@ public class ToolSet {
private final LocalPlayer player;
/**
* Used for evaluating the material cost of a tool.
* see {@link #getMaterialCost(ItemStack)}
* Prefer tools with lower material cost (lower index in this list).
*/
private static final List<TagKey<Item>> materialTagsPriorityList = List.of(
ItemTags.WOODEN_TOOL_MATERIALS,
ItemTags.STONE_TOOL_MATERIALS,
ItemTags.IRON_TOOL_MATERIALS,
ItemTags.GOLD_TOOL_MATERIALS,
ItemTags.DIAMOND_TOOL_MATERIALS,
ItemTags.NETHERITE_TOOL_MATERIALS
);
public ToolSet(LocalPlayer player) {
breakStrengthCache = new HashMap<>();
this.player = player;
@@ -80,17 +98,18 @@ public class ToolSet {
}
/**
* Evaluate the material cost of a possible tool. The priority matches the
* harvest level order; there is a chance for multiple at the same with modded tools
* but in that case we don't really care.
*
* Evaluate the material cost of a possible tool.
* If all else is equal, we want to prefer the tool with the lowest material cost.
* i.e. we want to prefer a wooden pickaxe over a stone pickaxe, if all else is equal.
* @param itemStack a possibly empty ItemStack
* @return values from 0 up
*/
private int getMaterialCost(ItemStack itemStack) {
Tool toolComponent = itemStack.get(DataComponents.TOOL);
if (toolComponent == null) return -1;
return toolComponent.damagePerBlock(); // todo: i have no idea what "material cost" means anymore
for (int i = 0; i < materialTagsPriorityList.size(); i++) {
final TagKey<Item> tag = materialTagsPriorityList.get(i);
if (itemStack.is(tag)) return i;
}
return -1;
}
public boolean hasSilkTouch(ItemStack stack) {