當前位置: 首頁>>代碼示例>>Java>>正文


Java ISidedInventory.setInventorySlotContents方法代碼示例

本文整理匯總了Java中net.minecraft.inventory.ISidedInventory.setInventorySlotContents方法的典型用法代碼示例。如果您正苦於以下問題:Java ISidedInventory.setInventorySlotContents方法的具體用法?Java ISidedInventory.setInventorySlotContents怎麽用?Java ISidedInventory.setInventorySlotContents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.minecraft.inventory.ISidedInventory的用法示例。


在下文中一共展示了ISidedInventory.setInventorySlotContents方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: extractItemStackFromInventory

import net.minecraft.inventory.ISidedInventory; //導入方法依賴的package包/類
public static ItemStack extractItemStackFromInventory(IInventory theInventory, int side) {

		ItemStack retStack = null;

		if (theInventory instanceof ISidedInventory) {
			ISidedInventory sidedInv = (ISidedInventory) theInventory;
			int slots[] = sidedInv.getAccessibleSlotsFromSide(side);
			for (int i = 0; i < slots.length && retStack == null; i++) {
				if (sidedInv.getStackInSlot(i) != null && sidedInv.canExtractItem(i, sidedInv.getStackInSlot(i), side)) {
					retStack = sidedInv.getStackInSlot(i).copy();
					sidedInv.setInventorySlotContents(i, null);
				}
			}
		} else {
			for (int i = 0; i < theInventory.getSizeInventory() && retStack == null; i++) {
				if (theInventory.getStackInSlot(i) != null) {
					retStack = theInventory.getStackInSlot(i).copy();
					theInventory.setInventorySlotContents(i, null);
				}
			}
		}
		if (retStack != null) {
			theInventory.onInventoryChanged();
		}
		return retStack;
	}
 
開發者ID:PaleoCrafter,項目名稱:R0b0ts,代碼行數:27,代碼來源:InventoryHelper.java

示例2: addToSidedInventory

import net.minecraft.inventory.ISidedInventory; //導入方法依賴的package包/類
private ItemStack addToSidedInventory(ISidedInventory inventory, int side, ItemStack stack)
{
    ItemStack adding = stack.copy();
    int[] accessibleSlots = inventory.getAccessibleSlotsFromSide(side);
    for (int i = 0; i < accessibleSlots.length && adding.stackSize > 0; i++)
    {
        int slot = accessibleSlots[i];
        ItemStack inSlot = inventory.getStackInSlot(slot);
        if (inSlot == null || inSlot.getItem() == null)
        {
            inventory.setInventorySlotContents(slot, adding.copy());
            adding.stackSize = 0;
        } else if (inSlot.isItemEqual(adding) && ItemStack.areItemStackTagsEqual(stack, inSlot))
        {
            int stackLimit = Math.min(inSlot.getMaxStackSize(), inventory.getInventoryStackLimit());
            int remaining = inSlot.stackSize + adding.stackSize - stackLimit;
            if (remaining > 0)
            {
                inSlot.stackSize = stackLimit;
                adding.stackSize = remaining;
            } else
            {
                inSlot.stackSize += adding.stackSize;
                adding.stackSize = 0;
            }
        }
    }
    return adding;
}
 
開發者ID:MrSpring,項目名稱:ToggleBlocks,代碼行數:30,代碼來源:TileEntityToggleBlock.java

示例3: inventoryTransfer

import net.minecraft.inventory.ISidedInventory; //導入方法依賴的package包/類
private void inventoryTransfer(BlockPos adj, EnumFacing otherFace) {
	ItemStack[] inventory = this.getInventory();
	TileEntity te = getWorld().getTileEntity(adj);
	if(te instanceof IInventory ){
		ISidedInventory inv = InventoryWrapper.wrap((IInventory)te);
		int[] accessibleSlots = inv.getSlotsForFace(otherFace);
		if(accessibleSlots.length == 0) return;
		for(int mySlot = 0; mySlot < inventory.length; mySlot++){
			if(inventory[mySlot] == null) continue;
			for(int i = 0; i < accessibleSlots.length; i++){
				int theirSlot = accessibleSlots[i];
				ItemStack theirItem = inv.getStackInSlot(theirSlot);
				if(inv.canInsertItem(theirSlot, inventory[mySlot], otherFace)){
					if(theirItem == null){
						ItemStack newItem = inventory[mySlot].copy();
						newItem.stackSize = 1;
						inv.setInventorySlotContents(theirSlot, newItem);
						inventory[mySlot].stackSize--;
						if(inventory[mySlot].stackSize <= 0) inventory[mySlot] = null;
						return;
					} else if(ItemStack.areItemsEqual(theirItem, inventory[mySlot]) 
							&& ItemStack.areItemStackTagsEqual(theirItem, inventory[mySlot])
							&& theirItem.stackSize < theirItem.getMaxStackSize()
							&& theirItem.stackSize < inv.getInventoryStackLimit()){
						theirItem.stackSize++;
						inventory[mySlot].stackSize--;
						if(inventory[mySlot].stackSize <= 0) inventory[mySlot] = null;
						return;
					}
				}
			}
		}
		
	}
}
 
開發者ID:cyanobacterium,項目名稱:ElectricAdvantage,代碼行數:36,代碼來源:ElectricDrillTileEntity.java

示例4: inventoryTransfer

import net.minecraft.inventory.ISidedInventory; //導入方法依賴的package包/類
private void inventoryTransfer(BlockPos adj, EnumFacing otherFace) {
	TileEntity te = getWorld().getTileEntity(adj);
	if(te instanceof IInventory ){
		ISidedInventory inv = InventoryWrapper.wrap((IInventory)te);
		int[] accessibleSlots = inv.getSlotsForFace(otherFace);
		if(accessibleSlots.length == 0) return;
		for(int mySlot = 0; mySlot < this.inventory.length; mySlot++){
			if(this.inventory[mySlot] == null) continue;
			for(int i = 0; i < accessibleSlots.length; i++){
				int theirSlot = accessibleSlots[i];
				ItemStack theirItem = inv.getStackInSlot(theirSlot);
				if(inv.canInsertItem(theirSlot, inventory[mySlot], otherFace)){
					if(theirItem == null){
						ItemStack newItem = inventory[mySlot].copy();
						newItem.stackSize = 1;
						inv.setInventorySlotContents(theirSlot, newItem);
						inventory[mySlot].stackSize--;
						if(inventory[mySlot].stackSize <= 0) inventory[mySlot] = null;
						return;
					} else if(ItemStack.areItemsEqual(theirItem, inventory[mySlot]) 
							&& ItemStack.areItemStackTagsEqual(theirItem, inventory[mySlot])
							&& theirItem.stackSize < theirItem.getMaxStackSize()
							&& theirItem.stackSize < inv.getInventoryStackLimit()){
						theirItem.stackSize++;
						inventory[mySlot].stackSize--;
						if(inventory[mySlot].stackSize <= 0) inventory[mySlot] = null;
						return;
					}
				}
			}
		}
		
	}
}
 
開發者ID:cyanobacterium,項目名稱:SteamAdvantage,代碼行數:35,代碼來源:SteamDrillTileEntity.java

示例5: addtoSidedExtInventory

import net.minecraft.inventory.ISidedInventory; //導入方法依賴的package包/類
public boolean addtoSidedExtInventory(ISidedInventory inv, int fromSlot) {
	int[] trySlots = inv.getSlotsForFace(extDirection.getOpposite());
	int i = 0;
	
	for (int j = 0; j < trySlots.length; j++) {
		i = trySlots[j];
		if (inv.getStackInSlot(i).isEmpty()) {
			if ( (inv.getStackInSlot(i).isItemEqual(slots[fromSlot])) 
					&& (inv.getStackInSlot(i).getCount() < inv.getStackInSlot(i).getMaxStackSize()) 
					&& (ItemStack.areItemStackTagsEqual(inv.getStackInSlot(i), slots[fromSlot])) ) {
				int avail = inv.getStackInSlot(i).getMaxStackSize() - inv.getStackInSlot(i).getCount();
				if (avail >= slots[fromSlot].getCount()) {
					inv.getStackInSlot(i).grow(slots[fromSlot].getCount());
					slots[fromSlot] = ItemStack.EMPTY;
					return true;
				} else {
					slots[fromSlot].shrink(avail);
					inv.getStackInSlot(i).grow(avail);
				}
			}
		}
	}
	if ( (!slots[fromSlot].isEmpty()) && (slots[fromSlot].getCount() > 0) ) {
		for (int j = 0; j < trySlots.length; j++) {
			i = trySlots[j];
			if (inv.canInsertItem(i, slots[fromSlot], extDirection.getOpposite())) {
				if ( (inv.getStackInSlot(i).isEmpty()) && (inv.isItemValidForSlot(i, slots[fromSlot])) ) {
					inv.setInventorySlotContents(i, slots[fromSlot]);
					slots[fromSlot] = ItemStack.EMPTY;
					return true;
				}
			}
		}
	}
	return false;
}
 
開發者ID:Vanhal,項目名稱:ProgressiveAutomation,代碼行數:37,代碼來源:BaseTileEntity.java


注:本文中的net.minecraft.inventory.ISidedInventory.setInventorySlotContents方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。