use of net.minecraft.inventory.ISidedInventory in project LogisticsPipes by RS485.
the class ModuleApiaristRefiller method tick.
@Override
public void tick() {
if (++currentTickCount < ticksToOperation) {
return;
}
currentTickCount = 0;
IInventory inv = _service.getRealInventory();
if (!(inv instanceof ISidedInventory)) {
return;
}
ISidedInventory sinv = (ISidedInventory) inv;
ForgeDirection direction = _service.inventoryOrientation().getOpposite();
ItemStack stack = extractItem(sinv, false, direction, 1);
if (stack == null) {
return;
}
if (!(_service.canUseEnergy(100))) {
return;
}
currentTickCount = ticksToOperation;
if (reinsertBee(stack, sinv, direction)) {
return;
}
Pair<Integer, SinkReply> reply = _service.hasDestination(ItemIdentifier.get(stack), true, new ArrayList<>());
if (reply == null) {
return;
}
_service.useEnergy(20);
extractItem(sinv, true, direction, 1);
_service.sendStack(stack, reply, ItemSendMode.Normal);
}
use of net.minecraft.inventory.ISidedInventory in project ArsMagica2 by Mithion.
the class InventoryUtilities method getFirstStackStartingFromSlot.
public static GetFirstStackStartingFromSlotResult getFirstStackStartingFromSlot(IInventory inventory, ItemStack itemStack, int slot, int side) {
if (inventory instanceof ISidedInventory) {
ISidedInventory sidededInventory = (ISidedInventory) inventory;
int[] slots = sidededInventory.getAccessibleSlotsFromSide(side);
for (int i = slot; i < slots.length; i++) {
itemStack = inventory.getStackInSlot(slots[i]);
if (itemStack != null && canExtractItemFromInventory(sidededInventory, itemStack, slots[i], side)) {
return new GetFirstStackStartingFromSlotResult(i, itemStack);
}
}
} else {
return getFirstStackStartingFromSlot(inventory, itemStack, slot);
}
return new GetFirstStackStartingFromSlotResult(-1, null);
}
use of net.minecraft.inventory.ISidedInventory in project ArsMagica2 by Mithion.
the class InventoryUtilities method inventoryHasItem.
public static boolean inventoryHasItem(IInventory inventory, ItemStack search, int quantity, int side) {
if (inventory instanceof ISidedInventory) {
ISidedInventory sidedInventory = (ISidedInventory) inventory;
int qtyFound = 0;
int[] slots = sidedInventory.getAccessibleSlotsFromSide(side);
for (int i = 0; i < slots.length; i++) {
ItemStack inventoryStack = inventory.getStackInSlot(slots[i]);
if (inventoryStack == null)
continue;
else if (compareItemStacks(inventoryStack, search, true, false, true, true)) {
qtyFound += inventoryStack.stackSize;
if (qtyFound >= quantity)
return true;
}
}
return false;
} else {
return inventoryHasItem(inventory, search, quantity);
}
}
use of net.minecraft.inventory.ISidedInventory in project ArsMagica2 by Mithion.
the class InventoryUtilities method mergeIntoInventory.
public static boolean mergeIntoInventory(IInventory inventory, ItemStack toMerge, int quantity, int side) {
if (inventory instanceof ISidedInventory) {
ItemStack stack = toMerge.splitStack(Math.min(toMerge.stackSize, quantity));
ISidedInventory sidedInventory = (ISidedInventory) inventory;
int[] slots = sidedInventory.getAccessibleSlotsFromSide(side);
boolean flag = false;
for (int i = 0; i < slots.length && stack != null && stack.stackSize > 0; ++i) {
//For each slot that can be accessed from this side
ItemStack prvStack = sidedInventory.getStackInSlot(slots[i]);
if (InventoryUtilities.canInsertItemToInventory(sidedInventory, stack, slots[i], side)) {
//if the items can be inserted into the current slot
if (prvStack == null) {
//if the stack in the slot is null then get the max value that can be moved and transfer the stack to the inventory
int max = Math.min(stack.getMaxStackSize(), sidedInventory.getInventoryStackLimit());
if (max >= stack.stackSize) {
sidedInventory.setInventorySlotContents(slots[i], stack.copy());
stack.stackSize = 0;
flag = true;
} else {
sidedInventory.setInventorySlotContents(slots[i], stack.splitStack(max));
flag = true;
}
} else if (InventoryUtilities.canStacksMerge(prvStack, stack)) {
//if the stack in the slot can be merged with the stack we are trying to move get the max items that can exist in the slot
//and insert as many as will fit from the stack we are trying to move
int max = Math.min(stack.getMaxStackSize(), sidedInventory.getInventoryStackLimit());
if (max > prvStack.stackSize) {
int qty = Math.min(stack.stackSize, max - prvStack.stackSize);
prvStack.stackSize += qty;
stack.stackSize -= qty;
flag = qty > 0;
}
}
}
}
toMerge.stackSize = toMerge.stackSize + stack.stackSize;
return flag;
} else {
return mergeIntoInventory(inventory, toMerge, quantity);
}
}
use of net.minecraft.inventory.ISidedInventory in project ArsMagica2 by Mithion.
the class InventoryUtilities method getLikeItemCount.
public static int getLikeItemCount(IInventory inventory, ItemStack stack, int side) {
if (inventory instanceof ISidedInventory) {
int totalCount = 0;
ISidedInventory sidedInventory = (ISidedInventory) inventory;
int[] slots = sidedInventory.getAccessibleSlotsFromSide(side);
for (int i = 0; i < slots.length; i++) {
ItemStack invStack = inventory.getStackInSlot(slots[i]);
if (invStack != null && compareItemStacks(invStack, stack, true, false, true, true))
totalCount += invStack.stackSize;
}
return totalCount;
} else {
return getLikeItemCount(inventory, stack);
}
}
Aggregations