net.minecraft.inventory.ISidedInventory Java Examples

The following examples show how to use net.minecraft.inventory.ISidedInventory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AdapterInventory.java    From OpenPeripheral-Integration with MIT License 6 votes vote down vote up
@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();
}
 
Example #2
Source File: InventoryRange.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
public InventoryRange(IInventory inv, int side)
{
    this.inv = inv;
    this.face = EnumFacing.values()[side];
    if(inv instanceof ISidedInventory)
    {
        sidedInv = (ISidedInventory)inv;
        slots = sidedInv.getSlotsForFace(face);
    }
    else
    {
        slots = new int[inv.getSizeInventory()];
        for(int i = 0; i < slots.length; i++)
            slots[i] = i;
    }
}
 
Example #3
Source File: PneumaticCraftUtils.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: IOHelper.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
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];
        }
    }
 
Example #5
Source File: IOHelper.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
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;
    }
 
Example #6
Source File: InventoryRange.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public InventoryRange(IInventory inv, Direction side) {
    this.inv = inv;
    this.face = side;
    if (inv instanceof ISidedInventory) {
        sidedInv = (ISidedInventory) inv;
        slots = sidedInv.getSlotsForFace(face);
    } else {
        slots = new int[inv.getSizeInventory()];
        for (int i = 0; i < slots.length; i++) {
            slots[i] = i;
        }
    }
}
 
Example #7
Source File: InventoryRange.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public InventoryRange(IInventory inv, InventoryRange access) {
    this.inv = inv;
    this.slots = access.slots;
    this.face = access.face;
    if (inv instanceof ISidedInventory) {
        sidedInv = (ISidedInventory) inv;
    }
}
 
Example #8
Source File: PyCodeBlockTileEntity.java    From pycode-minecraft with MIT License 5 votes vote down vote up
private static boolean isInventoryEmpty(IInventory inventoryIn, EnumFacing side)
{
    if (inventoryIn instanceof ISidedInventory)
    {
        ISidedInventory isidedinventory = (ISidedInventory)inventoryIn;
        int[] aint = isidedinventory.getSlotsForFace(side);

        for (int i : aint)
        {
            if (isidedinventory.getStackInSlot(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;
}
 
Example #9
Source File: InventoryRange.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public InventoryRange(IInventory inv, InventoryRange access)
{
    this.inv = inv;
    this.slots = access.slots;
    this.face = access.face;
    if(inv instanceof ISidedInventory)
        sidedInv = (ISidedInventory) inv;
}
 
Example #10
Source File: InventoryUtils.java    From OpenModsLib with MIT License 5 votes vote down vote up
public static IItemHandler tryGetHandler(TileEntity te, EnumFacing side) {
	if (te == null) return null;

	if (te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side))
		return te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side);

	if (te instanceof ISidedInventory)
		return new SidedInvWrapper((ISidedInventory)te, side);

	if (te instanceof IInventory)
		return new InvWrapper((IInventory)te);

	return null;
}
 
Example #11
Source File: CorporeaHelper.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 4 votes vote down vote up
/**
 * Gets if the slot passed in can be extracted from by a spark.
 */
public static boolean isValidSlot(IInventory inv, int slot) {
	return !(inv instanceof ISidedInventory) || arrayHas(((ISidedInventory) inv).getAccessibleSlotsFromSide(ForgeDirection.UP.ordinal()), slot) && ((ISidedInventory) inv).canExtractItem(slot, inv.getStackInSlot(slot), ForgeDirection.UP.ordinal());
}
 
Example #12
Source File: IOHelper.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public static boolean canInterfaceWith(TileEntity tile, ForgeDirection direction){
    if(tile instanceof IInventory) {
        return !(tile instanceof ISidedInventory) || ((ISidedInventory)tile).getAccessibleSlotsFromSide(direction.ordinal()).length > 0;
    }
    return false;
}
 
Example #13
Source File: SidedInventoryHelper.java    From BigReactors with MIT License 4 votes vote down vote up
public SidedInventoryHelper(ISidedInventory inventory, ForgeDirection side) {
	super(inventory);
	
	this.sidedInventory = inventory;
	this.side = side;
}
 
Example #14
Source File: ITileStructure.java    From PneumaticCraft with GNU General Public License v3.0 2 votes vote down vote up
/**
 * @return ISidedInventory representing the inventory accessed from this block.
 */
ISidedInventory getStructureInventory();
 
Example #15
Source File: IOHelper.java    From PneumaticCraft with GNU General Public License v3.0 2 votes vote down vote up
public static boolean canInsertItemToInventory(IInventory inventory, ItemStack itemStack, int slot, int side){

        return inventory.isItemValidForSlot(slot, itemStack) && (!(inventory instanceof ISidedInventory) || ((ISidedInventory)inventory).canInsertItem(slot, itemStack, side));
    }
 
Example #16
Source File: IOHelper.java    From PneumaticCraft with GNU General Public License v3.0 2 votes vote down vote up
public static boolean canExtractItemFromInventory(IInventory inventory, ItemStack itemStack, int slot, int side){

        return !(inventory instanceof ISidedInventory) || ((ISidedInventory)inventory).canExtractItem(slot, itemStack, side);
    }