Search in sources :

Example 21 with ItemStack

use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.

the class RecipeInputEnchantedBook method matches.

@Override
public boolean matches(ItemStack stack) {
    if (validEnchantments == null) {
        validEnchantments = new HashSet<Enchantment>();
        ItemStack[] items = { new ItemStack(BetterStorageItems.cardboardHelmet), new ItemStack(BetterStorageItems.cardboardChestplate), new ItemStack(BetterStorageItems.cardboardLeggings), new ItemStack(BetterStorageItems.cardboardBoots), new ItemStack(BetterStorageItems.cardboardSword), new ItemStack(BetterStorageItems.cardboardPickaxe), new ItemStack(BetterStorageItems.cardboardShovel), new ItemStack(BetterStorageItems.cardboardAxe), new ItemStack(BetterStorageItems.cardboardHoe) };
        for (Enchantment ench : Enchantment.enchantmentsList) {
            if ((ench == null) || !ench.isAllowedOnBooks())
                continue;
            for (ItemStack item : items) if (item.getItem() != null && ench.canApply(item)) {
                validEnchantments.add(ench);
                break;
            }
        }
    }
    if (stack.getItem() instanceof ItemEnchantedBook) {
        Map<Integer, Integer> enchants = EnchantmentHelper.getEnchantments(stack);
        for (Enchantment ench : validEnchantments) if (enchants.containsKey(ench.effectId))
            return true;
    }
    return false;
}
Also used : Enchantment(net.minecraft.enchantment.Enchantment) ItemStack(net.minecraft.item.ItemStack) ItemEnchantedBook(net.minecraft.item.ItemEnchantedBook)

Example 22 with ItemStack

use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.

the class InventoryCrateBlockView method setInventorySlotContents.

@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
    access();
    if ((slot < 0) || (slot >= getSizeInventory()))
        return;
    ItemStack oldStack = null;
    if (slot > 0) {
        oldStack = originalStacks[slot - 1];
        exposedStacks[slot - 1] = stack;
        originalStacks[slot - 1] = ItemStack.copyItemStack(stack);
    }
    isModifying = true;
    if (oldStack != null) {
        // If the two stacks match, just add/remove the difference.
        if (StackUtils.matches(oldStack, stack)) {
            int count = stack.stackSize - oldStack.stackSize;
            if (count > 0)
                data.addItems(StackUtils.copyStack(stack, count));
            else if (count < 0)
                data.removeItems(StackUtils.copyStack(stack, -count));
            isModifying = false;
            return;
        }
        data.removeItems(oldStack);
    }
    data.addItems(stack);
    isModifying = false;
}
Also used : ItemStack(net.minecraft.item.ItemStack)

Example 23 with ItemStack

use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.

the class InventoryCratePlayerView method decrStackSize.

@Override
public ItemStack decrStackSize(int slot, int amount) {
    ItemStack stack = getStackInSlot(slot);
    if (stack == null)
        return null;
    amount = Math.min(amount, stack.stackSize);
    ItemIdentifier item = new ItemIdentifier(stack);
    getMapData(item).itemCount -= amount;
    stack.stackSize -= amount;
    if (stack.stackSize <= 0)
        tempContents[slot] = null;
    ignoreModifiedItems = true;
    ItemStack result = data.removeItems(item, amount);
    ignoreModifiedItems = false;
    if (tempContents[slot] == null)
        onSlotEmptied(slot);
    return result;
}
Also used : ItemIdentifier(net.mcft.copy.betterstorage.misc.ItemIdentifier) ItemStack(net.minecraft.item.ItemStack)

Example 24 with ItemStack

use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.

the class InventoryCratePlayerView method onSlotEmptied.

private void onSlotEmptied(int slot) {
    int emptySlots = 0;
    for (int s = 0; s < tempContents.length; s++) if (tempContents[s] == null)
        emptySlots++;
    if (emptySlots <= data.getFreeSlots())
        return;
    for (ItemStack stack : data.getContents().getItems()) {
        ItemIdentifier item = new ItemIdentifier(stack);
        MapData itemData = getMapData(item);
        int count = (stack.stackSize - itemData.itemCount);
        if (count <= 0)
            continue;
        setItemsInSlot(slot, item, itemData, count);
    }
}
Also used : ItemIdentifier(net.mcft.copy.betterstorage.misc.ItemIdentifier) ItemStack(net.minecraft.item.ItemStack)

Example 25 with ItemStack

use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.

the class DrinkingHelmetRecipe method getCraftingResult.

@Override
public ItemStack getCraftingResult(InventoryCrafting crafting) {
    ItemStack drinkingHelmet = null;
    ItemStack[] potions = null;
    for (int i = 0; i < crafting.getSizeInventory(); i++) {
        drinkingHelmet = crafting.getStackInSlot(i);
        if ((drinkingHelmet != null) && (drinkingHelmet.getItem() instanceof ItemDrinkingHelmet)) {
            drinkingHelmet = drinkingHelmet.copy();
            potions = new ItemStack[] { crafting.getStackInSlot(i + 1), crafting.getStackInSlot(i - 1) };
            break;
        }
    }
    ItemDrinkingHelmet.setPotions(drinkingHelmet, potions);
    return drinkingHelmet;
}
Also used : ItemStack(net.minecraft.item.ItemStack) ItemDrinkingHelmet(net.mcft.copy.betterstorage.item.ItemDrinkingHelmet)

Aggregations

ItemStack (net.minecraft.item.ItemStack)2512 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)250 ArrayList (java.util.ArrayList)244 EntityItem (net.minecraft.entity.item.EntityItem)170 Slot (net.minecraft.inventory.Slot)164 TileEntity (net.minecraft.tileentity.TileEntity)155 EntityPlayer (net.minecraft.entity.player.EntityPlayer)153 Block (net.minecraft.block.Block)148 Item (net.minecraft.item.Item)118 BlockPos (net.minecraft.util.math.BlockPos)83 NBTTagList (net.minecraft.nbt.NBTTagList)74 IInventory (net.minecraft.inventory.IInventory)73 IBlockState (net.minecraft.block.state.IBlockState)70 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)67 FluidStack (net.minecraftforge.fluids.FluidStack)63 ShapedOreRecipe (net.minecraftforge.oredict.ShapedOreRecipe)63 World (net.minecraft.world.World)56 List (java.util.List)55 ResourceLocation (net.minecraft.util.ResourceLocation)50 Entity (net.minecraft.entity.Entity)47