Search in sources :

Example 76 with ItemSword

use of net.minecraft.item.ItemSword in project Spark-Client by Spark-Client-Development.

the class ToolSet method getBestSlot.

public int getBestSlot(Block b, boolean preferSilkTouch, boolean pathingCalculation) {
    /*
        If we actually want know what efficiency our held item has instead of the best one
        possible, this lets us make pathing depend on the actual tool to be used (if auto tool is disabled)
        */
    if (Baritone.settings().disableAutoTool.getValue() && pathingCalculation) {
        return player.inventory.currentItem;
    }
    int best = 0;
    double highestSpeed = Double.NEGATIVE_INFINITY;
    int lowestCost = Integer.MIN_VALUE;
    boolean bestSilkTouch = false;
    IBlockState blockState = b.getDefaultState();
    for (int i = 0; i < 9; i++) {
        ItemStack itemStack = player.inventory.getStackInSlot(i);
        if (!Baritone.settings().useSwordToMine.getValue() && itemStack.getItem() instanceof ItemSword) {
            continue;
        }
        if (Baritone.settings().itemSaver.getValue() && itemStack.getItemDamage() >= itemStack.getMaxDamage() && itemStack.getMaxDamage() > 1) {
            continue;
        }
        double speed = calculateSpeedVsBlock(itemStack, blockState);
        boolean silkTouch = hasSilkTouch(itemStack);
        if (speed > highestSpeed) {
            highestSpeed = speed;
            best = i;
            lowestCost = getMaterialCost(itemStack);
            bestSilkTouch = silkTouch;
        } else if (speed == highestSpeed) {
            int cost = getMaterialCost(itemStack);
            if ((cost < lowestCost && (silkTouch || !bestSilkTouch)) || (preferSilkTouch && !bestSilkTouch && silkTouch)) {
                highestSpeed = speed;
                best = i;
                lowestCost = cost;
                bestSilkTouch = silkTouch;
            }
        }
    }
    return best;
}
Also used : ItemSword(net.minecraft.item.ItemSword) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemSword (net.minecraft.item.ItemSword)76 ItemStack (net.minecraft.item.ItemStack)53 Item (net.minecraft.item.Item)25 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)23 EntityPlayer (net.minecraft.entity.player.EntityPlayer)22 ItemTool (net.minecraft.item.ItemTool)21 ItemHoe (net.minecraft.item.ItemHoe)18 IBlockState (net.minecraft.block.state.IBlockState)17 ItemBow (net.minecraft.item.ItemBow)15 Entity (net.minecraft.entity.Entity)13 Block (net.minecraft.block.Block)9 EntityLivingBase (net.minecraft.entity.EntityLivingBase)8 ItemAxe (net.minecraft.item.ItemAxe)8 ItemBlock (net.minecraft.item.ItemBlock)8 World (net.minecraft.world.World)7 ItemArmor (net.minecraft.item.ItemArmor)6 ItemFishingRod (net.minecraft.item.ItemFishingRod)6 DamageSource (net.minecraft.util.DamageSource)6 ItemDoor (net.minecraft.item.ItemDoor)5 ItemShield (net.minecraft.item.ItemShield)5