类net.minecraft.inventory.IInventory源码实例Demo

下面列出了怎么用net.minecraft.inventory.IInventory的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: PneumaticCraft   文件: BlockTrackEntryInventory.java
@Override
public boolean shouldTrackWithThisEntry(IBlockAccess world, int x, int y, int z, Block block, TileEntity te){
    if(tileEntityClassToNameMapping == null) {
        try {
            tileEntityClassToNameMapping = (Map)ReflectionHelper.findField(TileEntity.class, "field_145853_j", "classToNameMap").get(null);
        } catch(Exception e) {
            Log.error("[BlockTrackEntryInventory.class] Uhm reflection failed here!");
            e.printStackTrace();
        }
    }
    if(te instanceof TileEntityChest) {
        TileEntityChest chest = (TileEntityChest)te;
        if(chest.adjacentChestXNeg != null || chest.adjacentChestZNeg != null) return false;
    }
    return te != null && !invBlackList.contains(tileEntityClassToNameMapping.get(te.getClass())) && te instanceof IInventory && ((IInventory)te).getSizeInventory() > 0 && !MinecraftForge.EVENT_BUS.post(new InventoryTrackEvent(te));
}
 
源代码2 项目: ExtraCells1   文件: ContainerBusFluidStorage.java
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);
}
 
@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();
}
 
public ContainerMinecoprocessor(IInventory playerInventory, IInventory te) {
  this.te = te;

  this.codeBookSlot = this.addSlotToContainer(new CodeBookSlot(te, 0, 80, 35));

  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 9; ++j) {
      this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
    }
  }

  for (int k = 0; k < 9; ++k) {
    this.addSlotToContainer(new Slot(playerInventory, k, 8 + k * 18, 142));
  }

}
 
源代码5 项目: PneumaticCraft   文件: LogisticsManager.java
public static int getRequestedAmount(SemiBlockLogistics requester, ItemStack providingStack){
    TileEntity te = requester.getTileEntity();
    if(!(te instanceof IInventory)) return 0;
    int requestedAmount = requester instanceof ISpecificRequester ? ((ISpecificRequester)requester).amountRequested(providingStack) : providingStack.stackSize;
    if(requestedAmount == 0) return 0;
    providingStack = providingStack.copy();
    providingStack.stackSize = requestedAmount;
    ItemStack remainder = providingStack.copy();
    remainder.stackSize += requester.getIncomingItems(providingStack);
    for(ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
        remainder = IOHelper.insert(te, remainder, d, true);
        if(remainder == null) break;
    }
    if(remainder != null) providingStack.stackSize -= remainder.stackSize;
    if(providingStack.stackSize <= 0) return 0;
    return providingStack.stackSize;
}
 
源代码6 项目: PneumaticCraft   文件: TileEntityAirCannon.java
private boolean inventoryCanCarry(){
    insertingInventoryHasSpace = true;
    if(lastInsertingInventory == null) return true;
    if(inventory[0] == null) return true;
    TileEntity te = worldObj.getTileEntity(lastInsertingInventory.chunkPosX, lastInsertingInventory.chunkPosY, lastInsertingInventory.chunkPosZ);
    IInventory inv = IOHelper.getInventoryForTE(te);
    if(inv != null) {
        ItemStack remainder = IOHelper.insert(inv, inventory[0].copy(), lastInsertingInventorySide.ordinal(), true);
        insertingInventoryHasSpace = remainder == null;
        return insertingInventoryHasSpace;
    } else {
        lastInsertingInventory = null;
        lastInsertingInventorySide = null;
        return true;
    }
}
 
源代码7 项目: PneumaticCraft   文件: BlockTrackEntryInventory.java
@Override
public void addInformation(World world, int x, int y, int z, TileEntity te, List<String> infoList){
    try {
        IInventory inventory = IOHelper.getInventoryForTE(te);
        if(inventory != null) {
            boolean empty = true;
            ItemStack[] inventoryStacks = new ItemStack[inventory.getSizeInventory()];
            for(int i = 0; i < inventory.getSizeInventory(); i++) {
                ItemStack iStack = inventory.getStackInSlot(i);
                if(iStack != null) empty = false;
                inventoryStacks[i] = iStack;
            }
            if(empty) {
                infoList.add("Contents: Empty");
            } else {
                infoList.add("Contents:");
                PneumaticCraftUtils.sortCombineItemStacksAndToString(infoList, inventoryStacks);
            }
        }
    } catch(Throwable e) {
        addTileEntityToBlackList(te, e);
    }
}
 
源代码8 项目: PneumaticCraft   文件: IOHelper.java
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;
    }
 
源代码9 项目: PneumaticCraft   文件: IOHelper.java
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);
            }
        }
    }
 
源代码10 项目: ForbiddenMagic   文件: ItemSubCollar.java
/**
 * Returns true if the item can be used on the given entity, e.g. shears on sheep.
 */
@Override
public boolean itemInteractionForEntity(ItemStack itemstack, EntityPlayer player, EntityLivingBase entity)
{
    if (entity.worldObj.isRemote)
    {
        return false;
    }
    if (entity instanceof EntityPlayer)
    {
        EntityPlayer sub = (EntityPlayer)entity;
        IInventory baubles = BaublesApi.getBaubles(sub);
        if(baubles.getStackInSlot(0) == null) {
            if(!itemstack.hasTagCompound()){
                NBTTagCompound tag = new NBTTagCompound();
                itemstack.setTagCompound(tag);
            }
            itemstack.stackTagCompound.setString("owner", player.getDisplayName());
            baubles.setInventorySlotContents(0, itemstack.copy());
            itemstack.stackSize = 0;
            sub.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("message.collar.placescollar").replace("%s", player.getDisplayName())));
            player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("message.collar.youplacecollar").replace("%s", sub.getDisplayName())));
            return true;
        }
        else
            player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("message.collar.alreadywearing").replace("%s", sub.getDisplayName())));
    }
    return false;
}
 
源代码11 项目: TFC2   文件: ContainerCart.java
protected void layoutContainer(IInventory playerInventory, IInventory chestInventory, int xSize, int ySize)
{
	for(int y = 0; y < 3; y++)
	{
		for(int x = 0; x < 9; x++)
		{
			this.addSlotToContainer(new Slot(chestInventory, x+y*9, 8+x*18, 18+y*18));
		}
	}
}
 
源代码12 项目: ExtraCells1   文件: BlockHardMEDrive.java
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;
		}
	}
}
 
private void ejectChipFrom(IInventory guidanceComputer) {
	for(EnumFacing dir : EnumFacing.VALUES) {
		TileEntity tile = world.getTileEntity(getPos().offset(dir));
		if(tile instanceof IInventory) {
			if(ZUtils.doesInvHaveRoom(guidanceComputer.getStackInSlot(0), (IInventory)tile)) {
				ZUtils.mergeInventory(guidanceComputer.getStackInSlot(0), (IInventory)tile);
				guidanceComputer.removeStackFromSlot(0);
			}
		}
	}
}
 
源代码14 项目: GregTech   文件: EnchantmentTableTweaks.java
private static int getEnchantmentSlotIndex(ContainerEnchantment container) {
    IInventory inventory = container.tableInventory;
    for (int i = 0; i < container.inventorySlots.size(); i++) {
        Slot slot = container.inventorySlots.get(i);
        if (slot.isHere(inventory, EnchantmentLapisSlot.ENCHANTMENT_LAPIS_SLOT_INDEX)) return i;
    }
    return -1;
}
 
源代码15 项目: NOVA-Core   文件: InventoryConverter.java
@Override
public Inventory toNova(IInventory nativeObj) {
	if (nativeObj instanceof FWInventory) {
		return ((FWInventory) nativeObj).wrapped;
	}

	return new BWInventory(nativeObj);
}
 
源代码16 项目: Signals   文件: GuiContainerBase.java
@Override
protected void drawGuiContainerForegroundLayer(int x, int y){
    if(getInvNameOffset() != null && te instanceof IInventory) {
        IInventory inv = (IInventory)te;
        String containerName = inv.hasCustomName() ? inv.getName() : I18n.format(inv.getName() + ".name");
        fontRenderer.drawString(containerName, xSize / 2 - fontRenderer.getStringWidth(containerName) / 2 + getInvNameOffset().x, 6 + getInvNameOffset().y, 4210752);
    }
    if(getInvTextOffset() != null) fontRenderer.drawString(I18n.format("container.inventory"), 8 + getInvTextOffset().x, ySize - 94 + getInvTextOffset().y, 4210752);
}
 
private void dropInventory(World world, double x, double y, double z){

        IInventory inventory = this;
        Random rand = new Random();
        for(int i = 0; i < inventory.getSizeInventory(); i++) {

            ItemStack itemStack = inventory.getStackInSlot(i);

            if(itemStack != null && itemStack.stackSize > 0) {
                float dX = rand.nextFloat() * 0.8F - 0.4F;
                float dY = rand.nextFloat() * 0.8F - 0.4F;
                float dZ = rand.nextFloat() * 0.8F - 0.4F;

                EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, new ItemStack(itemStack.getItem(), itemStack.stackSize, itemStack.getItemDamage()));

                if(itemStack.hasTagCompound()) {
                    entityItem.getEntityItem().setTagCompound((NBTTagCompound)itemStack.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);
                // itemStack.stackSize = 0;
            }
        }
        this.inventory = new ItemStack[4];
    }
 
源代码18 项目: CodeChickenLib   文件: InventoryRange.java
public InventoryRange(IInventory inv, int fslot, int lslot)
{
    this.inv = inv;
    slots = new int[lslot-fslot];
    for(int i = 0; i < slots.length; i++)
        slots[i] = fslot+i;
}
 
public static String getInventoryName(IInventory inv)
{
    String invName = inv.getName();
    String prefix = "container.";
    if (invName.startsWith(prefix))
        invName = invName.substring(prefix.length());
    return invName;
}
 
源代码20 项目: CodeChickenLib   文件: InventoryUtils.java
/**
 * Consumes one item from slot in inv with support for containers.
 */
public static void consumeItem(IInventory inv, int slot) {
    ItemStack stack = inv.getStackInSlot(slot);
    Item item = stack.getItem();
    if (item.hasContainerItem(stack)) {
        ItemStack container = item.getContainerItem(stack);
        inv.setInventorySlotContents(slot, container);
    } else {
        inv.decrStackSize(slot, 1);
    }
}
 
源代码21 项目: PneumaticCraft   文件: AmadronOfferCustom.java
public void returnStock(){
    TileEntity provider = getProvidingTileEntity();
    TileEntity returning = getReturningTileEntity();
    invert();
    while(inStock > 0) {
        int stock = Math.min(inStock, 50);
        stock = ContainerAmadron.capShoppingAmount(this, stock, returning instanceof IInventory ? (IInventory)returning : null, provider instanceof IInventory ? (IInventory)provider : null, returning instanceof IFluidHandler ? (IFluidHandler)returning : null, provider instanceof IFluidHandler ? (IFluidHandler)provider : null, null);
        if(stock > 0) {
            inStock -= stock;
            if(getInput() instanceof ItemStack) {
                ItemStack deliveringItems = (ItemStack)getInput();
                int amount = deliveringItems.stackSize * stock;
                List<ItemStack> stacks = new ArrayList<ItemStack>();
                while(amount > 0) {
                    ItemStack stack = deliveringItems.copy();
                    stack.stackSize = Math.min(amount, stack.getMaxStackSize());
                    stacks.add(stack);
                    amount -= stack.stackSize;
                }
                PneumaticRegistry.getInstance().deliverItemsAmazonStyle(provider.getWorldObj(), provider.xCoord, provider.yCoord, provider.zCoord, stacks.toArray(new ItemStack[stacks.size()]));
            } else {
                FluidStack deliveringFluid = ((FluidStack)getInput()).copy();
                deliveringFluid.amount *= stock;
                PneumaticRegistry.getInstance().deliverFluidAmazonStyle(provider.getWorldObj(), provider.xCoord, provider.yCoord, provider.zCoord, deliveringFluid);
            }
        } else {
            break;
        }
    }
}
 
源代码22 项目: OpenModsLib   文件: InventoryUtils.java
public static Iterable<ItemStack> asIterable(final IInventory inv) {
	return () -> new AbstractIterator<ItemStack>() {
		final int size = inv.getSizeInventory();
		int slot = 0;

		@Override
		protected ItemStack computeNext() {
			if (slot >= size) return endOfData();
			return inv.getStackInSlot(slot++);
		}
	};
}
 
源代码23 项目: ToroQuest   文件: GraveyardGenerator.java
protected void addLootToChest(IInventory chest) {
	for (int i = 0; i < chest.getSizeInventory(); i++) {
		int roll = rand.nextInt(8);

		if (roll == 0) {
			chest.setInventorySlotContents(i, new ItemStack(Items.BONE, rand.nextInt(5) + 1));
		} else if (roll == 1) {
			chest.setInventorySlotContents(i, new ItemStack(Items.ROTTEN_FLESH, rand.nextInt(5) + 1));
		} else if (roll == 2) {
			if (rand.nextInt(20) == 0) {
				chest.setInventorySlotContents(i, new ItemStack(NICE_STUFF[rand.nextInt(NICE_STUFF.length)]));
			}
		}
	}
}
 
源代码24 项目: PneumaticCraft   文件: IOHelper.java
public static IInventory getInventoryForTE(TileEntity te){

        if(te instanceof IInventory) {
            IInventory inv = (IInventory)te;
            Block block = te.getBlockType();
            if(block instanceof BlockChest) {
                inv = ((BlockChest)block).func_149951_m(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord);
            }
            return inv;
        } else {
            return null;
        }
    }
 
源代码25 项目: PneumaticCraft   文件: DroneAIExternalProgram.java
@Override
protected boolean isValidPosition(ChunkPosition pos){
    if(traversedPositions.add(pos)) {
        curSlot = 0;
        TileEntity te = drone.getWorld().getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
        return te instanceof IInventory;
    }
    return false;
}
 
源代码26 项目: Gadomancy   文件: ArcanePackagerGui.java
public ArcanePackagerGui(InventoryPlayer playerInv, IInventory inventory) {
    super(new ContainerArcanePackager(playerInv, inventory));

    this.tile = (TileArcanePackager) inventory;
    this.playerInv = playerInv;

    this.ySize = 234;
    this.xSize = 190;
}
 
源代码27 项目: ExtraCells1   文件: ContainerBusFluidImport.java
protected void bindPlayerInventory(IInventory inventoryPlayer)
{
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 9; j++)
		{
			addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, i * 18 + 79));
		}
	}

	for (int i = 0; i < 9; i++)
	{
		addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 137));
	}
}
 
源代码28 项目: PneumaticCraft   文件: SemiBlockLogistics.java
public IInventory getFilters(){
    return filters;
}
 
源代码29 项目: PneumaticCraft   文件: ShapelessArcaneRecipe.java
@Override
public ItemStack getCraftingResult(IInventory var1){ return output.copy(); }
 
源代码30 项目: PneumaticCraft   文件: ShapedArcaneRecipe.java
@Override		
public AspectList getAspects(IInventory inv) {
	return aspects;
}