Search in sources :

Example 1 with EnumMaterialTier

use of net.silentchaos512.gems.api.lib.EnumMaterialTier 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 EnumMaterialTier

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

the class CTSilentGems method setToolRecipe.

@ZenMethod
public static void setToolRecipe(String itemClass, int tierRestriction, String[] recipe, Object... ingredients) {
    Item toolItem = Item.getByNameOrId(SilentGems.RESOURCE_PREFIX + itemClass.toLowerCase());
    EnumMaterialTier tier = null;
    if (tierRestriction >= 0 && tierRestriction < EnumMaterialTier.values().length) {
        tier = EnumMaterialTier.values()[tierRestriction];
    }
    Object[] params = new Object[recipe.length + ingredients.length];
    for (int i = 0; i < recipe.length; ++i) {
        params[i] = recipe[i];
    }
    for (int i = 0; i < ingredients.length; ++i) {
        if (ingredients[i] instanceof String) {
            String str = (String) ingredients[i];
            if (str.length() == 1) {
                // Character?
                params[recipe.length + i] = str.charAt(0);
            } else if (str.startsWith("ore:")) {
                // Oredict key?
                params[recipe.length + i] = str.replaceFirst("ore:", "");
            } else {
                // Item string?
                // We can't use CraftTweaker's typical ingredient annotation (<mod:item_name:meta>) because it doesn't yield
                // any values I can use. :(
                String[] array = str.split(":");
                String itemName = array[0] + ":" + array[1];
                Item item = Item.getByNameOrId(itemName);
                if (item != null) {
                    int meta = 0;
                    if (array.length > 2) {
                        try {
                            meta = Integer.parseInt(array[2]);
                        } catch (NumberFormatException ex) {
                        // Ignore
                        }
                    }
                    params[recipe.length + i] = new ItemStack(item, 1, meta);
                }
            }
        } else {
            // Nothing else will work, I assume? But pass it along anyway.
            params[recipe.length + i] = ingredients[i];
        }
    }
    ActionAddMixedMaterialRecipe action = new ActionAddMixedMaterialRecipe(toolItem, tier, params);
    MCRecipeManager.recipesToAdd.add(action);
// RECIPES_TO_ADD.add(action);
}
Also used : Item(net.minecraft.item.Item) EnumMaterialTier(net.silentchaos512.gems.api.lib.EnumMaterialTier) ItemStack(net.minecraft.item.ItemStack) ZenMethod(stanhebben.zenscript.annotations.ZenMethod)

Example 3 with EnumMaterialTier

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

the class ItemGemArmor method getMaxDamage.

@Override
public int getMaxDamage(ItemStack stack) {
    EnumMaterialTier tier = ToolHelper.getToolTier(stack);
    int x = ArmorHelper.getMaxDamage(stack);
    float y = (1.8f * x + 1515) / 131;
    float z = tier != null ? y * (tier.ordinal() + 1f) / 2f : y;
    return (int) (MAX_DAMAGE_ARRAY[armorType.getIndex()] * z);
}
Also used : EnumMaterialTier(net.silentchaos512.gems.api.lib.EnumMaterialTier)

Example 4 with EnumMaterialTier

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

the class RecipeMultiGemArmor method getCraftingResult.

@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
    // Get the middle stack, which determines the armor type.
    ItemStack centerStack = inv.getStackInRowAndColumn(1, 1);
    if (StackHelper.isEmpty(centerStack) || !(centerStack.getItem() instanceof ItemArmorFrame)) {
        return StackHelper.empty();
    }
    // Make sure nothing is in the corners.
    if (StackHelper.isValid(inv.getStackInRowAndColumn(0, 0)) || StackHelper.isValid(inv.getStackInRowAndColumn(2, 0)) || StackHelper.isValid(inv.getStackInRowAndColumn(2, 2)) || StackHelper.isValid(inv.getStackInRowAndColumn(0, 2))) {
        return StackHelper.empty();
    }
    // Determine the target tier and output item.
    ItemArmorFrame item = (ItemArmorFrame) centerStack.getItem();
    Item outputItem = item.getOutputItem(centerStack);
    EnumMaterialTier targetTier = item.getTier(centerStack);
    // Get armor parts. Check tiers match (getGems checks all materials are same tier, or it returns null).
    ItemStack[] stacks = getGems(inv);
    if (stacks == null || EnumMaterialTier.fromStack(stacks[0]) != targetTier)
        return StackHelper.empty();
    return ArmorHelper.constructArmor(outputItem, stacks);
}
Also used : Item(net.minecraft.item.Item) EnumMaterialTier(net.silentchaos512.gems.api.lib.EnumMaterialTier) ItemStack(net.minecraft.item.ItemStack) ItemArmorFrame(net.silentchaos512.gems.item.armor.ItemArmorFrame)

Example 5 with EnumMaterialTier

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

the class RecipeMultiGemArmor method getGems.

public ItemStack[] getGems(InventoryCrafting inv) {
    // Get materials from slots.
    ItemStack[] stacks = new ItemStack[4];
    // West
    stacks[0] = inv.getStackInRowAndColumn(0, 1);
    // North
    stacks[1] = inv.getStackInRowAndColumn(1, 0);
    // East
    stacks[2] = inv.getStackInRowAndColumn(2, 1);
    // South
    stacks[3] = inv.getStackInRowAndColumn(1, 2);
    // Make sure all are same tier and parts aren't blacklisted.
    ToolPart part;
    EnumMaterialTier tier = EnumMaterialTier.fromStack(stacks[0]);
    for (int i = 1; i < stacks.length; ++i) {
        part = ToolPartRegistry.fromStack(stacks[i]);
        if (tier == null || part == null || part.isBlacklisted(stacks[i]) || part.getTier() != tier) {
            return null;
        }
    }
    return stacks;
}
Also used : ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) EnumMaterialTier(net.silentchaos512.gems.api.lib.EnumMaterialTier) ItemStack(net.minecraft.item.ItemStack)

Aggregations

EnumMaterialTier (net.silentchaos512.gems.api.lib.EnumMaterialTier)23 ItemStack (net.minecraft.item.ItemStack)12 ToolPart (net.silentchaos512.gems.api.tool.part.ToolPart)12 ITool (net.silentchaos512.gems.api.ITool)5 EnumMaterialGrade (net.silentchaos512.gems.api.lib.EnumMaterialGrade)5 Item (net.minecraft.item.Item)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 TextFormatting (net.minecraft.util.text.TextFormatting)3 ToolPartMain (net.silentchaos512.gems.api.tool.part.ToolPartMain)3 ToolPartTip (net.silentchaos512.gems.api.tool.part.ToolPartTip)3 ArrayList (java.util.ArrayList)2 ItemTool (net.minecraft.item.ItemTool)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 IArmor (net.silentchaos512.gems.api.IArmor)2 ArmorPartFrame (net.silentchaos512.gems.api.tool.part.ArmorPartFrame)2 ToolPartRod (net.silentchaos512.gems.api.tool.part.ToolPartRod)2 ItemGemAxe (net.silentchaos512.gems.item.tool.ItemGemAxe)2 ItemGemBow (net.silentchaos512.gems.item.tool.ItemGemBow)2 ItemGemHoe (net.silentchaos512.gems.item.tool.ItemGemHoe)2 ItemGemShield (net.silentchaos512.gems.item.tool.ItemGemShield)2