Search in sources :

Example 11 with ToolPart

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

the class ItemGemArmor method clAddInformation.

@Override
public void clAddInformation(ItemStack stack, World world, List<String> list, boolean advanced) {
    LocalizationHelper loc = SilentGems.localizationHelper;
    ToolRenderHelper helper = ToolRenderHelper.getInstance();
    boolean controlDown = KeyTracker.isControlDown();
    boolean shiftDown = KeyTracker.isShiftDown();
    boolean altDown = KeyTracker.isAltDown();
    String line;
    // UUID
    if (GemsConfig.DEBUG_MODE && controlDown && shiftDown) {
        UUID uuid = ToolHelper.hasUUID(stack) ? ToolHelper.getUUID(stack) : null;
        list.add(uuid == null ? "No UUID" : uuid.toString());
        uuid = ToolHelper.getSoulUUID(stack);
        list.add(uuid == null ? "No Soul UUID" : uuid.toString());
    }
    // Tool Soul
    ToolSoul soul = SoulManager.getSoul(stack);
    if (soul != null) {
        soul.addInformation(stack, world, list, advanced);
    }
    // Show original owner?
    if (controlDown) {
        String owner = ArmorHelper.getOriginalOwner(stack);
        if (!owner.isEmpty()) {
            list.add(loc.getMiscText("Tooltip.OriginalOwner", owner));
        } else {
            list.add(loc.getMiscText("Tooltip.OriginalOwner.Unknown"));
        }
    }
    // TODO: Remove me
    if (altDown) {
        list.add(TextFormatting.RED + "Armor models WIP.");
    }
    // Broken?
    if (ArmorHelper.isBroken(stack)) {
        list.add(loc.getMiscText("Tooltip.Broken"));
    }
    final String sep = loc.getMiscText("Tooltip.Separator");
    if (controlDown) {
        // Properties header
        list.add(loc.getMiscText("Tooltip.Properties"));
        TextFormatting color = TextFormatting.YELLOW;
        float durabilityBoost = ToolSoul.getDurabilityModifierForDisplay(soul);
        list.add(color + helper.getTooltipLine("Durability", getMaxDamage(stack), durabilityBoost));
        float protectionBoost = ToolSoul.getProtectionModifierForDisplay(soul);
        list.add(color + helper.getTooltipLine("Protection", getProtection(stack), protectionBoost));
        // Statistics Header
        list.add(sep);
        list.add(loc.getMiscText("Tooltip.Statistics"));
        list.add(helper.getTooltipLine("DamageTaken", ArmorHelper.getStatDamageTaken(stack), 0f));
        list.add(helper.getTooltipLine("Redecorated", ArmorHelper.getStatRedecorated(stack), 0f));
        list.add(sep);
    } else {
        list.add(TextFormatting.GOLD + loc.getMiscText("PressCtrl"));
    }
    if (altDown) {
        list.add(loc.getMiscText("Tooltip.Construction"));
        ToolPart[] parts = ArmorHelper.getConstructionParts(stack);
        EnumMaterialGrade[] grades = ArmorHelper.getConstructionGrades(stack);
        for (int i = 0; i < parts.length; ++i) {
            ToolPart part = parts[i];
            EnumMaterialGrade grade = grades[i];
            line = "  " + TextFormatting.YELLOW + part.getKey() + TextFormatting.GOLD + " (" + grade + ")";
            list.add(line);
        }
        ToolPart partFrame = ArmorHelper.getPart(stack, ArmorPartPosition.FRAME);
        if (partFrame != null)
            list.add("  " + TextFormatting.YELLOW + partFrame.getKey());
        list.add(sep);
    } else {
        list.add(TextFormatting.GOLD + loc.getMiscText("PressAlt"));
    }
}
Also used : ToolRenderHelper(net.silentchaos512.gems.item.ToolRenderHelper) LocalizationHelper(net.silentchaos512.lib.util.LocalizationHelper) ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) EnumMaterialGrade(net.silentchaos512.gems.api.lib.EnumMaterialGrade) TextFormatting(net.minecraft.util.text.TextFormatting) UUID(java.util.UUID)

Example 12 with ToolPart

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

the class ToolStats method calculate.

public ToolStats calculate() {
    if (parts.length == 0)
        return this;
    Map<ItemStat, List<ItemStatModifier>> mods = new HashMap<>();
    for (ItemStat stat : ItemStat.ALL_STATS) {
        mods.put(stat, new ArrayList<>());
    }
    Set<ToolPart> uniqueParts = Sets.newConcurrentHashSet();
    // Head (main) parts
    for (int i = 0; i < parts.length; ++i) {
        ToolPart part = parts[i];
        EnumMaterialGrade grade = grades[i];
        for (ItemStat stat : ItemStat.ALL_STATS) {
            ItemStatModifier statModifier = part.getStatModifier(stat, grade);
            if (statModifier != null) {
                mods.get(stat).add(statModifier);
            }
        }
        // float multi = (100 + grade.bonusPercent) / 100f;
        // durability += part.getDurability() * multi;
        // harvestSpeed += part.getHarvestSpeed() * multi;
        // meleeDamage += part.getMeleeDamage() * multi;
        // magicDamage += part.getMagicDamage() * multi;
        // meleeSpeed += part.getMeleeSpeed() * multi;
        // enchantability += part.getEnchantability() * multi;
        // chargeSpeed += part.getChargeSpeed() * multi;
        // protection += part.getProtection() * multi;
        // harvestLevel = Math.max(harvestLevel, part.getHarvestLevel());
        uniqueParts.add(part);
    }
    // Variety bonus
    int variety = MathHelper.clamp(uniqueParts.size(), 1, GemsConfig.VARIETY_CAP);
    float bonus = 1.0f + GemsConfig.VARIETY_BONUS * (variety - 1);
    mods.get(CommonItemStats.DURABILITY).add(new ItemStatModifier(ID_VARIETY_BONUS, bonus, Operation.MULTIPLY));
    mods.get(CommonItemStats.HARVEST_SPEED).add(new ItemStatModifier(ID_VARIETY_BONUS, bonus, Operation.MULTIPLY));
    mods.get(CommonItemStats.MELEE_DAMAGE).add(new ItemStatModifier(ID_VARIETY_BONUS, bonus, Operation.MULTIPLY));
    mods.get(CommonItemStats.MAGIC_DAMAGE).add(new ItemStatModifier(ID_VARIETY_BONUS, bonus, Operation.MULTIPLY));
    mods.get(CommonItemStats.ATTACK_SPEED).add(new ItemStatModifier(ID_VARIETY_BONUS, bonus, Operation.MULTIPLY));
    mods.get(CommonItemStats.CHARGE_SPEED).add(new ItemStatModifier(ID_VARIETY_BONUS, bonus, Operation.MULTIPLY));
    mods.get(CommonItemStats.ENCHANTABILITY).add(new ItemStatModifier(ID_VARIETY_BONUS, bonus, Operation.MULTIPLY));
    mods.get(CommonItemStats.ARMOR).add(new ItemStatModifier(ID_VARIETY_BONUS, bonus, Operation.MULTIPLY));
    mods.get(CommonItemStats.MAGIC_ARMOR).add(new ItemStatModifier(ID_VARIETY_BONUS, bonus, Operation.MULTIPLY));
    // Tool class multipliers
    if (tool.getItem() instanceof ITool) {
        ITool itool = (ITool) tool.getItem();
        durability *= itool.getDurabilityMultiplier();
        harvestSpeed *= itool.getHarvestSpeedMultiplier();
    }
    // Rod, tip, grip, frame
    ToolPart partRod = ToolHelper.getConstructionRod(tool);
    ToolPart partTip = ToolHelper.getConstructionTip(tool);
    ToolPart partGrip = ToolHelper.getPart(tool, ToolPartPosition.ROD_GRIP);
    ToolPart partFrame = ArmorHelper.getPart(tool, ArmorPartPosition.FRAME);
    for (ToolPart part : Lists.newArrayList(partRod, partTip, partGrip, partFrame)) {
        if (part != null) {
            for (ItemStat stat : ItemStat.ALL_STATS) {
                ItemStatModifier statModifier = part.getStatModifier(stat, EnumMaterialGrade.NONE);
                if (statModifier != null) {
                    mods.get(stat).add(statModifier);
                }
            }
        }
    }
    durability = calcStat(CommonItemStats.DURABILITY, mods);
    harvestSpeed = calcStat(CommonItemStats.HARVEST_SPEED, mods);
    meleeDamage = calcStat(CommonItemStats.MELEE_DAMAGE, mods);
    magicDamage = calcStat(CommonItemStats.MAGIC_DAMAGE, mods);
    meleeSpeed = calcStat(CommonItemStats.ATTACK_SPEED, mods);
    chargeSpeed = calcStat(CommonItemStats.CHARGE_SPEED, mods);
    enchantability = calcStat(CommonItemStats.ENCHANTABILITY, mods);
    protection = calcStat(CommonItemStats.ARMOR, mods);
    harvestLevel = (int) calcStat(CommonItemStats.HARVEST_LEVEL, mods);
    return this;
}
Also used : ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) HashMap(java.util.HashMap) EnumMaterialGrade(net.silentchaos512.gems.api.lib.EnumMaterialGrade) ItemStatModifier(net.silentchaos512.gems.api.stats.ItemStatModifier) ArrayList(java.util.ArrayList) List(java.util.List) ITool(net.silentchaos512.gems.api.ITool) ItemStat(net.silentchaos512.gems.api.stats.ItemStat)

Example 13 with ToolPart

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

the class ItemTipUpgrade method applyToTool.

public ItemStack applyToTool(ItemStack tool, ItemStack upgrade) {
    ToolPart part = ToolPartRegistry.fromStack(upgrade);
    if (part == null) {
        return null;
    }
    ItemStack result = StackHelper.safeCopy(tool);
    ToolHelper.setConstructionTip(result, part);
    ToolHelper.recalculateStats(result);
    return result;
}
Also used : ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) ItemStack(net.minecraft.item.ItemStack)

Example 14 with ToolPart

use of net.silentchaos512.gems.api.tool.part.ToolPart 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.fromDecoStack(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);
        }
    }
    if (otherMats.isEmpty()) {
        return StackHelper.empty();
    }
    ItemStack result = StackHelper.safeCopy(tool);
    result = ToolHelper.decorateTool(tool, west, north, east, south);
    boolean lockedStats = result.getTagCompound().getBoolean(ToolHelper.NBT_LOCK_STATS);
    // Other materials
    for (ItemStack other : otherMats) {
        ToolPart part = ToolPartRegistry.fromDecoStack(other);
        EnumMaterialGrade grade = EnumMaterialGrade.fromStack(other);
        if (StackHelper.isValid(result) && part instanceof ToolPartRod) {
            ToolHelper.setRenderPart(result, part, grade, ToolPartPosition.ROD);
        } else if (part instanceof ToolPartTip) {
            if (lockedStats) {
                // Tips change stats, so using them with locked tools is not allowed.
                return StackHelper.empty();
            }
            ToolHelper.setConstructionTip(result, part);
        }
    }
    if (repairValue > 0) {
        // Makes odd repair values line up better (2 polished stone on pickaxe makes a full repair, etc.)
        repairValue += 1;
    }
    // Tool repair multiplier
    repairValue *= ((ITool) tool.getItem()).getRepairMultiplier();
    // Repair.
    ItemHelper.attemptDamageItem(result, -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);
    // Change the UUID so that rendering cache updates immediately for recipe output.
    result.getTagCompound().removeTag(ToolHelper.NBT_UUID + "Most");
    result.getTagCompound().removeTag(ToolHelper.NBT_UUID + "Least");
    ToolHelper.getUUID(result);
    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)

Example 15 with ToolPart

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

the class RecipeMixedMaterialItem method partTiersMatch.

protected boolean partTiersMatch(InventoryCrafting inv) {
    EnumMaterialTier tier = null;
    // Check mains
    for (ItemStack stack : getMaterials(inv)) {
        ToolPart part = ToolPartRegistry.fromStack(stack);
        if (tier == null) {
            tier = part.getTier();
        } else if (tier != part.getTier()) {
            return false;
        }
    }
    // No mains found?
    if (tier == null) {
        return false;
    }
    // Tier restrictions?
    if (tierRestriction != null && tier != tierRestriction) {
        return false;
    }
    // Check rod
    ItemStack rod = getRod(inv);
    if (StackHelper.isValid(rod))
        return ToolPartRegistry.fromStack(rod).validForToolOfTier(tier);
    // Check frame
    ItemStack frame = getFrame(inv);
    if (StackHelper.isValid(frame)) {
        ToolPart partFrame = ToolPartRegistry.fromStack(frame);
        if (partFrame instanceof ArmorPartFrame) {
            return partFrame.validForToolOfTier(tier) && doesFrameMatchItem((ArmorPartFrame) partFrame);
        }
    }
    return true;
}
Also used : ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) EnumMaterialTier(net.silentchaos512.gems.api.lib.EnumMaterialTier) ItemStack(net.minecraft.item.ItemStack) ArmorPartFrame(net.silentchaos512.gems.api.tool.part.ArmorPartFrame)

Aggregations

ToolPart (net.silentchaos512.gems.api.tool.part.ToolPart)22 ItemStack (net.minecraft.item.ItemStack)16 EnumMaterialGrade (net.silentchaos512.gems.api.lib.EnumMaterialGrade)10 EnumMaterialTier (net.silentchaos512.gems.api.lib.EnumMaterialTier)9 ToolPartMain (net.silentchaos512.gems.api.tool.part.ToolPartMain)8 ITool (net.silentchaos512.gems.api.ITool)6 TextFormatting (net.minecraft.util.text.TextFormatting)4 ToolPartRod (net.silentchaos512.gems.api.tool.part.ToolPartRod)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 ToolStats (net.silentchaos512.gems.api.tool.ToolStats)3 ArmorPartFrame (net.silentchaos512.gems.api.tool.part.ArmorPartFrame)3 ItemGemBow (net.silentchaos512.gems.item.tool.ItemGemBow)3 ToolSoul (net.silentchaos512.gems.lib.soul.ToolSoul)3 LocalizationHelper (net.silentchaos512.lib.util.LocalizationHelper)3 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)2 Item (net.minecraft.item.Item)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 IArmor (net.silentchaos512.gems.api.IArmor)2