本文整理汇总了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;
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
}
}
}
}
}
示例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;
}
}
}
}
}
}
示例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;
}
示例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;
}
示例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;
}