Search in sources :

Example 11 with ToolPartMain

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

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

the class ArmorHelper method decorate.

private static ItemStack decorate(ItemStack armor, ItemStack material, EnumDecoPos pos) {
    if (StackHelper.isEmpty(armor))
        return StackHelper.empty();
    if (StackHelper.isEmpty(material))
        return armor;
    ToolPart part = ToolPartRegistry.fromStack(material);
    if (part == null)
        return null;
    // Only main parts (like gems) work
    if (!(part instanceof ToolPartMain))
        return armor;
    ItemStack result = StackHelper.safeCopy(armor);
    switch(pos) {
        case WEST:
            setTagPart(result, NBT_DECO_WEST, part, EnumMaterialGrade.fromStack(material));
            break;
        case NORTH:
            setTagPart(result, NBT_DECO_NORTH, part, EnumMaterialGrade.fromStack(material));
            break;
        case EAST:
            setTagPart(result, NBT_DECO_EAST, part, EnumMaterialGrade.fromStack(material));
            break;
        case SOUTH:
            setTagPart(result, NBT_DECO_SOUTH, part, EnumMaterialGrade.fromStack(material));
            break;
        default:
            SilentGems.instance.logHelper.warning("ArmorHelper.decorate: invalid deco pos " + pos);
            break;
    }
    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 13 with ToolPartMain

use of net.silentchaos512.gems.api.tool.part.ToolPartMain 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, if we have enough energy.
        if (chaosStored >= CHAOS_PER_TICK) {
            // Analyzing material.
            if (progress < ANALYZE_TIME) {
                chaosStored -= CHAOS_PER_TICK;
                ++progress;
                requireClientSync = true;
            }
            // Grade material if any output slot is free.
            int outputSlot = getFreeOutputSlot();
            if (progress >= 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)

Aggregations

ToolPartMain (net.silentchaos512.gems.api.tool.part.ToolPartMain)13 ItemStack (net.minecraft.item.ItemStack)12 ToolPart (net.silentchaos512.gems.api.tool.part.ToolPart)11 ToolPartRod (net.silentchaos512.gems.api.tool.part.ToolPartRod)4 EnumMaterialTier (net.silentchaos512.gems.api.lib.EnumMaterialTier)3 ITool (net.silentchaos512.gems.api.ITool)2 EnumMaterialGrade (net.silentchaos512.gems.api.lib.EnumMaterialGrade)2 ItemGemShield (net.silentchaos512.gems.item.tool.ItemGemShield)2 IBlockState (net.minecraft.block.state.IBlockState)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 IAmmoTool (net.silentchaos512.gems.api.IAmmoTool)1 IArmor (net.silentchaos512.gems.api.IArmor)1 ToolPartGrip (net.silentchaos512.gems.api.tool.part.ToolPartGrip)1 ToolPartTip (net.silentchaos512.gems.api.tool.part.ToolPartTip)1 ItemStackList (net.silentchaos512.lib.collection.ItemStackList)1