Java 类net.minecraft.inventory.ISidedInventory 实例源码

项目:ElementalElaboration    文件:ContainerTileCustomMachine.java   
public ContainerTileCustomMachine(IInventory playerInv, TileCustomMachine tileEntity)
{
    super(0,3, 4,40);
    setTileEntity(tileEntity);

    CustomMachineSlot slotFirst = new CustomMachineSlot((ISidedInventory) tileEntity, 0, 52, 16);
    CustomMachineSlot slotSecond = new CustomMachineSlot((ISidedInventory) tileEntity, 1, 80, 16);
    CustomMachineSlot slotThird = new CustomMachineSlot((ISidedInventory) tileEntity, 2, 107, 16);
    CustomMachineSlot slotOut = new CustomMachineSlot((ISidedInventory) tileEntity, 3, 80, 46);

    // Tile Entity, Slot 0-3, Slot IDs 0-3
    this.addSlotToContainer(slotFirst);
    this.addSlotToContainer(slotSecond);
    this.addSlotToContainer(slotThird);

    this.addSlotToContainer(slotOut);

    // Player Inventory, Slot 4-35, Slot IDs 4-35
    for (int y = 0; y < 3; ++y)
        for (int x = 0; x < 9; ++x)
            this.addSlotToContainer(new Slot(playerInv, x + y * 9 + 9, 8 + x * 18, 84 + y * 18));

    // Player Inventory, Slot 0-8, Slot IDs 36-44
    for (int x = 0; x < 9; ++x)
        this.addSlotToContainer(new Slot(playerInv, x, 8 + x * 18, 142));
}
项目:Solar    文件:TileVacuumConveyor.java   
private void collectItems() {
    applyGravity(attract, true);
    IItemHandler handler = to.getKey();
    ISidedInventory sidedInv = to.getValue();
    getItemsFiltered(absorptionRange).forEach(e -> {
        e.setNoGravity(true);
        for(int slot = 0; slot < handler.getSlots(); slot++) {
            ItemStack inSlot = handler.getStackInSlot(slot);
            ItemStack in = e.getItem();
            if(sidedInv == null || sidedInv.canInsertItem(slot, in, getFacingLazy())) {
                if(inSlot.isEmpty() || (ItemHandlerHelper.canItemStacksStack(inSlot, in)
                        && (inSlot.getCount() < inSlot.getMaxStackSize()
                        && inSlot.getCount() < handler.getSlotLimit(slot)))) {
                    ItemStack out = handler.insertItem(slot, in, false);
                    if(out != in) {
                        e.setItem(out);
                        break;
                    }
                }
            }
        }
    });
}
项目:Solar    文件:TileVacuumConveyor.java   
private void dropItems() {
    if(world.getTotalWorldTime() % 10 != 0) return;
    applyGravity(repulse, false);
    IItemHandler handler = from.getKey();
    ISidedInventory sidedInv = from.getValue();
    Vector3 spawn = Vector3.create(getPos()).add(0.5D).offset(getFacingLazy(), 1);
    for(int slot = 0; slot < handler.getSlots(); slot++) {
        ItemStack inSlot = handler.getStackInSlot(slot);
        if(!inSlot.isEmpty()
                && (lookup.isEmpty() || ItemHandlerHelper.canItemStacksStack(lookup, inSlot))
                && (sidedInv == null || sidedInv.canExtractItem(slot, inSlot, getFacingLazy()))) {
            ItemStack out = handler.extractItem(slot, Integer.MAX_VALUE, false);
            EntityTemporalItem entity = new EntityTemporalItem(world, spawn.x, spawn.y, spawn.z, out);
            impulseEntityItem(spawn, entity);
            world.spawnEntity(entity);
            break;
        }
    }
}
项目:Solar    文件:TileGravityHopper.java   
private ItemStack transferOut(BlockPos pos, boolean test) {
    EnumFacing facing = getFacing().getOpposite();
    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 in = handler.getStackInSlot(slot);
            if(!in.isEmpty() && (tile == null || tile.canExtractItem(slot, in, facing))) {
                return handler.extractItem(slot, Integer.MAX_VALUE, test);
            }
        }
    }
    return ItemStack.EMPTY;
}
项目:Solar    文件:TileGravityHopper.java   
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;
}
项目:Backmemed    文件:TileEntityHopper.java   
/**
 * Attempts to place the passed stack in the inventory, using as many slots as required. Returns leftover items
 */
public static ItemStack putStackInInventoryAllSlots(IInventory inventoryIn, IInventory stack, ItemStack side, @Nullable EnumFacing p_174918_3_)
{
    if (stack instanceof ISidedInventory && p_174918_3_ != null)
    {
        ISidedInventory isidedinventory = (ISidedInventory)stack;
        int[] aint = isidedinventory.getSlotsForFace(p_174918_3_);

        for (int k = 0; k < aint.length && !side.func_190926_b(); ++k)
        {
            side = insertStack(inventoryIn, stack, side, aint[k], p_174918_3_);
        }
    }
    else
    {
        int i = stack.getSizeInventory();

        for (int j = 0; j < i && !side.func_190926_b(); ++j)
        {
            side = insertStack(inventoryIn, stack, side, j, p_174918_3_);
        }
    }

    return side;
}
项目:ExtraUtilities    文件:WidgetSlot.java   
public WidgetSlot(final IInventory inv, final int slot, final int x, final int y) {
    super(inv, slot, x + 1, y + 1);
    this.isISided = (inv instanceof ISidedInventory);
    this.side = 0;
    if (this.isISided) {
        this.side = 0;
        while (this.side < 6) {
            final int[] arr$;
            final int[] slots = arr$ = ((ISidedInventory)inv).getAccessibleSlotsFromSide(this.side);
            for (final int s : arr$) {
                if (s == slot) {
                    return;
                }
            }
            ++this.side;
        }
    }
}
项目:ExtraUtilities    文件:TileEntityTransferNodeInventory.java   
private static int getFirstExtractableItemStackSlot(final IInventory inv, final int side) {
    for (final int i : XUHelper.getInventorySideSlots(inv, side)) {
        final ItemStack item = inv.getStackInSlot(i);
        if (item != null && item.stackSize > 0 && (!(inv instanceof ISidedInventory) || ((ISidedInventory)inv).canExtractItem(i, item, side))) {
            if (!item.getItem().hasContainerItem(item)) {
                return i;
            }
            final ItemStack t = item.getItem().getContainerItem(item);
            for (final int j : XUHelper.getInventorySideSlots(inv, side)) {
                if (((j != i && inv.getStackInSlot(j) == null) || (j == i && item.stackSize == 1)) && inv.isItemValidForSlot(j, t) && (!(inv instanceof ISidedInventory) || ((ISidedInventory)inv).canInsertItem(i, t, side))) {
                    return i;
                }
            }
        }
    }
    return -1;
}
项目:ExtraUtilities    文件:TNHelper.java   
public static boolean isValidTileEntity(final TileEntity inv, final int side) {
    if (inv == null) {
        return false;
    }
    final ForgeDirection forgeSide = ForgeDirection.getOrientation(side);
    final String classname = inv.getClass().toString();
    if (classname.contains("thermalexpansion") && classname.contains("conduit")) {
        return false;
    }
    if (inv instanceof IFluidHandler) {
        final FluidTankInfo[] t = ((IFluidHandler)inv).getTankInfo(forgeSide);
        if (t != null && t.length != 0) {
            return true;
        }
    }
    if (inv instanceof IInventory && ((IInventory)inv).getSizeInventory() > 0) {
        if (!(inv instanceof ISidedInventory)) {
            return true;
        }
        final int[] t2 = ((ISidedInventory)inv).getAccessibleSlotsFromSide(side);
        if (t2 != null && t2.length != 0) {
            return true;
        }
    }
    return isRFEnergy(inv, forgeSide);
}
项目:4Space-5    文件:InventoryRange.java   
public InventoryRange(IInventory inv, int side)
{
    this.inv = inv;
    this.side = side;
    if(inv instanceof ISidedInventory)
    {
        sidedInv = (ISidedInventory)inv;
        slots = sidedInv.getAccessibleSlotsFromSide(side);
    }
    else
    {
        slots = new int[inv.getSizeInventory()];
        for(int i = 0; i < slots.length; i++)
            slots[i] = i;
    }
}
项目:CrystalMod    文件:ItemUtil.java   
public static int doInsertItem(Object into, ItemStack item, EnumFacing side, boolean insert) {
    if (into == null || ItemStackTools.isNullStack(item)) {
        return 0;
    }
    if (into instanceof ISidedInventory) {
        return ItemUtil.doInsertItemInv((ISidedInventory) into, item, side, insert);
    } else if (into instanceof IInventory) {
        return ItemUtil.doInsertItemInv(getInventory((IInventory) into), item, side, insert);
    } else if (into instanceof IItemHandler){
        IItemHandler handler = (IItemHandler)into;
        int startSize = ItemStackTools.getStackSize(item);
        ItemStack res = ItemHandlerHelper.insertItemStacked(handler, item.copy(), !insert);
        int val = ItemStackTools.isNullStack(res) ? startSize : startSize - ItemStackTools.getStackSize(res);
        return val;
    }

    return 0;
}
项目:Toms-Mod    文件:TomsModUtils.java   
public static IItemHandler getItemHandler(World world, BlockPos pos, EnumFacing side, boolean includeEntities) {
    TileEntity te = world.getTileEntity(pos);
    if (te instanceof IDrawer) {
        return new DrawerWrapper((IDrawer) te);
    } else if (te instanceof IDrawerGroup) {
        return new DrawerGroupWrapper((IDrawerGroup) te);
    } else if (te == null || !te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side)) {
        IInventory inv = includeEntities ? TileEntityHopper.getInventoryAtPosition(world, pos.getX(), pos.getY(), pos.getZ()) : (te instanceof IInventory ? (IInventory) te : null);
        if (inv != null) {
            if (inv instanceof ISidedInventory) {
                return new SidedInvWrapper((ISidedInventory) inv, side);
            } else {
                return new InvWrapper(inv);
            }
        } else
            return null;
    } else {
        return te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);
    }
}
项目:Factorization    文件:TileEntityParaSieve.java   
@Override
public boolean canInsertItem(int slot, ItemStack itemstack, EnumFacing direction) {
    if (slot < filters.length) {
        return true;
    }
    try {
        IInventory target = getRecursiveTarget();
        if (target == null) {
            return true;
        }
        if (target instanceof ISidedInventory) {
            return ((ISidedInventory) target).canInsertItem(slot - filters.length, itemstack, facing_direction) && itemPassesFilter(itemstack);
        }
        return itemPassesFilter(itemstack);
    } finally {
        endRecursion();
    }
}
项目:Factorization    文件:TileEntityParaSieve.java   
@Override
public boolean canExtractItem(int index, ItemStack itemstack, EnumFacing direction) {
    if (index < filters.length) {
        return true;
    }
    try {
        IInventory target = getRecursiveTarget();
        if (target == null) {
            return true;
        }
        if (target instanceof ISidedInventory) {
            return ((ISidedInventory) target).canExtractItem(index - filters.length, itemstack, facing_direction) && itemPassesFilter(itemstack);
        }
        return itemPassesFilter(itemstack);
    } finally {
        endRecursion();
    }
}
项目:Factorization    文件:InvUtil.java   
public static boolean canAccessSlot(IInventory inv, int slot) {
    if (inv instanceof ISidedInventory) {
        ISidedInventory isi = (ISidedInventory) inv;
        //O(n). Ugh.
        for (EnumFacing face : EnumFacing.VALUES) {
            int[] slots = isi.getSlotsForFace(face);
            for (int j = 0; j < slots.length; j++) {
                if (slots[j] == slot) {
                    return true;
                }
            }
        }
    } else {
        return true;
    }
    return false;
}
项目:EnderCore    文件:ItemUtil.java   
public static int doInsertItem(Object into, ItemStack item, ForgeDirection side) {
  if (into == null || item == null) {
    return 0;
  }
  if (into instanceof ISidedInventory) {
    return ItemUtil.doInsertItemInv((ISidedInventory) into, item, side, true);
  } else if (into instanceof IInventory) {
    return ItemUtil.doInsertItemInv(getInventory((IInventory) into), item, side, true);
  } else if (into instanceof IItemDuct) {
    return ItemUtil.doInsertItem((IItemDuct) into, item, side);
  }

  for (IItemReceptor rec : receptors) {
    if (rec.canInsertIntoObject(into, side)) {
      return rec.doInsertItem(into, item, side);
    }
  }

  return 0;
}
项目:EnderCore    文件:ItemUtil.java   
private static int doInsertItemInv(IInventory inv, ItemStack item, ForgeDirection inventorySide, boolean doInsert) {
  final ISidedInventory sidedInv = inv instanceof ISidedInventory ? (ISidedInventory) inv : null;
  ISlotIterator slots;

  if (sidedInv != null) {
    if (inventorySide == null) {
      inventorySide = ForgeDirection.UNKNOWN;
    }
    // Note: This is not thread-safe. Change to getInstance() to constructor when needed (1.8++?).
    slots = sidedSlotter.getInstance(sidedInv.getAccessibleSlotsFromSide(inventorySide.ordinal()));
  } else {
    slots = invSlotter.getInstance(0, inv.getSizeInventory());
  }

  return doInsertItemInv(inv, sidedInv, slots, item, inventorySide, doInsert);
}
项目:ToggleBlocks    文件:TileEntityToggleBlock.java   
private ItemStack getFromInventory(IInventory inventory, int side, ItemStack stack)
{
    if (inventory instanceof ISidedInventory)
        return getFromSidedInventory((ISidedInventory) inventory, side, stack);
    else
    {
        ItemStack result = null;
        int slots = inventory.getSizeInventory();
        for (int slot = 0; slot < slots && result == null; slot++)
        {
            ItemStack inSlot = inventory.getStackInSlot(slot);
            if (inSlot != null && inSlot.isItemEqual(stack) && inSlot.stackSize > 0)
                result = inSlot;
        }
        return result;
    }
}
项目:ToggleBlocks    文件:TileEntityToggleBlock.java   
private ItemStack getTFromInventory(IInventory inventory, int side, String toolType)
{
    if (inventory instanceof ISidedInventory)
        return getTFromSidedInventory((ISidedInventory) inventory, side, toolType);
    else
    {
        ItemStack result = null;
        int slots = inventory.getSizeInventory();
        for (int slot = 0; slot < slots && result == null; slot++)
        {
            ItemStack inSlot = inventory.getStackInSlot(slot);
            if (isItemTool(toolType, inSlot))
                result = inSlot;
        }
        return result;
    }
}
项目:vsminecraft    文件:TransporterUtils.java   
public static boolean isValidAcceptorOnSide(TileEntity tile, ForgeDirection side)
{
    if(tile instanceof ITransmitterTile || !(tile instanceof IInventory))
        return false;

    IInventory inventory = (IInventory)tile;

    if(inventory.getSizeInventory() > 0)
    {
        if(!(inventory instanceof ISidedInventory))
            return true;

        int[] slots = ((ISidedInventory)inventory).getAccessibleSlotsFromSide(side.getOpposite().ordinal());

        return (slots != null && slots.length > 0);
    }
    return false;
}
项目:CCFactoryManager    文件:TileEntityFactoryController.java   
private static boolean isSlotAccessibleFromAnySide(IInventory inventory, int slot) {
    if (inventory instanceof ISidedInventory) {
        ISidedInventory sidedInventory = (ISidedInventory) inventory;
        for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
            int[] accessible = sidedInventory.getAccessibleSlotsFromSide(dir.ordinal());
            for (int i = 0; i < accessible.length; i++) {
                if (accessible[i] == slot) {
                    return true;
                }
            }
        }

        return false;
    }

    return true;
}
项目:SMES    文件:TileEntityRareMetalExtractor.java   
private void outputResult() {
    // Check all sides if output side
    for (int i = 0; i < 6; i++) {
        if (this.getSideConfig(i) == 2) {
            // Grab the adjecent tile at the output side
            TileEntity adjecent = BlockHelper.getAdjacentTileEntity(this, i);

            // Check if the adjecent tile entity is an inventory (IIventory, ISidedInventory or IItemDuct)
            if (adjecent instanceof IInventory || adjecent instanceof ISidedInventory || adjecent instanceof IItemDuct) {
                // Try to output into the inventory
                if (InventoryHelper.isInsertion(adjecent)) {
                    ItemStack notInserted = InventoryHelper.addToInsertion(adjecent, i, this.getInventory()[1]);
                    this.getInventory()[1] = notInserted;
                }
            }
        }
    }
}
项目:OpenPeripheral-Integration    文件:AdapterInventory.java   
@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();
}
项目:BluePower    文件:IOHelper.java   
public static ItemStack extractOneItem(TileEntity tile, ForgeDirection dir) {

    if (tile instanceof IInventory) {
        IInventory inv = (IInventory) tile;
        int[] accessibleSlots;
        if (inv instanceof ISidedInventory) {
            accessibleSlots = ((ISidedInventory) inv).getAccessibleSlotsFromSide(dir.ordinal());
        } else {
            accessibleSlots = new int[inv.getSizeInventory()];
            for (int i = 0; i < accessibleSlots.length; i++)
                accessibleSlots[i] = i;
        }
        for (int slot : accessibleSlots) {
            ItemStack stack = inv.getStackInSlot(slot);
            if (stack != null && IOHelper.canExtractItemFromInventory(inv, stack, slot, dir.ordinal())) {
                ItemStack ret = stack.splitStack(1);
                if (stack.stackSize == 0) inv.setInventorySlotContents(slot, null);
                tile.markDirty();
                return ret;
            }
        }
    }
    return null;
}
项目:BluePower    文件: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 {
        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;
}
项目:PeripheralsPlusPlus    文件:Util.java   
public static List<Integer> buildInventorySlotWhitelist(IInventory inv) {
    List<Integer> ret = new ArrayList<Integer>(inv.getSizeInventory());

    if (inv instanceof ISidedInventory) {
        ISidedInventory sidedinv = (ISidedInventory)inv;

        for (int i = 0; i < 6; i++) {
            int[] slots = sidedinv.getAccessibleSlotsFromSide(i);
            for (int j = 0; j < slots.length; j++) {
                ret.add(j);
            }
        }

        if (inv instanceof TileEntityFurnace) { // special case for furnace exploit
            ret.remove(2);
        }
    } else {
        for (int i = 0; i < inv.getSizeInventory(); i++) {
            ret.add(i);
        }
    }

    return ret;
}
项目:PowerAdvantageAPI    文件:TileEntityConveyorFilter.java   
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;
    }
}
项目:PowerAdvantageAPI    文件:TileEntityConveyorFilter.java   
private void dropItem(TileEntity target) {
    World w = getWorld();
    IBlockState bs = w.getBlockState(getPos().down());
    if(target == null && !(bs.getMaterial().blocksMovement())){
        // drop item in the air
        EntityItem ie = new EntityItem(w,getPos().getX()+0.5,getPos().getY()-0.5,getPos().getZ()+0.5,getInventory()[0]);
        ie.motionX = 0;
        ie.motionZ = 0;
        ie.motionY = 0;
        w.spawnEntityInWorld(ie);
        getInventory()[0] = null;
        transferCooldown = transferInvterval;
        this.markDirty();
    } else if(target instanceof IInventory){
        // add item to inventory
        EnumFacing myDir = EnumFacing.DOWN;
        EnumFacing theirDir = EnumFacing.UP;
        BlockPos targetPos = target.getPos();
        ISidedInventory targetInv = InventoryWrapper.wrap(TileEntityHopper.getInventoryAtPosition(getWorld(),targetPos.getX(), targetPos.getY(), targetPos.getZ()));
        if(transferItem(this,myDir,targetInv,theirDir)){
            transferCooldown = transferInvterval;
            this.markDirty();
        }
    }
}
项目:PowerAdvantageAPI    文件:TileEntityConveyor.java   
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;
}
项目:PowerAdvantageAPI    文件:TileEntityOverflowFilter.java   
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;
    }
}
项目:R0b0ts    文件:InventoryHelper.java   
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;
    }
项目:RuneCraftery    文件:TileEntityHopper.java   
public static ItemStack func_94117_a(IInventory p_94117_0_, ItemStack p_94117_1_, int p_94117_2_) {
   if(p_94117_0_ instanceof ISidedInventory && p_94117_2_ > -1) {
      ISidedInventory var6 = (ISidedInventory)p_94117_0_;
      int[] var7 = var6.func_94128_d(p_94117_2_);

      for(int var5 = 0; var5 < var7.length && p_94117_1_ != null && p_94117_1_.field_77994_a > 0; ++var5) {
         p_94117_1_ = func_102014_c(p_94117_0_, p_94117_1_, var7[var5], p_94117_2_);
      }
   } else {
      int var3 = p_94117_0_.func_70302_i_();

      for(int var4 = 0; var4 < var3 && p_94117_1_ != null && p_94117_1_.field_77994_a > 0; ++var4) {
         p_94117_1_ = func_102014_c(p_94117_0_, p_94117_1_, var4, p_94117_2_);
      }
   }

   if(p_94117_1_ != null && p_94117_1_.field_77994_a == 0) {
      p_94117_1_ = null;
   }

   return p_94117_1_;
}
项目:Gizmos    文件:TileEntityInventoryMultiplexer.java   
public void updateCachedData() {
    ArrayList<InvInt> invs=new ArrayList<InvInt>(6);
    for(ForgeDirection dir:ForgeDirection.VALID_DIRECTIONS) {
        if(dir.ordinal() != worldObj.getBlockMetadata(xCoord, yCoord, zCoord)) {
            InvInt ii=new InvInt();
            ISidedInventory neighbour=SidedInventory.get(worldObj.getTileEntity(xCoord+dir.offsetX, yCoord+dir.offsetY, zCoord+dir.offsetZ));
            if(neighbour != null) {
                ii.inv=neighbour;
                ii.direction=dir;
                invs.add(ii);
            }
        }
    }
    invs.trimToSize();
    this.cachedData=invs;
    this.tick=MinecraftServer.getServer().getTickCounter();
}
项目:PneumaticCraft    文件:PneumaticCraftUtils.java   
/**
 * Returns a set of integers of slots that are accessible for the given sides.
 * @param inventory
 * @param accessibleSides a boolean[6], representing for each of the sides if it is accessible or not.
 * @return
 */
public static Set<Integer> getAccessibleSlotsForInventoryAndSides(IInventory inventory, boolean[] accessibleSides){
    Set<Integer> slots = new HashSet<Integer>();
    if(inventory instanceof ISidedInventory) {
        for(int i = 0; i < accessibleSides.length; i++) {
            if(accessibleSides[i]) {
                int[] accessibleSlots = ((ISidedInventory)inventory).getAccessibleSlotsFromSide(i);
                for(int accessibleSlot : accessibleSlots) {
                    slots.add(accessibleSlot);
                }
            }
        }
    } else {
        for(boolean bool : accessibleSides) {
            if(bool) {
                for(int i = 0; i < inventory.getSizeInventory(); i++) {
                    slots.add(i);
                }
                break;
            }
        }
    }
    return slots;
}
项目:PneumaticCraft    文件:IOHelper.java   
public static int[] getAccessibleSlotsForInventory(IInventory inv, ForgeDirection side){

        int[] accessibleSlots;
        if(inv != null) {
            if(inv instanceof ISidedInventory) {
                accessibleSlots = ((ISidedInventory)inv).getAccessibleSlotsFromSide(side.ordinal());
            } else {
                accessibleSlots = new int[inv.getSizeInventory()];
                for(int i = 0; i < accessibleSlots.length; i++)
                    accessibleSlots[i] = i;
            }
            return accessibleSlots;
        } else {
            return new int[0];
        }
    }
项目: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;
    }
项目:RefinedRelocation    文件:RelocatorModuleStock.java   
public int getAmountOfItemsInInventory(IInventory inventory, int side, ItemStack stack)
{
    int amount = 0;
    if (inventory instanceof ISidedInventory)
    {
        int[] accessibleSlots = ((ISidedInventory) inventory).getAccessibleSlotsFromSide(side);
        for (int slot : accessibleSlots)
        {
            amount += getAmountOfItemsInSlot(inventory, slot, stack);
        }
    }
    else
    {
        for (int slot = 0; slot < inventory.getSizeInventory(); slot++)
        {
            amount += getAmountOfItemsInSlot(inventory, slot, stack);
        }
    }
    return amount;
}
项目:interactionwheel    文件:InventoryHelper.java   
/**
 * Merges provided ItemStack with the first available one in this inventory. It will return the amount
 * of items that could not be merged. Also fills the undo buffer in case you want to undo the operation.
 * This version also checks for ISidedInventory if that's implemented by the inventory
 */
public static int mergeItemStackSafe(IInventory inventory, EnumFacing side, ItemStack result, int start, int stop, Map<Integer,ItemStack> undo) {
    if (inventory instanceof ISidedInventory) {
        return mergeItemStackInternal(inventory, (ISidedInventory) inventory, side, result, start, stop, undo);
    } else {
        return mergeItemStackInternal(inventory, null, side, result, start, stop, undo);
    }
}
项目:DecompiledMinecraft    文件:TileEntityHopper.java   
/**
 * Returns false if the inventory has any room to place items in
 */
private boolean isInventoryFull(IInventory inventoryIn, EnumFacing side)
{
    if (inventoryIn instanceof ISidedInventory)
    {
        ISidedInventory isidedinventory = (ISidedInventory)inventoryIn;
        int[] aint = isidedinventory.getSlotsForFace(side);

        for (int k = 0; k < aint.length; ++k)
        {
            ItemStack itemstack1 = isidedinventory.getStackInSlot(aint[k]);

            if (itemstack1 == null || itemstack1.stackSize != itemstack1.getMaxStackSize())
            {
                return false;
            }
        }
    }
    else
    {
        int i = inventoryIn.getSizeInventory();

        for (int j = 0; j < i; ++j)
        {
            ItemStack itemstack = inventoryIn.getStackInSlot(j);

            if (itemstack == null || itemstack.stackSize != itemstack.getMaxStackSize())
            {
                return false;
            }
        }
    }

    return true;
}
项目:DecompiledMinecraft    文件:TileEntityHopper.java   
/**
 * Returns false if the specified IInventory contains any items
 */
private static boolean isInventoryEmpty(IInventory inventoryIn, EnumFacing side)
{
    if (inventoryIn instanceof ISidedInventory)
    {
        ISidedInventory isidedinventory = (ISidedInventory)inventoryIn;
        int[] aint = isidedinventory.getSlotsForFace(side);

        for (int i = 0; i < aint.length; ++i)
        {
            if (isidedinventory.getStackInSlot(aint[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;
}