Java Code Examples for net.minecraft.inventory.IInventory#getStackInSlot()
The following examples show how to use
net.minecraft.inventory.IInventory#getStackInSlot() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InventoryUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 6 votes |
/** * Static default implementation for IInventory method */ @Nonnull public static ItemStack decrStackSize(IInventory inv, int slot, int size) { ItemStack item = inv.getStackInSlot(slot); if (!item.isEmpty()) { if (item.getCount() <= size) { inv.setInventorySlotContents(slot, ItemStack.EMPTY); inv.markDirty(); return item; } ItemStack itemstack1 = item.split(size); if (item.getCount() == 0) { inv.setInventorySlotContents(slot, ItemStack.EMPTY); } else { inv.setInventorySlotContents(slot, item); } inv.markDirty(); return itemstack1; } return ItemStack.EMPTY; }
Example 2
Source File: IOHelper.java From PneumaticCraft with GNU General Public License v3.0 | 6 votes |
public static void dropInventory(World world, int x, int y, int z){ TileEntity tileEntity = world.getTileEntity(x, y, z); if(!(tileEntity instanceof IInventory)) { return; } IInventory inventory = (IInventory)tileEntity; for(int i = 0; i < inventory.getSizeInventory(); i++) { ItemStack itemStack = inventory.getStackInSlot(i); if(itemStack != null && itemStack.stackSize > 0) { spawnItemInWorld(world, itemStack, x, y, z); } } }
Example 3
Source File: TileMicrowaveReciever.java From AdvancedRocketry with MIT License | 6 votes |
@Override public void onInventoryUpdated() { super.onInventoryUpdated(); List list = new LinkedList<Long>(); for(IInventory inv : itemInPorts) { for(int i = 0; i < inv.getSizeInventory(); i++) { ItemStack stack = inv.getStackInSlot(i); if(stack != null && stack.getItem() instanceof ItemSatelliteIdentificationChip) { ItemSatelliteIdentificationChip item = (ItemSatelliteIdentificationChip)stack.getItem(); list.add(item.getSatelliteId(stack)); } } } connectedSatellites = list; }
Example 4
Source File: SemiBlockHeatFrame.java From PneumaticCraft with GNU General Public License v3.0 | 6 votes |
private boolean tryCookSlot(IInventory inv, int slot){ ItemStack stack = inv.getStackInSlot(slot); if(stack != null) { ItemStack result = FurnaceRecipes.smelting().getSmeltingResult(stack); if(result != null) { ItemStack remainder = IOHelper.insert(getTileEntity(), result, true); if(remainder == null) { IOHelper.insert(getTileEntity(), result, false); inv.decrStackSize(slot, 1); lastValidSlot = slot; return true; } } } return false; }
Example 5
Source File: DataFamiliar.java From Gadomancy with GNU Lesser General Public License v3.0 | 6 votes |
public void equipTick(World world, EntityPlayer player, Aspect aspect) { if(world.isRemote) return; FamiliarData data = new FamiliarData(player.getCommandSenderName(), aspect.getTag()); IInventory baublesInv = BaublesApi.getBaubles(player); if(baublesInv.getStackInSlot(0) == null) { handleUnequip(world, player, aspect); return; } if(familiarControllers.get(player) == null || !playersWithFamiliar.contains(data)) { handleEquip(world, player, aspect); } familiarControllers.get(player).tick(); }
Example 6
Source File: TileGuidanceComputerHatch.java From AdvancedRocketry with MIT License | 6 votes |
@Override public boolean linkRocket(EntityRocketBase rocket) { this.rocket = (EntityRocket) rocket; IInventory guidanceComputer; if(!chipEjected && buttonState[buttonAutoEject] && (guidanceComputer = this.rocket.storage.getGuidanceComputer()) != null ) { ItemStack stack = guidanceComputer.getStackInSlot(0); if(!stack.isEmpty()) { if( (stack.getItem() instanceof ItemSatelliteIdentificationChip && buttonState[buttonSatellite]) || (stack.getItem() instanceof ItemPlanetIdentificationChip && buttonState[buttonPlanet]) || (stack.getItem() instanceof ItemStationChip && buttonState[buttonStation])) { ejectChipFrom(guidanceComputer); chipEjected = true; } } else chipEjected = true; } return true; }
Example 7
Source File: BlockUtils.java From OpenModsLib with MIT License | 5 votes |
public static void dropInventory(IInventory inventory, World world, double x, double y, double z) { if (inventory == null) { return; } for (int i = 0; i < inventory.getSizeInventory(); ++i) { ItemStack itemStack = inventory.getStackInSlot(i); if (!itemStack.isEmpty()) { dropItemStackInWorld(world, x, y, z, itemStack); } } }
Example 8
Source File: TileWarpCore.java From AdvancedRocketry with MIT License | 5 votes |
@Override public void onInventoryUpdated() { //Needs completion if(itemInPorts.isEmpty() /*&& !worldObj.isRemote*/) { attemptCompleteStructure(world.getBlockState(pos)); } if(getSpaceObject() == null || getSpaceObject().getFuelAmount() == getSpaceObject().getMaxFuelAmount()) return; for(IInventory inv : itemInPorts) { for(int i = 0; i < inv.getSizeInventory(); i++) { ItemStack stack = inv.getStackInSlot(i); int amt = 0; if(stack != null && OreDictionary.itemMatches(MaterialRegistry.getItemStackFromMaterialAndType("Dilithium", AllowedProducts.getProductByName("CRYSTAL")), stack, false)) { int stackSize = stack.getCount(); if(!world.isRemote) amt = getSpaceObject().addFuel(Configuration.fuelPointsPerDilithium*stack.getCount()); else amt = Math.min(getSpaceObject().getFuelAmount() + 10*stack.getCount(), getSpaceObject().getMaxFuelAmount()) - getSpaceObject().getFuelAmount();// inv.decrStackSize(i, amt/10); inv.markDirty(); //If full if(stackSize/10 != amt) return; } } } }
Example 9
Source File: AIBreakBlock.java From Gadomancy with GNU Lesser General Public License v3.0 | 5 votes |
private void trySwitchTool(IInventory inv) { for(int slot = 0; slot < inv.getSizeInventory(); slot++) { ItemStack stack = inv.getStackInSlot(slot); ItemStack current = golem.getCarried(); if(current != null) { current = InventoryUtils.insertStack(inv, current, golem.homeFacing, true); if(current != null) { return; } golem.setCarried(null); if(hasValidTool()) { hasValidTool = true; return; } } if(stack != null && isValidTool(stack)) { stack = stack.copy(); stack.stackSize = 1; stack = InventoryUtils.extractStack(inv, stack, golem.homeFacing, false, false, false, true); if(stack != null) { golem.setCarried(stack); golem.updateCarried(); player.setHeldItem(stack); hasValidTool = true; break; } } } }
Example 10
Source File: DataFamiliar.java From Gadomancy with GNU Lesser General Public License v3.0 | 5 votes |
public void checkPlayerEquipment(EntityPlayer p) { IInventory baublesInv = BaublesApi.getBaubles(p); if(baublesInv.getStackInSlot(0) != null) { ItemStack amulet = baublesInv.getStackInSlot(0); if(amulet.getItem() != null && amulet.getItem() instanceof ItemEtherealFamiliar) { Aspect a = ItemEtherealFamiliar.getFamiliarAspect(amulet); if(a != null) { handleEquip(p.worldObj, p, a); } } } }
Example 11
Source File: SearchUpgradeHandler.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
/** * This method will be called by the BlockTrackUpgradeHandler when it finds inventories while scanning blocks. * @param te TileEntity that already has been checked on if it implements IInventory, so it's save to cast it to IInventory. */ public void checkInventoryForItems(TileEntity te){ try { ItemStack searchStack = ItemPneumaticArmor.getSearchedStack(FMLClientHandler.instance().getClient().thePlayer.getCurrentArmor(3)); IInventory inventory = (IInventory)te; boolean hasFoundItem = false; if(searchStack != null) { for(int l = 0; l < inventory.getSizeInventory(); l++) { if(inventory.getStackInSlot(l) != null) { int items = RenderSearchItemBlock.getSearchedItemCount(inventory.getStackInSlot(l), searchStack); if(items > 0) { hasFoundItem = true; searchedItemCounter += items; } } } } if(hasFoundItem) { boolean inList = false; for(RenderSearchItemBlock trackedBlock : searchedBlocks) { if(trackedBlock.isAlreadyTrackingCoord(te.xCoord, te.yCoord, te.zCoord)) { inList = true; break; } } if(!inList) searchedBlocks.add(new RenderSearchItemBlock(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord)); } } catch(Throwable e) { } }
Example 12
Source File: AdapterDeconstructor.java From OpenPeripheral-Integration with MIT License | 5 votes |
@ScriptCallable(returnTypes = ReturnType.BOOLEAN, description = "Has the Table any items") public boolean hasItem(Object target) { if (target instanceof IInventory) { IInventory inv = (IInventory)target; return inv.getStackInSlot(0) != null; } return false; }
Example 13
Source File: TileEntityTicketMachine.java From OpenPeripheral-Addons with MIT License | 5 votes |
@Override public void onInventoryChanged(IInventory inventory, int slotNumber) { if (worldObj.isRemote) return; boolean nowHasTicket = inventory.getStackInSlot(SLOT_OUTPUT) != null; if (nowHasTicket != hasTicket.getValue()) hasTicket.set(nowHasTicket); markUpdated(); }
Example 14
Source File: BlockHardMEDrive.java From ExtraCells1 with MIT License | 5 votes |
private void dropItems(World world, int x, int y, int z) { Random rand = new Random(); TileEntity tileEntity = world.getBlockTileEntity(x, y, z); if (!(tileEntity instanceof IInventory)) { return; } IInventory inventory = (IInventory) tileEntity; for (int i = 0; i < inventory.getSizeInventory(); i++) { ItemStack item = inventory.getStackInSlot(i); if (item != null && item.stackSize > 0) { float rx = rand.nextFloat() * 0.8F + 0.1F; float ry = rand.nextFloat() * 0.8F + 0.1F; float rz = rand.nextFloat() * 0.8F + 0.1F; EntityItem entityItem = new EntityItem(world, x + rx, y + ry, z + rz, new ItemStack(item.itemID, item.stackSize, item.getItemDamage())); if (item.hasTagCompound()) { entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy()); } float factor = 0.05F; entityItem.motionX = rand.nextGaussian() * factor; entityItem.motionY = rand.nextGaussian() * factor + 0.2F; entityItem.motionZ = rand.nextGaussian() * factor; world.spawnEntityInWorld(entityItem); item.stackSize = 0; } } }
Example 15
Source File: ShapelessArcaneRecipe.java From ForbiddenMagic with Do What The F*ck You Want To Public License | 4 votes |
@Override public boolean matches(IInventory var1, World world, EntityPlayer player) { if (research.length()>0 && !ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), research)) { return false; } ArrayList required = new ArrayList(input); for (int x = 0; x < 9; x++) { ItemStack slot = var1.getStackInSlot(x); if (slot != null) { boolean inRecipe = false; Iterator req = required.iterator(); while (req.hasNext()) { boolean match = false; Object next = req.next(); if (next instanceof ItemStack) { match = checkItemEquals((ItemStack)next, slot); } else if (next instanceof ArrayList) { for (ItemStack item : (ArrayList<ItemStack>)next) { match = match || checkItemEquals(item, slot); } } if (match) { inRecipe = true; required.remove(next); break; } } if (!inRecipe) { return false; } } } return required.isEmpty(); }
Example 16
Source File: ShapelessArcaneRecipe.java From AdvancedMod with GNU General Public License v3.0 | 4 votes |
@Override public boolean matches(IInventory var1, World world, EntityPlayer player) { if (research.length()>0 && !ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), research)) { return false; } ArrayList required = new ArrayList(input); for (int x = 0; x < 9; x++) { ItemStack slot = var1.getStackInSlot(x); if (slot != null) { boolean inRecipe = false; Iterator req = required.iterator(); while (req.hasNext()) { boolean match = false; Object next = req.next(); if (next instanceof ItemStack) { match = checkItemEquals((ItemStack)next, slot); } else if (next instanceof ArrayList) { for (ItemStack item : (ArrayList<ItemStack>)next) { match = match || checkItemEquals(item, slot); } } if (match) { inRecipe = true; required.remove(next); break; } } if (!inRecipe) { return false; } } } return required.isEmpty(); }
Example 17
Source File: ManaItemHandler.java From ForbiddenMagic with Do What The F*ck You Want To Public License | 4 votes |
/** * Dispatches mana to items in a given player's inventory. Note that this method * does not automatically remove mana from the item which is exporting. * @param manaToSend How much mana is to be sent. * @param remove If true, the mana will be added from the target item. Set to false to just check. * @return The amount of mana actually sent. */ public static int dispatchMana(ItemStack stack, EntityPlayer player, int manaToSend, boolean add) { if(stack == null) return 0; IInventory mainInv = player.inventory; IInventory baublesInv = BotaniaAPI.internalHandler.getBaublesInventory(player); int invSize = mainInv.getSizeInventory(); int size = invSize; if(baublesInv != null) size += baublesInv.getSizeInventory(); for(int i = 0; i < size; i++) { boolean useBaubles = i >= invSize; IInventory inv = useBaubles ? baublesInv : mainInv; int slot = i - (useBaubles ? invSize : 0); ItemStack stackInSlot = inv.getStackInSlot(slot); if(stackInSlot == stack) continue; if(stackInSlot != null && stackInSlot.getItem() instanceof IManaItem) { IManaItem manaItemSlot = (IManaItem) stackInSlot.getItem(); if(manaItemSlot.canReceiveManaFromItem(stackInSlot, stack)) { if(stack.getItem() instanceof IManaItem && !((IManaItem) stack.getItem()).canExportManaToItem(stack, stackInSlot)) continue; int received = 0; if(manaItemSlot.getMana(stackInSlot) + manaToSend <= manaItemSlot.getMaxMana(stackInSlot)) received = manaToSend; else received = manaToSend - (manaItemSlot.getMana(stackInSlot) + manaToSend - manaItemSlot.getMaxMana(stackInSlot)); if(add) manaItemSlot.addMana(stackInSlot, manaToSend); if(useBaubles) BotaniaAPI.internalHandler.sendBaubleUpdatePacket(player, slot); return received; } } } return 0; }
Example 18
Source File: InventoryUtils.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 4 votes |
/** * Gets the size of the stack in a slot. Returns 0 on empty stacks */ public static int stackSize(IInventory inv, int slot) { ItemStack stack = inv.getStackInSlot(slot); return stack.isEmpty() ? 0 : stack.getCount(); }
Example 19
Source File: ContainerEnchantment.java From Et-Futurum with The Unlicense | 4 votes |
/** * Callback for when the crafting matrix is changed. */ @Override public void onCraftMatrixChanged(IInventory p_75130_1_) { if (p_75130_1_ == tableInventory) { ItemStack var2 = p_75130_1_.getStackInSlot(0); int power; if (var2 != null && var2.isItemEnchantable()) { if (!world.isRemote) { power = 0; int j; for (j = -1; j <= 1; ++j) for (int k = -1; k <= 1; ++k) if ((j != 0 || k != 0) && world.isAirBlock(posX + k, posY, posZ + j) && world.isAirBlock(posX + k, posY + 1, posZ + j)) { power += ForgeHooks.getEnchantPower(world, posX + k * 2, posY, posZ + j * 2); power += ForgeHooks.getEnchantPower(world, posX + k * 2, posY + 1, posZ + j * 2); if (k != 0 && j != 0) { power += ForgeHooks.getEnchantPower(world, posX + k * 2, posY, posZ + j); power += ForgeHooks.getEnchantPower(world, posX + k * 2, posY + 1, posZ + j); power += ForgeHooks.getEnchantPower(world, posX + k, posY, posZ + j * 2); power += ForgeHooks.getEnchantPower(world, posX + k, posY + 1, posZ + j * 2); } } rand.setSeed(enchantmentSeed); for (j = 0; j < 3; ++j) { enchantLevels[j] = EnchantmentHelper.calcItemStackEnchantability(rand, j, power, var2); field_178151_h[j] = -1; if (enchantLevels[j] < j + 1) enchantLevels[j] = 0; } for (j = 0; j < 3; ++j) if (enchantLevels[j] > 0) { List<EnchantmentData> var7 = func_178148_a(var2, j, enchantLevels[j]); if (var7 != null && !var7.isEmpty()) { EnchantmentData var6 = var7.get(rand.nextInt(var7.size())); field_178151_h[j] = var6.enchantmentobj.effectId | var6.enchantmentLevel << 8; } } detectAndSendChanges(); } } else for (power = 0; power < 3; ++power) { enchantLevels[power] = 0; field_178151_h[power] = -1; } } }
Example 20
Source File: ShapelessArcaneRecipe.java From Chisel-2 with GNU General Public License v2.0 | 4 votes |
@Override public boolean matches(IInventory var1, World world, EntityPlayer player) { if (research.length()>0 && !ThaumcraftApiHelper.isResearchComplete(player.getCommandSenderName(), research)) { return false; } ArrayList required = new ArrayList(input); for (int x = 0; x < 9; x++) { ItemStack slot = var1.getStackInSlot(x); if (slot != null) { boolean inRecipe = false; Iterator req = required.iterator(); while (req.hasNext()) { boolean match = false; Object next = req.next(); if (next instanceof ItemStack) { match = checkItemEquals((ItemStack)next, slot); } else if (next instanceof ArrayList) { for (ItemStack item : (ArrayList<ItemStack>)next) { match = match || checkItemEquals(item, slot); } } if (match) { inRecipe = true; required.remove(next); break; } } if (!inRecipe) { return false; } } } return required.isEmpty(); }