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

下面列出了怎么用net.minecraft.inventory.ISidedInventory的API类实例代码及写法,或者点击链接到github查看源代码。

@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();
}
 
源代码2 项目: CodeChickenLib   文件: InventoryRange.java
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;
    }
}
 
源代码3 项目: 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;
}
 
源代码4 项目: 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];
        }
    }
 
源代码5 项目: 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;
    }
 
源代码6 项目: CodeChickenLib   文件: InventoryRange.java
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;
        }
    }
}
 
源代码7 项目: CodeChickenLib   文件: InventoryRange.java
public InventoryRange(IInventory inv, InventoryRange access) {
    this.inv = inv;
    this.slots = access.slots;
    this.face = access.face;
    if (inv instanceof ISidedInventory) {
        sidedInv = (ISidedInventory) inv;
    }
}
 
源代码8 项目: pycode-minecraft   文件: PyCodeBlockTileEntity.java
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;
}
 
源代码9 项目: CodeChickenLib   文件: InventoryRange.java
public InventoryRange(IInventory inv, InventoryRange access)
{
    this.inv = inv;
    this.slots = access.slots;
    this.face = access.face;
    if(inv instanceof ISidedInventory)
        sidedInv = (ISidedInventory) inv;
}
 
源代码10 项目: OpenModsLib   文件: InventoryUtils.java
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;
}
 
源代码11 项目: ForbiddenMagic   文件: CorporeaHelper.java
/**
 * 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());
}
 
源代码12 项目: PneumaticCraft   文件: IOHelper.java
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;
}
 
源代码13 项目: BigReactors   文件: SidedInventoryHelper.java
public SidedInventoryHelper(ISidedInventory inventory, ForgeDirection side) {
	super(inventory);
	
	this.sidedInventory = inventory;
	this.side = side;
}
 
源代码14 项目: PneumaticCraft   文件: ITileStructure.java
/**
 * @return ISidedInventory representing the inventory accessed from this block.
 */
ISidedInventory getStructureInventory();
 
源代码15 项目: PneumaticCraft   文件: IOHelper.java
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));
    }
 
源代码16 项目: PneumaticCraft   文件: IOHelper.java
public static boolean canExtractItemFromInventory(IInventory inventory, ItemStack itemStack, int slot, int side){

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