Search in sources :

Example 1 with ItemHoldingGem

use of net.silentchaos512.gems.item.ItemHoldingGem in project SilentGems by SilentChaos512.

the class RecipeHoldingGemSetBlock method getCraftingResult.

@SuppressWarnings("deprecation")
@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
    ItemStack holdingGem = StackHelper.empty();
    ItemStack blockStack = StackHelper.empty();
    ItemStack stack;
    for (int i = 0; i < inv.getSizeInventory(); ++i) {
        stack = inv.getStackInSlot(i);
        if (StackHelper.isValid(stack)) {
            if (stack.getItem() instanceof ItemHoldingGem) {
                if (StackHelper.isValid(holdingGem) || stack.getItemDamage() < stack.getMaxDamage())
                    return StackHelper.empty();
                holdingGem = stack;
            } else if (stack.getItem() instanceof ItemBlock) {
                if (StackHelper.isValid(blockStack))
                    return StackHelper.empty();
                blockStack = stack;
            }
        }
    }
    if (StackHelper.isEmpty(holdingGem) || StackHelper.isEmpty(blockStack))
        return StackHelper.empty();
    ItemStack result = StackHelper.safeCopy(holdingGem);
    Block block = ((ItemBlock) blockStack.getItem()).block;
    int meta = blockStack.getItemDamage();
    IBlockState state = block.getStateFromMeta(meta);
    ((ItemHoldingGem) result.getItem()).setBlockPlaced(result, state);
    result.setItemDamage(result.getMaxDamage() - 1);
    return result;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock) ItemHoldingGem(net.silentchaos512.gems.item.ItemHoldingGem)

Example 2 with ItemHoldingGem

use of net.silentchaos512.gems.item.ItemHoldingGem in project SilentGems by SilentChaos512.

the class RecipeHoldingGemSetBlock method matches.

@Override
public boolean matches(InventoryCrafting inv, World world) {
    int countGem = 0;
    int countBlock = 0;
    for (ItemStack stack : getNonEmptyStacks(inv)) {
        // Empty holding gem
        Item item = stack.getItem();
        if (item instanceof ItemHoldingGem && ((ItemBlockPlacer) item).getRemainingBlocks(stack) == 0)
            ++countGem;
        else // Block item
        if (item instanceof ItemBlock)
            ++countBlock;
        else
            return false;
    }
    return countGem == 1 && countBlock == 1;
}
Also used : ItemBlockPlacer(net.silentchaos512.gems.item.ItemBlockPlacer) Item(net.minecraft.item.Item) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock) ItemHoldingGem(net.silentchaos512.gems.item.ItemHoldingGem)

Aggregations

ItemBlock (net.minecraft.item.ItemBlock)2 ItemStack (net.minecraft.item.ItemStack)2 ItemHoldingGem (net.silentchaos512.gems.item.ItemHoldingGem)2 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 Item (net.minecraft.item.Item)1 ItemBlockPlacer (net.silentchaos512.gems.item.ItemBlockPlacer)1