Search in sources :

Example 1 with ITool

use of net.silentchaos512.gems.api.ITool in project SilentGems by SilentChaos512.

the class ActionAddMixedMaterialRecipe method apply.

@Override
public void apply() {
    // Add the real recipe.
    IRecipe irecipe = new RecipeMixedMaterialItem(tier, toolItem, recipe);
    irecipe.setRegistryName(new ResourceLocation("crafttweaker", calculateName()));
    ForgeRegistries.RECIPES.register(irecipe);
    // Also add example recipes.
    List<EnumMaterialTier> tiers = new ArrayList<>();
    if (tier == null) {
        for (EnumMaterialTier t : EnumMaterialTier.values()) {
            tiers.add(t);
        }
    } else {
        tiers.add(tier);
    }
    List<String> recipeLines = new ArrayList<>();
    int index = 0;
    while (index < recipe.length && recipe[index] instanceof String) {
        recipeLines.add((String) recipe[index++]);
    }
    List<Object> extraParams = new ArrayList<>();
    for (; index < recipe.length; ++index) {
        extraParams.add(recipe[index]);
    }
    EnumMaterialTier[] arrayTiers = tiers.toArray(new EnumMaterialTier[tiers.size()]);
    String[] arrayLines = recipeLines.toArray(new String[recipeLines.size()]);
    Object[] arrayExtraParams = extraParams.toArray();
    if (toolItem instanceof ITool)
        ToolHelper.addExampleRecipe(toolItem, arrayTiers, arrayLines, arrayExtraParams);
}
Also used : RecipeMixedMaterialItem(net.silentchaos512.gems.recipe.RecipeMixedMaterialItem) IRecipe(net.minecraft.item.crafting.IRecipe) ArrayList(java.util.ArrayList) ITool(net.silentchaos512.gems.api.ITool) ResourceLocation(net.minecraft.util.ResourceLocation) EnumMaterialTier(net.silentchaos512.gems.api.lib.EnumMaterialTier)

Example 2 with ITool

use of net.silentchaos512.gems.api.ITool in project SilentGems by SilentChaos512.

the class RecipeApplyToolSoul method getCraftingResult.

@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
    ItemStack tool = StackHelper.empty();
    ItemStack soul = StackHelper.empty();
    for (int i = 0; i < inv.getSizeInventory(); ++i) {
        ItemStack stack = inv.getStackInSlot(i);
        // Found a tool or armor piece?
        if (stack.getItem() instanceof ITool || stack.getItem() instanceof IArmor) {
            if (StackHelper.isValid(tool)) {
                return StackHelper.empty();
            }
            tool = stack;
        } else // Found a soul?
        if (stack.getItem() instanceof ItemToolSoul) {
            if (StackHelper.isValid(soul)) {
                return StackHelper.empty();
            }
            soul = stack;
        }
    }
    if (StackHelper.isEmpty(tool) || StackHelper.isEmpty(soul)) {
        return StackHelper.empty();
    }
    // Does tool already have a soul?
    if (SoulManager.getSoul(tool) != null) {
        return StackHelper.empty();
    }
    // Is the soul valid?
    ToolSoul toolSoul = ModItems.toolSoul.getSoul(soul);
    if (toolSoul == null) {
        return StackHelper.empty();
    }
    ItemStack result = StackHelper.safeCopy(tool);
    // Have to change UUID to prevent soul duping.
    // result.getTagCompound().removeTag(ToolHelper.NBT_UUID);
    SoulManager.setSoul(result, toolSoul, true);
    // Apply name, if applicable.
    if (soul.hasDisplayName()) {
        String name = soul.getDisplayName();
        toolSoul.setName(name);
        result.setStackDisplayName(name);
    }
    // Recalculate stats and return.
    ToolHelper.recalculateStats(result);
    return result;
}
Also used : ItemToolSoul(net.silentchaos512.gems.item.ItemToolSoul) ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) ItemToolSoul(net.silentchaos512.gems.item.ItemToolSoul) ItemStack(net.minecraft.item.ItemStack) ITool(net.silentchaos512.gems.api.ITool) IArmor(net.silentchaos512.gems.api.IArmor)

Example 3 with ITool

use of net.silentchaos512.gems.api.ITool in project SilentGems by SilentChaos512.

the class SoulManager method writeToolSoulsToNBT.

public static void writeToolSoulsToNBT(EntityPlayer player) {
    // Find all the players tools. Find the matching souls in the map.
    int count = 0;
    for (ItemStack tool : PlayerHelper.getNonEmptyStacks(player, true, true, true, s -> s.getItem() instanceof ITool || s.getItem() instanceof IArmor)) {
        // UUID uuid = getSoulUUID(tool);
        // ToolSoul soul = toolSoulMap.get(uuid);
        ToolSoul soul = getSoul(tool);
        if (soul != null) {
            setSoul(tool, soul, false);
            ++count;
        }
    }
// SilentGems.logHelper.debug("Saved " + count + " tool(s) for " + player.getName());
}
Also used : ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) ItemStack(net.minecraft.item.ItemStack) ITool(net.silentchaos512.gems.api.ITool) IArmor(net.silentchaos512.gems.api.IArmor)

Example 4 with ITool

use of net.silentchaos512.gems.api.ITool in project SilentGems by SilentChaos512.

the class SoulSkill method selectSkillToLearn.

public static SoulSkill selectSkillToLearn(ToolSoul soul, ItemStack tool) {
    // if (soul.getLevel() == 5) {
    // return SUPER_SKILL;
    // }
    Map<SoulSkill, Double> candidates = new LinkedHashMap<>();
    // Create list of candidates
    for (SoulSkill skill : SKILL_LIST.values()) {
        if (skill.canLearn(soul, tool)) {
            boolean favorsElement = false;
            // Select a weight based on favored elements.
            double weight = skill.favoredElements.length < 1 ? 20 : 7;
            for (EnumSoulElement elem : skill.favoredElements) {
                if (elem == soul.getPrimaryElement()) {
                    weight = 20;
                    favorsElement = true;
                    break;
                } else if (elem == soul.getSecondaryElement()) {
                    weight = 15;
                    favorsElement = true;
                    break;
                }
            }
            // Favors certain tool types?
            if (skill.favoredType != EnumToolType.NONE) {
                EnumToolType toolType = tool.getItem() instanceof ITool ? ((ITool) tool.getItem()).getToolType() : tool.getItem() instanceof IArmor ? ((IArmor) tool.getItem()).getToolType() : EnumToolType.NONE;
                if (toolType == skill.favoredType) {
                    weight += 5;
                }
            }
            // If skill has a median level, apply that to the weight.
            if (skill.medianXpLevel > 0) {
                int diff = Math.abs(soul.level - skill.medianXpLevel);
                if (diff > 6) {
                    diff = 6;
                }
                weight -= 0.75 * diff;
            }
            // If a lower level of the skill is already known, reduce the weight.
            if (soul.skills.containsKey(skill)) {
                weight -= 2.5 * soul.skills.get(skill);
            }
            // Base weight diff, favors multiplier
            weight += skill.weightDiff;
            if (favorsElement) {
                weight *= skill.favorWeightMulti;
            }
            // Make sure weight is at least 1.
            if (weight < 1) {
                weight = 1;
            }
            candidates.put(skill, weight);
        }
    }
    // Seed based on soul elements, level, and tool UUID.
    Random rand = new Random(soul.getPrimaryElement().ordinal() + (soul.getSecondaryElement().ordinal() << 4) + (soul.getLevel() << 8) + (ToolHelper.getUUID(tool).getLeastSignificantBits() << 16));
    // Weighted random selection.
    SoulSkill selected = null;
    double bestValue = Double.MIN_VALUE;
    for (SoulSkill skill : candidates.keySet()) {
        double value = -Math.log(rand.nextFloat() / candidates.get(skill));
        SilentGems.logHelper.debug(skill.id, candidates.get(skill), value, bestValue);
        if (value > bestValue) {
            bestValue = value;
            selected = skill;
        }
    }
    return selected;
}
Also used : Random(java.util.Random) EnumToolType(net.silentchaos512.gems.lib.EnumToolType) EnumSoulElement(net.silentchaos512.gems.lib.soul.EnumSoulElement) ITool(net.silentchaos512.gems.api.ITool) IArmor(net.silentchaos512.gems.api.IArmor) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with ITool

use of net.silentchaos512.gems.api.ITool in project SilentGems by SilentChaos512.

the class ToolStats method calculate.

public ToolStats calculate() {
    if (parts.length == 0)
        return this;
    Set<ToolPart> uniqueParts = Sets.newConcurrentHashSet();
    // Head (main) parts
    for (int i = 0; i < parts.length; ++i) {
        ToolPart part = parts[i];
        EnumMaterialGrade grade = grades[i];
        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;
        blockingPower += part.getProtection() / 16f * 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);
    // Average head parts
    durability = bonus * durability / parts.length;
    harvestSpeed = bonus * harvestSpeed / parts.length;
    meleeDamage = bonus * meleeDamage / parts.length;
    magicDamage = bonus * magicDamage / parts.length;
    meleeSpeed = bonus * meleeSpeed / parts.length;
    chargeSpeed = bonus * chargeSpeed / parts.length;
    enchantability = bonus * enchantability / parts.length;
    blockingPower = Math.max(bonus * blockingPower / parts.length, ItemGemShield.MIN_BLOCKING_POWER);
    // Tool class multipliers
    if (tool.getItem() instanceof ITool) {
        ITool itool = (ITool) tool.getItem();
        durability *= itool.getDurabilityMultiplier();
        harvestSpeed *= itool.getHarvestSpeedMultiplier();
    }
    // Rod, tip, grip
    ToolPart partRod = ToolHelper.getConstructionRod(tool);
    ToolPart partTip = ToolHelper.getConstructionTip(tool);
    ToolPart partGrip = ToolHelper.getPart(tool, EnumPartPosition.ROD_GRIP);
    for (ToolPart part : Lists.newArrayList(partRod, partTip, partGrip)) {
        if (part != null) {
            part.applyStats(this);
        }
    }
    return this;
}
Also used : ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) EnumMaterialGrade(net.silentchaos512.gems.api.lib.EnumMaterialGrade) ITool(net.silentchaos512.gems.api.ITool)

Aggregations

ITool (net.silentchaos512.gems.api.ITool)22 ItemStack (net.minecraft.item.ItemStack)16 IArmor (net.silentchaos512.gems.api.IArmor)11 EnumMaterialTier (net.silentchaos512.gems.api.lib.EnumMaterialTier)5 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)4 ToolPart (net.silentchaos512.gems.api.tool.part.ToolPart)4 ToolSoul (net.silentchaos512.gems.lib.soul.ToolSoul)4 UUID (java.util.UUID)3 EnumMaterialGrade (net.silentchaos512.gems.api.lib.EnumMaterialGrade)3 ArrayList (java.util.ArrayList)2 Nullable (javax.annotation.Nullable)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 Item (net.minecraft.item.Item)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 ToolPartMain (net.silentchaos512.gems.api.tool.part.ToolPartMain)2 EnumGem (net.silentchaos512.gems.lib.EnumGem)2 LinkedHashMap (java.util.LinkedHashMap)1 Random (java.util.Random)1 Entity (net.minecraft.entity.Entity)1