Search in sources :

Example 1 with ToolPartGrip

use of net.silentchaos512.gems.api.tool.part.ToolPartGrip in project SilentGems by SilentChaos512.

the class RecipeDecorateTool method getCraftingResult.

@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
    int i;
    int toolRow = 0;
    int toolCol = 0;
    ItemStack stack;
    ItemStack tool = StackHelper.empty();
    int repairValue = 0;
    int ammoValue = 0;
    // Find tool position
    for (int row = 0; row < inv.getWidth(); ++row) {
        for (int col = 0; col < inv.getHeight(); ++col) {
            stack = inv.getStackInRowAndColumn(row, col);
            if (StackHelper.isValid(stack) && stack.getItem() instanceof ITool) {
                tool = stack;
                toolRow = row;
                toolCol = col;
            }
        }
    }
    // Found a tool?
    if (StackHelper.isEmpty(tool)) {
        return StackHelper.empty();
    }
    // Check adjacent materials
    ItemStack west = inv.getStackInRowAndColumn(toolRow - 1, toolCol);
    ItemStack north = inv.getStackInRowAndColumn(toolRow, toolCol - 1);
    ItemStack east = inv.getStackInRowAndColumn(toolRow + 1, toolCol);
    ItemStack south = inv.getStackInRowAndColumn(toolRow, toolCol + 1);
    if (!checkIsDecorationMaterial(west) || !checkIsDecorationMaterial(north) || !checkIsDecorationMaterial(east) || !checkIsDecorationMaterial(south)) {
        return StackHelper.empty();
    }
    // Check other materials and get all repair values.
    List<ItemStack> otherMats = Lists.newArrayList();
    EnumMaterialTier toolTier = ToolHelper.getToolTier(tool);
    for (i = 0; i < inv.getSizeInventory(); ++i) {
        stack = inv.getStackInSlot(i);
        if (StackHelper.isValid(stack) && !(stack.getItem() instanceof ITool)) {
            ToolPart part = ToolPartRegistry.fromStack(stack);
            // Invalid part or not a part?
            if (part == null) {
                return StackHelper.empty();
            }
            // Valid for tool tier?
            if (!part.validForToolOfTier(toolTier) && !(part instanceof ToolPartMain)) {
                return StackHelper.empty();
            }
            int repairAmount = part.getRepairAmount(tool, stack);
            if (repairAmount > 0) {
                repairValue += repairAmount;
                ++ammoValue;
            }
            otherMats.add(stack);
        }
    }
    ItemStack result = StackHelper.safeCopy(tool);
    result = ToolHelper.decorateTool(tool, west, north, east, south);
    // Other materials
    for (ItemStack other : otherMats) {
        ToolPart part = ToolPartRegistry.fromStack(other);
        EnumMaterialGrade grade = EnumMaterialGrade.fromStack(other);
        if (StackHelper.isValid(result) && part instanceof ToolPartRod) {
            ToolHelper.setRenderPart(result, part, grade, EnumPartPosition.ROD);
        } else if (part instanceof ToolPartGrip) {
            ToolHelper.setRenderPart(result, part, grade, EnumPartPosition.ROD_GRIP);
        } else if (part instanceof ToolPartTip) {
            ToolHelper.setRenderPart(result, part, grade, EnumPartPosition.TIP);
        }
    }
    repairValue += 1;
    // Tool repair multiplier
    repairValue *= ((ITool) tool.getItem()).getRepairMultiplier();
    // Repair.
    result.attemptDamageItem(-repairValue, SilentGems.instance.random);
    // Restore ammo.
    if (result.getItem() instanceof IAmmoTool && ammoValue > 0) {
        IAmmoTool ammoTool = (IAmmoTool) result.getItem();
        ammoTool.addAmmo(result, ammoValue * GemsConfig.TOMAHAWK_AMMO_PER_MAT);
    }
    // Recalculate stats.
    ToolHelper.recalculateStats(result);
    ToolHelper.incrementStatRedecorated(result, 1);
    return result;
}
Also used : ToolPartMain(net.silentchaos512.gems.api.tool.part.ToolPartMain) ToolPartTip(net.silentchaos512.gems.api.tool.part.ToolPartTip) ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) IAmmoTool(net.silentchaos512.gems.api.IAmmoTool) EnumMaterialGrade(net.silentchaos512.gems.api.lib.EnumMaterialGrade) EnumMaterialTier(net.silentchaos512.gems.api.lib.EnumMaterialTier) ItemStack(net.minecraft.item.ItemStack) ITool(net.silentchaos512.gems.api.ITool) ToolPartRod(net.silentchaos512.gems.api.tool.part.ToolPartRod) ToolPartGrip(net.silentchaos512.gems.api.tool.part.ToolPartGrip)

Aggregations

ItemStack (net.minecraft.item.ItemStack)1 IAmmoTool (net.silentchaos512.gems.api.IAmmoTool)1 ITool (net.silentchaos512.gems.api.ITool)1 EnumMaterialGrade (net.silentchaos512.gems.api.lib.EnumMaterialGrade)1 EnumMaterialTier (net.silentchaos512.gems.api.lib.EnumMaterialTier)1 ToolPart (net.silentchaos512.gems.api.tool.part.ToolPart)1 ToolPartGrip (net.silentchaos512.gems.api.tool.part.ToolPartGrip)1 ToolPartMain (net.silentchaos512.gems.api.tool.part.ToolPartMain)1 ToolPartRod (net.silentchaos512.gems.api.tool.part.ToolPartRod)1 ToolPartTip (net.silentchaos512.gems.api.tool.part.ToolPartTip)1