Search in sources :

Example 6 with ToolPart

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

the class ArmorHelper method constructArmor.

public static ItemStack constructArmor(Item item, ItemStack frame, ItemStack... materials) {
    // Shortcut for JEI recipes.
    if (materials.length == 1) {
        ItemStack[] newMats = new ItemStack[4];
        for (int i = 0; i < newMats.length; ++i) newMats[i] = materials[0];
        materials = newMats;
    }
    ItemStack result = new ItemStack(item);
    result.setTagCompound(new NBTTagCompound());
    result.getTagCompound().setTag(ToolHelper.NBT_TEMP_PARTLIST, new NBTTagCompound());
    // Construction
    ToolPart part;
    EnumMaterialGrade grade;
    for (int i = 0; i < materials.length; ++i) {
        if (StackHelper.isEmpty(materials[i])) {
            String str = "ArmorHelper.constructArmor: empty part! ";
            for (ItemStack stack : materials) str += stack + ", ";
            throw new IllegalArgumentException(str);
        }
        part = ToolPartRegistry.fromStack(materials[i]);
        grade = EnumMaterialGrade.fromStack(materials[i]);
        setTagPart(result, "Part" + i, part, grade);
        // Write part list for client-side name generation.
        result.getTagCompound().getCompoundTag(ToolHelper.NBT_TEMP_PARTLIST).setTag("part" + i, materials[i].writeToNBT(new NBTTagCompound()));
    }
    // Frame
    part = ToolPartRegistry.fromStack(frame);
    if (part != null) {
        setTagPart(result, ArmorPartPosition.FRAME.getKey(0), part, EnumMaterialGrade.NONE);
    }
    // Create name
    String displayName = ToolHelper.createToolName(item, materials);
    result.setStackDisplayName(displayName);
    recalculateStats(result);
    return result;
}
Also used : ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) EnumMaterialGrade(net.silentchaos512.gems.api.lib.EnumMaterialGrade) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 7 with ToolPart

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

the class ToolHelper method createToolName.

public static String createToolName(Item item, List<ItemStack> materials) {
    ToolPart part;
    LocalizationHelper loc = SilentGems.localizationHelper;
    Set<String> prefixSet = Sets.newLinkedHashSet();
    Set<String> materialSet = Sets.newLinkedHashSet();
    for (ItemStack stack : materials) {
        part = ToolPartRegistry.fromStack(stack);
        if (part != null) {
            String prefix = part.getDisplayNamePrefix(stack);
            if (prefix != null && !prefix.isEmpty())
                prefixSet.add(prefix);
            materialSet.add(part.getDisplayName(stack));
        }
    }
    String prefix = String.join(" ", prefixSet);
    if (!prefix.isEmpty())
        prefix += " ";
    String delimiter = loc.getLocalizedString("tool.silentgems:delimiter");
    String materialName = String.join(delimiter, materialSet);
    String toolName = ((IRegistryObject) item).getName();
    String name = loc.getLocalizedString("tool", toolName, materialName);
    return prefix + name;
}
Also used : ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) IRegistryObject(net.silentchaos512.lib.registry.IRegistryObject) ItemStack(net.minecraft.item.ItemStack) LocalizationHelper(net.silentchaos512.lib.util.LocalizationHelper)

Example 8 with ToolPart

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

the class ToolHelper method constructTool.

public static ItemStack constructTool(Item item, ItemStack rod, ItemStack... materials) {
    if (materials.length == 1) {
        ItemStack[] newMats = new ItemStack[3];
        for (int i = 0; i < newMats.length; ++i) newMats[i] = materials[0];
        materials = newMats;
    }
    ItemStack result = new ItemStack(item);
    result.setTagCompound(new NBTTagCompound());
    result.getTagCompound().setTag(NBT_TEMP_PARTLIST, new NBTTagCompound());
    // Set construction materials
    ToolPart part;
    // Head
    for (int i = 0; i < materials.length; ++i) {
        if (StackHelper.isEmpty(materials[i])) {
            String str = "ToolHelper.constructTool: empty part! ";
            for (ItemStack stack : materials) str += stack + ", ";
            throw new IllegalArgumentException(str);
        }
        part = ToolPartRegistry.fromStack(materials[i]);
        EnumMaterialGrade grade = EnumMaterialGrade.fromStack(materials[i]);
        setTagPart(result, ToolPartPosition.HEAD.getKey(i), part, grade);
        // Write part list for client-side name generation.
        result.getTagCompound().getCompoundTag(NBT_TEMP_PARTLIST).setTag("part" + i, materials[i].writeToNBT(new NBTTagCompound()));
    }
    // Rod
    part = ToolPartRegistry.fromStack(rod);
    if (part == null) {
        return StackHelper.empty();
    }
    setTagPart(result, ToolPartPosition.ROD.getKey(0), part, EnumMaterialGrade.NONE);
    // Create name
    String displayName = createToolName(item, materials);
    result.setStackDisplayName(displayName);
    recalculateStats(result);
    // Is this tier valid for this tool class?
    EnumMaterialTier toolTier = getToolTier(result);
    if (item instanceof ITool && !((ITool) item).getValidTiers().contains(toolTier)) {
        return StackHelper.empty();
    }
    return result;
}
Also used : ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) EnumMaterialGrade(net.silentchaos512.gems.api.lib.EnumMaterialGrade) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EnumMaterialTier(net.silentchaos512.gems.api.lib.EnumMaterialTier) ItemStack(net.minecraft.item.ItemStack) ITool(net.silentchaos512.gems.api.ITool)

Example 9 with ToolPart

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

the class ToolHelper method getConstructionParts.

public static ToolPart[] getConstructionParts(ItemStack tool) {
    if (StackHelper.isEmpty(tool))
        return new ToolPart[] {};
    List<ToolPart> parts = Lists.newArrayList();
    int index = -1;
    String key;
    ToolPart part;
    do {
        key = getPartId(tool, ToolPartPosition.HEAD.getKey(++index));
        if (key != null) {
            part = ToolPartRegistry.getPart(key);
            if (part != null)
                parts.add(part);
        }
    } while (key != null && !key.isEmpty());
    return parts.toArray(new ToolPart[parts.size()]);
}
Also used : ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart)

Example 10 with ToolPart

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

the class ToolHelper method getStats.

public static ToolStats getStats(ItemStack toolOrArmor, boolean applySoulModifiers) {
    ToolPart[] parts = getConstructionParts(toolOrArmor);
    EnumMaterialGrade[] grades = getConstructionGrades(toolOrArmor);
    if (parts.length == 0)
        return new ToolStats(toolOrArmor);
    ToolStats stats = new ToolStats(toolOrArmor, parts, grades);
    if (toolOrArmor.getTagCompound().getBoolean(NBT_LOCK_STATS)) {
        // TODO: Is this right?
        stats.chargeSpeed = getChargeSpeed(toolOrArmor);
        stats.durability = getMaxDamage(toolOrArmor);
        stats.enchantability = getItemEnchantability(toolOrArmor);
        stats.harvestLevel = getHarvestLevel(toolOrArmor);
        stats.harvestSpeed = getDigSpeedOnProperMaterial(toolOrArmor);
        stats.magicDamage = getMagicDamage(toolOrArmor);
        stats.meleeDamage = getMeleeDamage(toolOrArmor);
        stats.meleeSpeed = getMeleeSpeed(toolOrArmor);
        stats.protection = getProtection(toolOrArmor);
        return stats;
    }
    stats.calculate();
    if (applySoulModifiers) {
        ToolSoul soul = SoulManager.getSoul(toolOrArmor);
        if (soul != null) {
            soul.applyToStats(stats);
        }
    }
    return stats;
}
Also used : ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) EnumMaterialGrade(net.silentchaos512.gems.api.lib.EnumMaterialGrade) ToolStats(net.silentchaos512.gems.api.tool.ToolStats)

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