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


Java ISidedInventory.canInsertItem方法代碼示例

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


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

示例1: transferIn

import net.minecraft.inventory.ISidedInventory; //導入方法依賴的package包/類
private boolean transferIn(BlockPos pos, ItemStack inserted, boolean test) {
	EnumFacing facing = getFacing();
	Pair<IItemHandler, ISidedInventory> inv = getInventory(pos, facing);
	if(inv.getKey() != null) {
		IItemHandler handler = inv.getKey();
		ISidedInventory tile = inv.getValue();

		for(int slot = 0; slot < handler.getSlots(); slot++) {
			ItemStack inSlot = handler.getStackInSlot(slot);
			if(tile != null && !tile.canInsertItem(slot, inserted, facing)) return false;
			if(inSlot.isEmpty() || (ItemHandlerHelper.canItemStacksStack(inSlot, inserted) && (inSlot.getCount() < inSlot.getMaxStackSize() && inSlot.getCount() < handler.getSlotLimit(slot)))) {
				return handler.insertItem(slot, inserted, test) != inserted;
			}
		}
	}
	return false;
}
 
開發者ID:ArekkuusuJerii,項目名稱:Solar,代碼行數:18,代碼來源:TileGravityHopper.java

示例2: isValidItemFor

import net.minecraft.inventory.ISidedInventory; //導入方法依賴的package包/類
protected boolean isValidItemFor(ItemStack item, TileEntity target, EnumFacing side){
	if(item == null) return false;
	if(target instanceof IInventory){
		BlockPos targetPos = target.getPos();
		ISidedInventory dt = InventoryWrapper.wrap(TileEntityHopper.getInventoryAtPosition(getWorld(),targetPos.getX(), targetPos.getY(), targetPos.getZ()));
		int[] slots = dt.getSlotsForFace(side);
		for(int i = 0; i < slots.length; i++){
			int slot = slots[i];
			if(dt.canInsertItem(slot, item, side)){
				return true;
			}
		}
		return false;
	}else{
		return true;
	}
}
 
開發者ID:cyanobacterium,項目名稱:PowerAdvantageAPI,代碼行數:18,代碼來源:TileEntityConveyorFilter.java

示例3: canInsertItemInto

import net.minecraft.inventory.ISidedInventory; //導入方法依賴的package包/類
protected static boolean canInsertItemInto(ItemStack item, ISidedInventory dest, EnumFacing destFace){
	if(item == null || item.getItem() == null || isLocked(dest)){
		return false;
	}
	int[] slots = dest.getSlotsForFace(destFace);
	for(int i = 0; i < slots.length; i++){
		int slot = slots[i];
		if(dest.canInsertItem(slot, item, destFace)){
			ItemStack destItem = dest.getStackInSlot(slot);
			if(destItem == null) {
				return true;
			} else {
				return ItemStack.areItemsEqual(item, destItem);
			}
		}
	}
	return false;
}
 
開發者ID:cyanobacterium,項目名稱:PowerAdvantageAPI,代碼行數:19,代碼來源:TileEntityConveyor.java

示例4: canInsert

import net.minecraft.inventory.ISidedInventory; //導入方法依賴的package包/類
private boolean canInsert(ItemStack item, EnumFacing f){
	TileEntity target = getWorld().getTileEntity(getPos().offset(f));
	if(target instanceof IInventory){
		EnumFacing side = f.getOpposite();
		ISidedInventory dt = InventoryWrapper.wrap((IInventory)target);
		int[] slots = dt.getSlotsForFace(side);
		for(int i = 0; i < slots.length; i++){
			int slot = slots[i];
			if(dt.canInsertItem(slot, item, side)){
				ItemStack targetSlot = dt.getStackInSlot(slot);
				if( (targetSlot == null) || 
						(ItemStack.areItemsEqual(item, targetSlot) 
								&& !targetSlot.getItem().isDamageable()
								&& targetSlot.stackSize < targetSlot.getMaxStackSize()
								&& targetSlot.stackSize < dt.getInventoryStackLimit())){
					return true;
				}
			}
		}
		return false;
	}else{
		return false;
	}
}
 
開發者ID:cyanobacterium,項目名稱:PowerAdvantageAPI,代碼行數:25,代碼來源:TileEntityOverflowFilter.java

示例5: doInsertItemInvMatching

import net.minecraft.inventory.ISidedInventory; //導入方法依賴的package包/類
private static int doInsertItemInvMatching(IInventory inv, ISidedInventory sidedInv, ISlotIterator slots, ItemStack item, EnumFacing inventorySide,
		boolean doInsert) {
	int numInserted = 0;
	int numToInsert = ItemStackTools.getStackSize(item);
	int firstFreeSlot = -1;

	// PASS1: Try to add to an existing stack
	while (numToInsert > 0 && slots.hasNext()) {
		final int slot = slots.nextSlot();
		if (sidedInv == null || sidedInv.canInsertItem(slot, item, inventorySide)) {
			final ItemStack contents = inv.getStackInSlot(slot);
			if (!ItemStackTools.isNullStack(contents)) {
				if (areStackMergable(contents, item)) {
					final int freeSpace = Math.min(inv.getInventoryStackLimit(), contents.getMaxStackSize()) - ItemStackTools.getStackSize(contents); // some inventories like using itemstacks with invalid stack sizes
					if (freeSpace > 0) {
						final int noToInsert = Math.min(numToInsert, freeSpace);
						final ItemStack toInsert = item.copy();
						ItemStackTools.setStackSize(toInsert, ItemStackTools.getStackSize(contents) + noToInsert);
						// isItemValidForSlot() may check the stacksize, so give it the number the stack would have in the end.
						// If it does something funny, like "only even numbers", we are screwed.
						if (sidedInv != null || inv.isItemValidForSlot(slot, toInsert)) {
							if (doInsert) {
								inv.setInventorySlotContents(slot, toInsert);
							}
						}
					}
				}
			} else if (firstFreeSlot == -1) {
				firstFreeSlot = slot;
			}
		}
	}

	if (numInserted > 0 && doInsert) {
		inv.markDirty();
	}
	return numInserted;
}
 
開發者ID:Alec-WAM,項目名稱:CrystalMod,代碼行數:39,代碼來源:ItemUtil.java

示例6: 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

示例7: 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

示例8: simulateInsertItemStackIntoInventory

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

		if (stack == null) {
			return null;
		}
		if (theInventory instanceof ISidedInventory) {
			ISidedInventory sidedInv = (ISidedInventory) theInventory;
			int slots[] = sidedInv.getAccessibleSlotsFromSide(side);

			if (slots == null) {
				return stack;
			}
			for (int i = 0; i < slots.length && stack != null; i++) {
				if (sidedInv.canInsertItem(slots[i], stack, side) && ItemHelper.itemsEqualWithMetadata(stack, theInventory.getStackInSlot(slots[i]), true)) {
					stack = simulateAddToOccupiedInventorySlot(sidedInv, slots[i], stack);
				}
			}
			for (int i = 0; i < slots.length && stack != null; i++) {
				if (sidedInv.canInsertItem(slots[i], stack, side) && theInventory.getStackInSlot(slots[i]) == null) {
					stack = simulateAddToEmptyInventorySlot(sidedInv, slots[i], stack);
				}
			}
		} else {
			int invSize = theInventory.getSizeInventory();
			for (int i = 0; i < invSize && stack != null; i++) {
				if (ItemHelper.itemsEqualWithMetadata(stack, theInventory.getStackInSlot(i), true)) {
					stack = simulateAddToOccupiedInventorySlot(theInventory, i, stack);
				}
			}
			for (int i = 0; i < invSize && stack != null; i++) {
				if (theInventory.getStackInSlot(i) == null) {
					stack = simulateAddToEmptyInventorySlot(theInventory, i, stack);
				}
			}
		}
		return stack;
	}
 
開發者ID:PaleoCrafter,項目名稱:R0b0ts,代碼行數:38,代碼來源:InventoryHelper.java

示例9: 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

示例10: insertItemStackIntoInventory

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

		if (stack == null) {
			return null;
		}
		int stackSize = stack.stackSize;

		if (theInventory instanceof ISidedInventory) {
			ISidedInventory sidedInv = (ISidedInventory) theInventory;
			int slots[] = sidedInv.getAccessibleSlotsFromSide(side);

			if (slots == null) {
				return stack;
			}
			for (int i = 0; i < slots.length && stack != null; i++) {
				if (sidedInv.canInsertItem(slots[i], stack, side) && ItemHelper.itemsEqualWithMetadata(stack, theInventory.getStackInSlot(slots[i]), true)) {
					stack = addToOccupiedInventorySlot(sidedInv, slots[i], stack);
				}
			}
			for (int i = 0; i < slots.length && stack != null; i++) {
				if (sidedInv.canInsertItem(slots[i], stack, side) && theInventory.getStackInSlot(slots[i]) == null) {
					stack = addToEmptyInventorySlot(sidedInv, slots[i], stack);
				}
			}
		} else {
			int invSize = theInventory.getSizeInventory();
			for (int i = 0; i < invSize && stack != null; i++) {
				if (ItemHelper.itemsEqualWithMetadata(stack, theInventory.getStackInSlot(i), true)) {
					stack = addToOccupiedInventorySlot(theInventory, i, stack);
				}
			}
			for (int i = 0; i < invSize && stack != null; i++) {
				if (theInventory.getStackInSlot(i) == null) {
					stack = addToEmptyInventorySlot(theInventory, i, stack);
				}
			}
		}
		if (stack == null || stack.stackSize != stackSize) {
			theInventory.onInventoryChanged();
		}
		return stack;
	}
 
開發者ID:PaleoCrafter,項目名稱:R0b0ts,代碼行數:43,代碼來源:InventoryHelper.java


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