Search in sources :

Example 11 with ITool

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

the class RecipeMixedMaterialItem method getCraftingResult.

@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
    if (!partTiersMatch(inv)) {
        return StackHelper.empty();
    }
    ItemStack rod = getRod(inv);
    ItemStack frame = getFrame(inv);
    ItemStackList materials = getMaterials(inv);
    ItemStack[] array = materials.toArray(new ItemStack[materials.size()]);
    if (toolItem instanceof ITool)
        return ((ITool) toolItem).constructTool(rod, array);
    if (toolItem instanceof IArmor)
        return ((IArmor) toolItem).constructArmor(frame, array);
    return StackHelper.empty();
}
Also used : ItemStackList(net.silentchaos512.lib.collection.ItemStackList) ItemStack(net.minecraft.item.ItemStack) ITool(net.silentchaos512.gems.api.ITool) IArmor(net.silentchaos512.gems.api.IArmor)

Example 12 with ITool

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

the class SoulManager method getSoul.

@Nullable
public static ToolSoul getSoul(ItemStack tool) {
    if (StackHelper.isEmpty(tool) || !(tool.getItem() instanceof ITool || tool.getItem() instanceof IArmor) || ToolHelper.isExampleItem(tool)) {
        return null;
    }
    UUID uuid = ToolHelper.getSoulUUID(tool);
    // Soul already in map?
    ToolSoul soul = map.get(uuid);
    if (soul != null) {
        return soul;
    }
    // Does soul exist in NBT?
    ToolHelper.initRootTag(tool);
    if (!tool.getTagCompound().hasKey(ToolHelper.NBT_ROOT_TOOL_SOUL)) {
        return null;
    }
    // Read from NBT, place in map for fast access.
    soul = ToolSoul.readFromNBT(ToolHelper.getRootTag(tool, ToolHelper.NBT_ROOT_TOOL_SOUL));
    if (uuid == null) {
        ToolHelper.setRandomSoulUUID(tool);
        uuid = ToolHelper.getSoulUUID(tool);
    }
    map.put(uuid, soul);
    // SilentGems.logHelper.debug("Put tool soul " + soul + " in the map! Total count: " + map.size());
    return soul;
}
Also used : ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) UUID(java.util.UUID) ITool(net.silentchaos512.gems.api.ITool) IArmor(net.silentchaos512.gems.api.IArmor) Nullable(javax.annotation.Nullable)

Example 13 with ITool

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

the class ToolHelper method recalculateStats.

/**
 * Recalculate all stats and properties, including the rendering cache for the given tool. In general, this should be
 * called any time changes are made to a tool (aside from incrementing statistics, or something like that). For
 * example, this is called during construction, decoration, and for all tools in the players inventory during login.
 *
 * @param toolOrArmor
 */
public static void recalculateStats(ItemStack toolOrArmor) {
    // Make sure the item has a UUID!
    getUUID(toolOrArmor);
    ToolPart[] parts = getConstructionParts(toolOrArmor);
    if (parts.length == 0)
        return;
    // Clear old render cache
    clearOldRenderCache(toolOrArmor);
    if (!toolOrArmor.getTagCompound().getBoolean(NBT_LOCK_STATS)) {
        ToolStats stats = getStats(toolOrArmor, true);
        String root = NBT_ROOT_PROPERTIES;
        // Tools only
        if (toolOrArmor.getItem() instanceof ITool) {
            setTagFloat(toolOrArmor, root, NBT_PROP_HARVEST_SPEED, stats.harvestSpeed);
            setTagFloat(toolOrArmor, root, NBT_PROP_MELEE_DAMAGE, stats.meleeDamage);
            setTagFloat(toolOrArmor, root, NBT_PROP_MAGIC_DAMAGE, stats.magicDamage);
            setTagFloat(toolOrArmor, root, NBT_PROP_MELEE_SPEED, stats.meleeSpeed);
            setTagFloat(toolOrArmor, root, NBT_PROP_CHARGE_SPEED, stats.chargeSpeed);
            setTagInt(toolOrArmor, root, NBT_PROP_HARVEST_LEVEL, stats.harvestLevel);
        }
        // Tools and armor
        setTagInt(toolOrArmor, root, NBT_PROP_DURABILITY, (int) stats.durability);
        setTagFloat(toolOrArmor, root, NBT_PROP_PROTECTION, stats.protection);
        setTagInt(toolOrArmor, root, NBT_PROP_ENCHANTABILITY, (int) stats.enchantability);
        setTagInt(toolOrArmor, root, NBT_TOOL_TIER, parts[0].getTier().ordinal());
    }
}
Also used : ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) ToolStats(net.silentchaos512.gems.api.tool.ToolStats) ITool(net.silentchaos512.gems.api.ITool)

Example 14 with ITool

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

the class ToolHelper method addExampleRecipe.

public static void addExampleRecipe(Item item, EnumMaterialTier[] tiers, String[] lines, Object... extraParams) {
    // New ingredient-based recipes
    ConfigOptionToolClass config = item instanceof ITool ? ((ITool) item).getConfig() : null;
    for (EnumMaterialTier tier : tiers) {
        // Only add recipes for valid tiers
        if (config != null && !config.validTiers.contains(tier))
            continue;
        // Head parts for tier
        List<ItemStack> heads = new ArrayList<>();
        for (ToolPart part : ToolPartRegistry.getMains()) if (!part.isBlacklisted(part.getCraftingStack()) && part.getTier() == tier && StackHelper.isValid(part.getCraftingStack()))
            heads.add(part.getCraftingStack());
        IngredientSL headIngredient = IngredientSL.from(heads.toArray(new ItemStack[0]));
        // Rods for tier
        List<ItemStack> rods = new ArrayList<>();
        for (ToolPart part : ToolPartRegistry.getRods()) if (!part.isBlacklisted(part.getCraftingStack()) && part.getCompatibleTiers().contains(tier))
            rods.add(part.getCraftingStack());
        IngredientSL rodIngredient = IngredientSL.from(rods.toArray(new ItemStack[0]));
        // Armor frames
        List<ItemStack> frames = new ArrayList<>();
        if (item instanceof ItemGemArmor) {
            EntityEquipmentSlot slot = ((ItemGemArmor) item).armorType;
            for (ToolPart part : ToolPartRegistry.getValues()) if (part instanceof ArmorPartFrame && ((ArmorPartFrame) part).getSlot() == slot && part.getTier() == tier && !part.isBlacklisted(part.getCraftingStack()))
                frames.add(part.getCraftingStack());
        }
        IngredientSL frameIngredient = IngredientSL.from(frames.toArray(new ItemStack[0]));
        ResourceLocation recipeName = new ResourceLocation(item.getRegistryName().toString() + "_" + tier.name().toLowerCase() + "_example");
        ItemStack result = new ItemStack(item);
        NBTTagCompound tags = new NBTTagCompound();
        tags.setInteger(NBT_EXAMPLE_TOOL_TIER, tier.ordinal());
        result.setTagCompound(tags);
        // Super ugly, but I've got never better at the moment.
        List<Object> params = new ArrayList<>();
        for (String line : lines) params.add(line);
        if (recipeContainsKey(lines, "h")) {
            params.add('h');
            params.add(headIngredient);
        }
        if (recipeContainsKey(lines, "r")) {
            params.add('r');
            params.add(rodIngredient);
        }
        if (recipeContainsKey(lines, "a")) {
            params.add('a');
            params.add(frameIngredient);
        }
        for (Object obj : extraParams) params.add(obj);
        EXAMPLE_RECIPES.add(SilentGems.registry.recipes.makeShaped(recipeName.getResourcePath(), result, params.toArray()));
    }
}
Also used : IngredientSL(net.silentchaos512.lib.recipe.IngredientSL) EntityEquipmentSlot(net.minecraft.inventory.EntityEquipmentSlot) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ITool(net.silentchaos512.gems.api.ITool) ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) ResourceLocation(net.minecraft.util.ResourceLocation) ConfigOptionToolClass(net.silentchaos512.gems.config.ConfigOptionToolClass) EnumMaterialTier(net.silentchaos512.gems.api.lib.EnumMaterialTier) IRegistryObject(net.silentchaos512.lib.registry.IRegistryObject) ItemGemArmor(net.silentchaos512.gems.item.armor.ItemGemArmor) ItemStack(net.minecraft.item.ItemStack) ArmorPartFrame(net.silentchaos512.gems.api.tool.part.ArmorPartFrame)

Example 15 with ITool

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

the class ToolHelper method getSubItems.

public static List<ItemStack> getSubItems(Item item, int materialLength) {
    if (toolSubItems.containsKey(item)) {
        // Return cached list.
        return toolSubItems.get(item);
    }
    List<ItemStack> list = Lists.newArrayList();
    // final boolean isSuperTool = item instanceof ITool && ((ITool) item).isSuperTool();
    final ItemStack rodWood = new ItemStack(Items.STICK);
    final ItemStack rodIron = ModItems.craftingMaterial.toolRodIron;
    final ItemStack rodGold = ModItems.craftingMaterial.toolRodGold;
    for (ToolPartMain part : ToolPartRegistry.getMains()) {
        // Check for parts with empty crafting stacks and scream at the user if any are found.
        if (StackHelper.isEmpty(part.getCraftingStack())) {
            if (!emptyPartSet.contains(part)) {
                emptyPartSet.add(part);
                SilentGems.logHelper.severe("Part with empty crafting stack: " + part);
                if (!foundEmptyPart) {
                    Greetings.addExtraMessage(TextFormatting.RED + "Errored tool part found! Please report this issue on the GitHub issue tracker.");
                    foundEmptyPart = true;
                }
                Greetings.addExtraMessage(TextFormatting.ITALIC + part.toString());
            }
        } else {
            if (!part.isBlacklisted(part.getCraftingStack())) {
                if (item instanceof ITool && !((ITool) item).getValidTiers().contains(part.getTier())) {
                    continue;
                }
                ItemStack rod = part.getTier() == EnumMaterialTier.SUPER ? rodGold : item instanceof ItemGemShield && part.getTier() == EnumMaterialTier.REGULAR ? rodIron : rodWood;
                ItemStack tool = constructTool(item, rod, part.getCraftingStack());
                tool.getTagCompound().setBoolean(NBT_EXAMPLE_TOOL, true);
                list.add(tool);
            }
        }
    }
    // Set maker name.
    String makerName = SilentGems.localizationHelper.getMiscText("Tooltip.OriginalOwner.Creative");
    for (ItemStack stack : list) ToolHelper.setOriginalOwner(stack, makerName);
    // Save for later to prevent duplicates with different UUIDs.
    toolSubItems.put(item, list);
    return list;
}
Also used : ToolPartMain(net.silentchaos512.gems.api.tool.part.ToolPartMain) ItemGemShield(net.silentchaos512.gems.item.tool.ItemGemShield) ItemStack(net.minecraft.item.ItemStack) 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