Search in sources :

Example 16 with ITool

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

the class ToolHelper method getUUID.

/**
 * Gets the tool's or armor's UUID. If it currently does not have a UUID, one will be created if appropriate.
 *
 * @param tool
 *          The tool or armor stack. The stack's item must implement either ITool or IArmor.
 * @return The UUID of the tool or armor, or null if the item is not allowed to have one.
 */
@Nullable
public static UUID getUUID(ItemStack tool) {
    if (!(tool.getItem() instanceof ITool || tool.getItem() instanceof IArmor)) {
        return null;
    }
    initRootTag(tool);
    if (!tool.getTagCompound().hasUniqueId(NBT_UUID)) {
        UUID uuid = UUID.randomUUID();
        tool.getTagCompound().setUniqueId(NBT_UUID, uuid);
        return uuid;
    }
    return tool.getTagCompound().getUniqueId(NBT_UUID);
}
Also used : UUID(java.util.UUID) ITool(net.silentchaos512.gems.api.ITool) IArmor(net.silentchaos512.gems.api.IArmor) Nullable(javax.annotation.Nullable)

Example 17 with ITool

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

the class ToolRandomizer method randomizeArmor.

public ItemStack randomizeArmor(ItemStack armor, float superChance) {
    if (!ToolHelper.hasNoConstruction(armor))
        return armor;
    IArmor itool = (IArmor) armor.getItem();
    // Regular or super?
    boolean superTier = SilentGems.random.nextFloat() < superChance;
    // How many gems?
    boolean gem2 = SilentGems.random.nextFloat() < SECOND_GEM_CHANCE;
    boolean gem3 = gem2 && SilentGems.random.nextFloat() < THIRD_GEM_CHANCE;
    boolean gem4 = gem3 && SilentGems.random.nextFloat() < FOURTH_GEM_CHANCE;
    // Gem array
    EnumGem[] gems;
    if (gem4) {
        gems = new EnumGem[] { EnumGem.getRandom(), EnumGem.getRandom(), EnumGem.getRandom(), EnumGem.getRandom() };
    } else if (gem3) {
        EnumGem g1 = EnumGem.getRandom();
        gems = new EnumGem[] { g1, EnumGem.getRandom(), EnumGem.getRandom(), g1 };
    } else if (gem2) {
        EnumGem g1 = EnumGem.getRandom();
        EnumGem g2 = EnumGem.getRandom();
        gems = new EnumGem[] { g1, g2, g1, g2 };
    } else {
        EnumGem g1 = EnumGem.getRandom();
        gems = new EnumGem[] { g1, g1, g1, g1 };
    }
    // Crafting stack array
    ItemStack[] craftingStacks = new ItemStack[gems.length];
    for (int i = 0; i < craftingStacks.length; ++i) {
        craftingStacks[i] = superTier ? gems[i].getItemSuper() : gems[i].getItem();
    }
    ItemStack frame = ModItems.armorFrame.getFrameForArmorPiece((ItemArmor) armor.getItem(), superTier ? EnumMaterialTier.SUPER : EnumMaterialTier.REGULAR);
    ItemStack temp = ArmorHelper.constructArmor(armor.getItem(), frame, craftingStacks);
    // Set name
    String ownerName = nameAdjectives.get(SilentGems.random.nextInt(nameAdjectives.size())) + " " + nameNouns.get(SilentGems.random.nextInt(nameNouns.size()));
    ToolHelper.setOriginalOwner(temp, TextFormatting.AQUA + ownerName);
    armor.setTagCompound(temp.getTagCompound());
    return temp;
}
Also used : EnumGem(net.silentchaos512.gems.lib.EnumGem) ItemStack(net.minecraft.item.ItemStack) IArmor(net.silentchaos512.gems.api.IArmor)

Example 18 with ITool

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

the class ToolRandomizer method randomize.

public ItemStack randomize(ItemStack tool, float superChance) {
    if (tool.getItem() instanceof IArmor)
        return randomizeArmor(tool, superChance);
    if (!(tool.getItem() instanceof ITool) || !ToolHelper.hasNoConstruction(tool))
        return tool;
    ITool itool = (ITool) tool.getItem();
    // Regular or super?
    boolean superTier = !itool.getValidTiers().contains(EnumMaterialTier.REGULAR) || (SilentGems.random.nextFloat() < superChance && itool.getValidTiers().contains(EnumMaterialTier.SUPER));
    // How many gems?
    boolean gem2 = SilentGems.random.nextFloat() < SECOND_GEM_CHANCE;
    boolean gem3 = gem2 && SilentGems.random.nextFloat() < THIRD_GEM_CHANCE;
    // Gem array
    EnumGem[] gems;
    if (gem3) {
        // 3 gems
        gems = new EnumGem[] { EnumGem.getRandom(), EnumGem.getRandom(), EnumGem.getRandom() };
    } else if (gem2) {
        // 2 gems (3rd = 1st)
        EnumGem g1 = EnumGem.getRandom();
        EnumGem g2 = EnumGem.getRandom();
        if (tool.getItem() == ModItems.sword)
            gems = new EnumGem[] { g1, g2 };
        else
            gems = new EnumGem[] { g1, g2, g1 };
    } else {
        // 1 gem
        EnumGem g1 = EnumGem.getRandom();
        gems = new EnumGem[] { g1, g1, g1 };
    }
    // Crafting stack array
    ItemStack[] craftingStacks = new ItemStack[gems.length];
    for (int i = 0; i < craftingStacks.length; ++i) {
        craftingStacks[i] = superTier ? gems[i].getItemSuper() : gems[i].getItem();
    }
    // Select rod
    ItemStack rod;
    if (superTier) {
        ItemStack[] choices = new ItemStack[] { ModItems.craftingMaterial.toolRodGold, ModItems.craftingMaterial.toolRodSilver, ModItems.craftingMaterial.toolRodIron };
        rod = choices[SilentGems.random.nextInt(choices.length)];
    } else {
        ItemStack[] choices = new ItemStack[] { new ItemStack(Items.STICK), new ItemStack(Items.BONE), ModItems.craftingMaterial.toolRodIron };
        rod = choices[SilentGems.random.nextInt(choices.length)];
    }
    ItemStack temp = ToolHelper.constructTool(tool.getItem(), rod, craftingStacks);
    if (temp.getItem() instanceof ItemGemKatana)
        temp = ((ItemGemKatana) temp.getItem()).addDefaultGrip(temp);
    // Set name
    String ownerName = nameAdjectives.get(SilentGems.random.nextInt(nameAdjectives.size())) + " " + nameNouns.get(SilentGems.random.nextInt(nameNouns.size()));
    ToolHelper.setOriginalOwner(temp, TextFormatting.AQUA + ownerName);
    tool.setTagCompound(temp.getTagCompound());
    return temp;
}
Also used : EnumGem(net.silentchaos512.gems.lib.EnumGem) ItemStack(net.minecraft.item.ItemStack) IArmor(net.silentchaos512.gems.api.IArmor) ITool(net.silentchaos512.gems.api.ITool) ItemGemKatana(net.silentchaos512.gems.item.tool.ItemGemKatana)

Example 19 with ITool

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

the class ToolRenderHelper method updateModelCache.

@Override
public void updateModelCache(ItemStack toolOrArmor) {
    if (ToolHelper.hasUUID(toolOrArmor)) {
        UUID uuid = ToolHelper.getUUID(toolOrArmor);
        IModelData modelData = toolOrArmor.getItem() instanceof ITool ? new ToolModelData(toolOrArmor) : new ArmorModelData(toolOrArmor);
        if (ToolHelper.isExampleItem(toolOrArmor)) {
            modelCacheExamples.put(uuid, modelData);
        } else {
            modelCache.put(uuid, modelData);
        }
    }
}
Also used : ToolModelData(net.silentchaos512.gems.lib.client.ToolModelData) ArmorModelData(net.silentchaos512.gems.lib.client.ArmorModelData) UUID(java.util.UUID) ITool(net.silentchaos512.gems.api.ITool) IModelData(net.silentchaos512.gems.lib.client.IModelData)

Example 20 with ITool

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

the class ToolPartMain method getRepairAmount.

@Override
public int getRepairAmount(ItemStack toolOrArmor, ItemStack partRep) {
    if (isBlacklisted(partRep)) {
        return 0;
    }
    if (GemsConfigHC.REPAIR_LOGIC != GemsConfigHC.EnumRepairLogic.CLASSIC) {
        ToolPart repairPart = ToolPartRegistry.fromStack(partRep);
        EnumMaterialGrade repairGrade = EnumMaterialGrade.fromStack(partRep);
        float amount = repairPart.getDurability() * (100 + repairGrade.bonusPercent) / 100;
        // Since armor has much lower durability per item, we'll adjust down for armor.
        if (toolOrArmor.getItem() instanceof IArmor) {
            amount /= 2f;
        }
        switch(GemsConfigHC.REPAIR_LOGIC) {
            case HARD_MATERIAL_BASED:
                return (int) (amount / 4f);
            case MATERIAL_BASED:
                return (int) (amount / 2f);
            case NOT_ALLOWED:
                return 0;
            default:
                break;
        }
    }
    // Classic repair logic.
    int max = toolOrArmor.getMaxDamage();
    float scale = 0.0f;
    EnumMaterialTier partTier = getTier();
    EnumMaterialTier stackTier = toolOrArmor.getItem() instanceof ITool ? ToolHelper.getToolTier(toolOrArmor) : (toolOrArmor.getItem() instanceof IArmor ? ArmorHelper.getArmorTier(toolOrArmor) : null);
    if (stackTier == null)
        return 0;
    int toolTierIndex = ToolHelper.getToolTier(toolOrArmor).ordinal();
    int partTierIndex = partTier.ordinal();
    scale = REPAIR_VALUES[toolTierIndex][partTierIndex];
    return (int) (scale * max);
}
Also used : EnumMaterialGrade(net.silentchaos512.gems.api.lib.EnumMaterialGrade) EnumMaterialTier(net.silentchaos512.gems.api.lib.EnumMaterialTier) IArmor(net.silentchaos512.gems.api.IArmor) ITool(net.silentchaos512.gems.api.ITool)

Aggregations

ITool (net.silentchaos512.gems.api.ITool)21 ItemStack (net.minecraft.item.ItemStack)14 IArmor (net.silentchaos512.gems.api.IArmor)11 EnumMaterialTier (net.silentchaos512.gems.api.lib.EnumMaterialTier)5 ToolPart (net.silentchaos512.gems.api.tool.part.ToolPart)5 EnumMaterialGrade (net.silentchaos512.gems.api.lib.EnumMaterialGrade)4 ToolSoul (net.silentchaos512.gems.lib.soul.ToolSoul)4 ArrayList (java.util.ArrayList)3 UUID (java.util.UUID)3 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)3 Nullable (javax.annotation.Nullable)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 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Random (java.util.Random)1 Entity (net.minecraft.entity.Entity)1