Search in sources :

Example 16 with ToolPart

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

the class TileMaterialGrader method isItemValidForSlot.

@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
    if (index == SLOT_INPUT) {
        if (StackHelper.isEmpty(stack)) {
            return false;
        }
        ToolPart part = ToolPartRegistry.fromStack(stack);
        EnumMaterialGrade grade = EnumMaterialGrade.fromStack(stack);
        if (part != null && part instanceof ToolPartMain && grade == EnumMaterialGrade.NONE) {
            return true;
        }
        return false;
    }
    return false;
}
Also used : ToolPartMain(net.silentchaos512.gems.api.tool.part.ToolPartMain) ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) EnumMaterialGrade(net.silentchaos512.gems.api.lib.EnumMaterialGrade)

Example 17 with ToolPart

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

the class TileMaterialGrader method update.

@Override
public void update() {
    if (world.isRemote)
        return;
    ItemStack input = getStackInSlot(SLOT_INPUT);
    ToolPart part = ToolPartRegistry.fromStack(input);
    // Is input (if anything) a grade-able part?
    if (part != null && part instanceof ToolPartMain && EnumMaterialGrade.fromStack(input) == EnumMaterialGrade.NONE) {
        // Analyze, using chaos if possible
        boolean useChaos = chaosStored >= CHAOS_PER_TICK;
        // Analyzing material.
        if (progress < BASE_ANALYZE_TIME) {
            if (useChaos) {
                chaosStored -= CHAOS_PER_TICK;
            }
            progress += useChaos ? ANALYZE_SPEED_WITH_CHAOS : ANALYZE_SPEED_NO_CHAOS;
            requireClientSync = true;
        }
        // Grade material if any output slot is free.
        int outputSlot = getFreeOutputSlot();
        if (progress >= BASE_ANALYZE_TIME && outputSlot > 0) {
            progress = 0;
            // Take one from input stack.
            ItemStack stack = StackHelper.safeCopy(input);
            StackHelper.setCount(stack, 1);
            StackHelper.shrink(input, 1);
            // Assign random grade.
            EnumMaterialGrade.selectRandom(SilentGems.random).setGradeOnStack(stack);
            // Set to output slot, clear input slot if needed.
            setInventorySlotContents(outputSlot, stack);
            if (StackHelper.getCount(input) <= 0) {
                setInventorySlotContents(SLOT_INPUT, StackHelper.empty());
            }
            requireClientSync = true;
        }
    } else {
        progress = 0;
    }
    // Send update to client?
    if (requireClientSync) {
        IBlockState state = world.getBlockState(pos);
        world.notifyBlockUpdate(pos, state, state, 3);
        requireClientSync = false;
    }
}
Also used : ToolPartMain(net.silentchaos512.gems.api.tool.part.ToolPartMain) ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack)

Example 18 with ToolPart

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

the class ArmorHelper method decorate.

private static ItemStack decorate(ItemStack armor, ItemStack material, ArmorPartPosition pos) {
    if (StackHelper.isEmpty(armor))
        return StackHelper.empty();
    if (StackHelper.isEmpty(material))
        return armor;
    ToolPart part = ToolPartRegistry.fromDecoStack(material);
    if (part == null)
        return null;
    // Only main parts (like gems) work
    if (!(part instanceof ToolPartMain))
        return armor;
    ItemStack result = StackHelper.safeCopy(armor);
    setTagPart(result, pos.getDecoKey(), part, EnumMaterialGrade.fromStack(material));
    return result;
}
Also used : ToolPartMain(net.silentchaos512.gems.api.tool.part.ToolPartMain) ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) ItemStack(net.minecraft.item.ItemStack)

Example 19 with ToolPart

use of net.silentchaos512.gems.api.tool.part.ToolPart 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 20 with ToolPart

use of net.silentchaos512.gems.api.tool.part.ToolPart 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)

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