Java Code Examples for net.minecraft.inventory.IInventory#getSizeInventory()

The following examples show how to use net.minecraft.inventory.IInventory#getSizeInventory() . These examples are extracted from open source projects. 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 Project: ExtraCells1   File: ContainerBusFluidExport.java    License: MIT License 6 votes vote down vote up
public ContainerBusFluidExport(IInventory inventoryPlayer, IInventory inventoryTileEntity)
{
	super(inventoryTileEntity.getSizeInventory());

	tileentity = inventoryTileEntity;

	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 4; j++)
		{
			addSlotToContainer(new SlotFake(inventoryTileEntity, j + i * 4, 53 + j * 18, i * 18 + 21)
			{
				public boolean isItemValid(ItemStack itemstack)
				{
					return tileentity.isItemValidForSlot(0, itemstack);
				}
			});
		}
	}

	bindPlayerInventory(inventoryPlayer);
}
 
Example 2
@Override
public void onModuleEnabled() {
    try {
        Class.forName("powercrystals.minefactoryreloaded.net.ServerPacketHandler");
        MovingObjectPosition mop = Wrapper.INSTANCE.mc().objectMouseOver;
        TileEntity entity = Wrapper.INSTANCE.world().getTileEntity(mop.blockX, mop.blockY, mop.blockZ);
        if (entity == null) {
            this.off();
            return;
        }
        if (entity instanceof IInventory) {
            IInventory inv = (IInventory) entity;
            for (int i = 0; i < inv.getSizeInventory(); i++) {
                setSlot(i, mop.blockX, mop.blockY, mop.blockZ);
            }
        }
        InteropUtils.log("Cleared", this);
        this.off();
    } catch (Exception ex) {
        this.off();
    }
}
 
Example 3
@Asynchronous(false)
@ScriptCallable(description = "Swap two slots in the inventory")
public void swapStacks(IInventory target,
		@Arg(name = "from", description = "The first slot") Index fromSlot,
		@Arg(name = "to", description = "The other slot") Index intoSlot,
		@Optionals @Arg(name = "fromDirection") ForgeDirection fromDirection,
		@Arg(name = "fromDirection") ForgeDirection toDirection) {
	IInventory inventory = InventoryUtils.getInventory(target);
	Preconditions.checkNotNull(inventory, "Invalid target!");
	final int size = inventory.getSizeInventory();
	fromSlot.checkElementIndex("first slot id", size);
	intoSlot.checkElementIndex("second slot id", size);
	if (inventory instanceof ISidedInventory) {
		InventoryUtils.swapStacks((ISidedInventory)inventory,
				fromSlot.value, Objects.firstNonNull(fromDirection, ForgeDirection.UNKNOWN),
				intoSlot.value, Objects.firstNonNull(toDirection, ForgeDirection.UNKNOWN));
	} else InventoryUtils.swapStacks(inventory, fromSlot.value, intoSlot.value);

	inventory.markDirty();
}
 
Example 4
public InventoryRange(IInventory inv, int side)
{
    this.inv = inv;
    this.face = EnumFacing.values()[side];
    if(inv instanceof ISidedInventory)
    {
        sidedInv = (ISidedInventory)inv;
        slots = sidedInv.getSlotsForFace(face);
    }
    else
    {
        slots = new int[inv.getSizeInventory()];
        for(int i = 0; i < slots.length; i++)
            slots[i] = i;
    }
}
 
Example 5
@Override
public int amountRequested(ItemStack stack){
    int totalRequestingAmount = getTotalRequestedAmount(stack);
    if(totalRequestingAmount > 0) {
        IInventory inv = IOHelper.getInventoryForTE(getTileEntity());
        int count = 0;
        if(inv != null) {
            for(int i = 0; i < inv.getSizeInventory(); i++) {
                ItemStack s = inv.getStackInSlot(i);
                if(s != null && isItemEqual(s, stack)) {
                    count += s.stackSize;
                }
            }
            count += getIncomingItems(stack);
            int requested = Math.max(0, Math.min(stack.stackSize, totalRequestingAmount - count));
            return requested;
        }
    }
    return 0;
}
 
Example 6
Source Project: ExtraCells1   File: ContainerBusFluidStorage.java    License: MIT License 6 votes vote down vote up
public ContainerBusFluidStorage(IInventory inventoryPlayer, IInventory inventoryTileEntity)
{
	super(inventoryTileEntity.getSizeInventory());

	tileentity = inventoryTileEntity;

	for (int i = 0; i < 6; i++)
	{
		for (int j = 0; j < 9; j++)
		{
			addSlotToContainer(new SlotFake(inventoryTileEntity, j + i * 9, 8 + j * 18, i * 18 - 10)
			{
				public boolean isItemValid(ItemStack itemstack)
				{
					return tileentity.isItemValidForSlot(0, itemstack);
				}
			});
		}
	}

	bindPlayerInventory(inventoryPlayer);
}
 
Example 7
Source Project: AdvancedRocketry   File: TileMicrowaveReciever.java    License: MIT License 6 votes vote down vote up
@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 8
public static ItemStack insert(IInventory inventory, ItemStack itemStack, int side, boolean simulate){

        if(inventory instanceof ISidedInventory && side > -1) {
            ISidedInventory isidedinventory = (ISidedInventory)inventory;
            int[] aint = isidedinventory.getAccessibleSlotsFromSide(side);

            for(int j = 0; j < aint.length && itemStack != null && itemStack.stackSize > 0; ++j) {
                itemStack = insert(inventory, itemStack, aint[j], side, simulate);
            }
        } else if(inventory != null) {
            int k = inventory.getSizeInventory();

            for(int l = 0; l < k && itemStack != null && itemStack.stackSize > 0; ++l) {
                itemStack = insert(inventory, itemStack, l, side, simulate);
            }
        }

        if(itemStack != null && itemStack.stackSize == 0) {
            itemStack = null;
        }

        return itemStack;
    }
 
Example 9
Source Project: ExtraCells1   File: ContainerBusFluidImport.java    License: MIT License 6 votes vote down vote up
public ContainerBusFluidImport(IInventory inventoryPlayer, IInventory inventoryTileEntity)
{
	super(inventoryTileEntity.getSizeInventory());

	tileentity = inventoryTileEntity;
	
	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 4; j++)
		{
			addSlotToContainer(new SlotFake(inventoryTileEntity, j + i * 4, 53 + j * 18, i * 18 + 21)
			{
				public boolean isItemValid(ItemStack itemstack)
				{
					return tileentity.isItemValidForSlot(0, itemstack);
				}
			});
		}
	}

	bindPlayerInventory(inventoryPlayer);
}
 
Example 10
Source Project: OpenModsLib   File: EntityBlock.java    License: MIT License 6 votes vote down vote up
private void dropBlock() {
	final Block block = blockState.getBlock();

	Random rand = world.rand;

	final int count = block.quantityDropped(blockState, 0, rand);
	for (int i = 0; i < count; i++) {
		final Item item = block.getItemDropped(blockState, rand, 0);
		if (item != null) {
			ItemStack toDrop = new ItemStack(item, 1, block.damageDropped(blockState));
			entityDropItem(toDrop, 0.1f);
		}
	}

	if (tileEntity instanceof IInventory) {
		IInventory inv = (IInventory)tileEntity;
		for (int i = 0; i < inv.getSizeInventory(); i++) {
			ItemStack is = inv.getStackInSlot(i);
			if (is != null) entityDropItem(is, 0.1f);
		}
	}
}
 
Example 11
@ScriptCallable(description = "Get the undamagedness of the rotor, from 0% (dead) to 100% (brand new)", returnTypes = ReturnType.NUMBER)
public Integer getTurbineRotorStatus(Object tileSteamTurbine) {
	IInventory inventory = GET_INVENTORY.call(tileSteamTurbine);

	if (inventory != null && inventory.getSizeInventory() >= 1) {
		ItemStack itemStack = inventory.getStackInSlot(0);
		if (itemStack != null) {
			Item item = itemStack.getItem();
			if (item != null) { return 100 - (int)(itemStack.getItemDamage() * 100.0 / item.getMaxDamage()); }
		}
	}
	return null;
}
 
Example 12
/**
 * 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 13
public InventoryRange(IInventory inv, Direction side) {
    this.inv = inv;
    this.face = side;
    if (inv instanceof ISidedInventory) {
        sidedInv = (ISidedInventory) inv;
        slots = sidedInv.getSlotsForFace(face);
    } else {
        slots = new int[inv.getSizeInventory()];
        for (int i = 0; i < slots.length; i++) {
            slots[i] = i;
        }
    }
}
 
Example 14
public ContainerMinecart(InventoryPlayer playerInv, EntityMinecart cart, boolean isMotorized){
    super(null);
    this.cart = cart;
    this.isMotorized = isMotorized;
    CapabilityMinecartDestination cap = cart.getCapability(CapabilityMinecartDestination.INSTANCE, null);
    addSyncedFields(cap);
    
    if(isMotorized){
    	IInventory inv = cap.getFuelInv();
    	for(int i = 0; i < inv.getSizeInventory(); i++){
    		addSlotToContainer(new SlotInventoryLimiting(inv, i, 18 * i + 164, 70));
    	}
    	addPlayerSlots(playerInv, 128, 120);
    }
}
 
Example 15
Source Project: AdvancedRocketry   File: StorageChunk.java    License: MIT License 5 votes vote down vote up
public static StorageChunk cutWorldBB(World worldObj, AxisAlignedBB bb) {
	StorageChunk chunk = StorageChunk.copyWorldBB(worldObj, bb);
	for(int x = (int)bb.minX; x <= bb.maxX; x++) {
		for(int z = (int)bb.minZ; z <= bb.maxZ; z++) {
			for(int y = (int)bb.minY; y<= bb.maxY; y++) {

				BlockPos pos = new BlockPos(x, y, z);
				//Workaround for dupe
				TileEntity tile = worldObj.getTileEntity(pos);
				if(tile instanceof IInventory) {
					IInventory inv = (IInventory) tile;
					for(int i = 0; i < inv.getSizeInventory(); i++) {
						inv.setInventorySlotContents(i, ItemStack.EMPTY);
					}
				}

				worldObj.setBlockState(pos, Blocks.AIR.getDefaultState(),2);
			}
		}
	}

	//Carpenter's block's dupe
	for(Object entity : worldObj.getEntitiesWithinAABB(EntityItem.class, bb.grow(5, 5, 5)) ) {
		((Entity)entity).setDead();
	}

	return chunk;
}
 
Example 16
Source Project: pycode-minecraft   File: PyCodeBlockTileEntity.java    License: MIT License 5 votes vote down vote up
private static boolean isInventoryEmpty(IInventory inventoryIn, EnumFacing side)
{
    if (inventoryIn instanceof ISidedInventory)
    {
        ISidedInventory isidedinventory = (ISidedInventory)inventoryIn;
        int[] aint = isidedinventory.getSlotsForFace(side);

        for (int i : aint)
        {
            if (isidedinventory.getStackInSlot(i) != null)
            {
                return false;
            }
        }
    }
    else
    {
        int j = inventoryIn.getSizeInventory();

        for (int k = 0; k < j; ++k)
        {
            if (inventoryIn.getStackInSlot(k) != null)
            {
                return false;
            }
        }
    }

    return true;
}
 
Example 17
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Get a table with all the items of the chest")
public Map<Index, Object> getAllStacks(IInventory target,
		@Env(Constants.ARG_ARCHITECTURE) IArchitecture access,
		@Optionals @Arg(name = "proxy", description = "If false, method will compute whole table, instead of returning proxy") Boolean proxy) {
	final IInventory inventory = InventoryUtils.getInventory(target);
	Map<Index, Object> result = Maps.newHashMap();

	for (int i = 0; i < inventory.getSizeInventory(); i++) {
		ItemStack stack = inventory.getStackInSlot(i);
		if (stack != null) result.put(access.createIndex(i), (proxy != Boolean.FALSE)? OpcAccess.itemStackMetaBuilder.createProxy(stack) : stack);
	}
	return result;
}
 
Example 18
@Override
public void processCommand(ICommandSender sender, String[] args){
    if(args.length < 2) throw new WrongUsageException("command.deliverAmazon.args");
    int x, y, z;
    int curArg;
    String regex = "-?\\d+";
    if(args[0].matches(regex)) {
        if(args.length < 4) throw new WrongUsageException("command.deliverAmazon.args");
        if(!args[1].matches(regex) || !args[2].matches(regex)) throw new WrongUsageException("command.deliverAmazon.coords");
        x = Integer.parseInt(args[0]);
        y = Integer.parseInt(args[1]);
        z = Integer.parseInt(args[2]);
        curArg = 3;
    } else {
        EntityPlayerMP player = MinecraftServer.getServer().getConfigurationManager().func_152612_a(args[0]);
        if(player != null) {
            x = (int)Math.floor(player.posX);
            y = (int)Math.floor(player.posY) + 1;
            z = (int)Math.floor(player.posZ);
            curArg = 1;
        } else {
            throw new WrongUsageException("command.deliverAmazon.playerName");
        }
    }

    if(args.length < curArg + 3) throw new WrongUsageException("command.deliverAmazon.args");
    if(!args[curArg].matches(regex) || !args[curArg + 1].matches(regex) || !args[curArg + 2].matches(regex)) throw new WrongUsageException("command.deliverAmazon.coords");
    TileEntity te = sender.getEntityWorld().getTileEntity(Integer.parseInt(args[curArg]), Integer.parseInt(args[curArg + 1]), Integer.parseInt(args[curArg + 2]));
    IInventory inv = IOHelper.getInventoryForTE(te);
    if(inv != null) {
        List<ItemStack> deliveredStacks = new ArrayList<ItemStack>();
        for(int i = 0; i < inv.getSizeInventory() && deliveredStacks.size() < 65; i++) {
            if(inv.getStackInSlot(i) != null) deliveredStacks.add(inv.getStackInSlot(i));
        }
        if(deliveredStacks.size() > 0) {
            PneumaticRegistry.getInstance().deliverItemsAmazonStyle(sender.getEntityWorld(), x, y, z, deliveredStacks.toArray(new ItemStack[deliveredStacks.size()]));
            sender.addChatMessage(new ChatComponentTranslation("command.deliverAmazon.success"));
        } else {
            sender.addChatMessage(new ChatComponentTranslation("command.deliverAmazon.noItems"));
        }
    } else {
        throw new WrongUsageException("command.deliverAmazon.noInventory");
    }

}
 
Example 19
Source Project: Et-Futurum   File: ServerEventHandler.java    License: The Unlicense 4 votes vote down vote up
@SubscribeEvent
public void arrowLoose(ArrowLooseEvent event) {
	if (event.bow == null)
		return;

	IInventory invt = event.entityPlayer.inventory;
	for (int i = 0; i < invt.getSizeInventory(); i++) {
		ItemStack arrow = invt.getStackInSlot(i);
		if (arrow != null && arrow.stackSize > 0 && arrow.getItem() == ModItems.tipped_arrow) {
			float charge = event.charge / 20.0F;
			charge = (charge * charge + charge * 2.0F) / 3.0F;

			if (charge < 0.1D)
				return;
			if (charge > 1.0F)
				charge = 1.0F;

			EntityTippedArrow arrowEntity = new EntityTippedArrow(event.entityPlayer.worldObj, event.entityPlayer, charge * 2.0F);
			arrowEntity.setEffect(TippedArrow.getEffect(arrow));

			if (charge == 1.0F)
				arrowEntity.setIsCritical(true);

			int power = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, event.bow);
			if (power > 0)
				arrowEntity.setDamage(arrowEntity.getDamage() + power * 0.5D + 0.5D);

			int punch = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, event.bow);
			if (punch > 0)
				arrowEntity.setKnockbackStrength(punch);

			if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, event.bow) > 0)
				arrowEntity.setFire(100);

			event.bow.damageItem(1, event.entityPlayer);
			event.entityPlayer.worldObj.playSoundAtEntity(event.entityPlayer, "random.bow", 1.0F, 1.0F / (event.entityPlayer.worldObj.rand.nextFloat() * 0.4F + 1.2F) + charge * 0.5F);

			if (!event.entityPlayer.capabilities.isCreativeMode && --arrow.stackSize <= 0)
				event.entityPlayer.inventory.setInventorySlotContents(i, null);

			if (!event.entityPlayer.worldObj.isRemote)
				event.entityPlayer.worldObj.spawnEntityInWorld(arrowEntity);
			event.setCanceled(true);
			return;
		}
	}
}
 
Example 20
private ItemStack getJarItem(IInventory inv) {
    int itemCount = 0;
    int invWidth = (int) Math.sqrt(inv.getSizeInventory());

    ItemStack jarItem = null;

    for(int i = 0; i < invWidth*invWidth; i++) {
        ItemStack current = inv.getStackInSlot(i);
        if(current != null) {
            itemCount++;
            if(itemCount > 2) {
                return null;
            }

            if(jarItem == null) {
                if(current.getItem() == Items.slime_ball) {
                    return null;
                }

                boolean isSticky = RegisteredItems.isStickyableJar(current) && (!current.hasTagCompound()
                        || !current.getTagCompound().getBoolean("isStickyJar"));
                if(current.getItem() != Items.slime_ball && !isSticky) {
                    return null;
                }


                if(isSticky) {
                    int slimeSlot = i + invWidth;

                    if(slimeSlot < 0 || slimeSlot > inv.getSizeInventory()) {
                        return null;
                    }

                    ItemStack slime = inv.getStackInSlot(slimeSlot);
                    if(slime == null || slime.getItem() != Items.slime_ball) {
                        return null;
                    }

                    jarItem = current;
                }
            }
        }
    }
    return jarItem;
}