Search in sources :

Example 1 with IToolType

use of com.minecolonies.api.util.constant.IToolType in project minecolonies by Minecolonies.

the class AbstractEntityAIBasic method requestTool.

/**
 * Request the appropriate tool for this block.
 *
 * @param target the block to mine
 * @param pos the pos to mine
 */
private void requestTool(@NotNull final Block target, final BlockPos pos) {
    final IToolType toolType = WorkerUtil.getBestToolForBlock(target);
    final int required = WorkerUtil.getCorrectHavestLevelForBlock(target);
    if (getOwnBuilding().getMaxToolLevel() < required) {
        chatSpamFilter.talkWithoutSpam(BUILDING_LEVEL_TOO_LOW, new ItemStack(target).getDisplayName(), pos.toString());
    }
    updateToolFlag(toolType, required);
}
Also used : IToolType(com.minecolonies.api.util.constant.IToolType) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IToolType

use of com.minecolonies.api.util.constant.IToolType in project minecolonies by Minecolonies.

the class AbstractEntityAIBasic method getMostEfficientTool.

/**
 * Calculates the most efficient tool to use
 * on that block.
 *
 * @param target the Block type to mine
 * @return the slot with the best tool
 */
private int getMostEfficientTool(@NotNull final Block target) {
    final IToolType toolType = WorkerUtil.getBestToolForBlock(target);
    final int required = WorkerUtil.getCorrectHavestLevelForBlock(target);
    int bestSlot = -1;
    int bestLevel = Integer.MAX_VALUE;
    @NotNull final InventoryCitizen inventory = worker.getInventoryCitizen();
    final int maxToolLevel = worker.getWorkBuilding().getMaxToolLevel();
    for (int i = 0; i < new InvWrapper(worker.getInventoryCitizen()).getSlots(); i++) {
        final ItemStack item = inventory.getStackInSlot(i);
        final int level = ItemStackUtils.getMiningLevel(item, toolType);
        if (level >= required && level < bestLevel && (toolType == ToolType.NONE || ItemStackUtils.verifyToolLevel(item, level, required, maxToolLevel))) {
            bestSlot = i;
            bestLevel = level;
        }
    }
    return bestSlot;
}
Also used : IToolType(com.minecolonies.api.util.constant.IToolType) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) InventoryCitizen(com.minecolonies.coremod.inventory.InventoryCitizen) ItemStack(net.minecraft.item.ItemStack) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with IToolType

use of com.minecolonies.api.util.constant.IToolType in project minecolonies by Minecolonies.

the class Tool method deserialize.

/**
 * Static method that constructs an instance from NBT.
 *
 * @param controller The {@link IFactoryController} to deserialize components with.
 * @param nbt        The nbt to serialize from.
 * @return An instance of Tool with the data contained in the given NBT.
 */
@NotNull
public static Tool deserialize(final IFactoryController controller, final NBTTagCompound nbt) {
    // API:Map the given strings a proper way.
    final IToolType type = ToolType.getToolType(nbt.getString(NBT_TYPE));
    final Integer minLevel = nbt.getInteger(NBT_MIN_LEVEL);
    final Integer maxLevel = nbt.getInteger(NBT_MAX_LEVEL);
    final ItemStack result = new ItemStack(nbt.getCompoundTag(NBT_RESULT));
    return new Tool(type, minLevel, maxLevel, result);
}
Also used : IToolType(com.minecolonies.api.util.constant.IToolType) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

IToolType (com.minecolonies.api.util.constant.IToolType)3 ItemStack (net.minecraft.item.ItemStack)2 NotNull (org.jetbrains.annotations.NotNull)2 InventoryCitizen (com.minecolonies.coremod.inventory.InventoryCitizen)1 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)1