use of net.minecraft.inventory.ISidedInventory in project BluePower by Qmunity.
the class IOHelper method extract.
public static ItemStack extract(IInventory inventory, ForgeDirection direction, boolean simulate) {
if (inventory instanceof ISidedInventory) {
ISidedInventory isidedinventory = (ISidedInventory) inventory;
int[] accessibleSlotsFromSide = isidedinventory.getAccessibleSlotsFromSide(direction.ordinal());
for (int anAccessibleSlotsFromSide : accessibleSlotsFromSide) {
ItemStack stack = extract(inventory, direction, anAccessibleSlotsFromSide, simulate);
if (stack != null)
return stack;
}
} else {
int j = inventory.getSizeInventory();
for (int k = 0; k < j; ++k) {
ItemStack stack = extract(inventory, direction, k, simulate);
if (stack != null)
return stack;
}
}
return null;
}
use of net.minecraft.inventory.ISidedInventory in project BluePower by Qmunity.
the class IOHelper method extract.
/**
* Retrieves an item from the specified inventory. This item can be specified.
*
* @param tile
* @param direction
* @param requestedStack
* @param useItemCount
* if true, it'll only retrieve the stack of the exact item count given. it'll look in multiple slots of the inventory. if false, the
* first matching stack, ignoring item count, will be returned.
* @param simulate
* @param fuzzySetting
* ,
* @return
*/
public static ItemStack extract(TileEntity tile, ForgeDirection direction, ItemStack requestedStack, boolean useItemCount, boolean simulate, int fuzzySetting) {
if (requestedStack == null)
return requestedStack;
IInventory inv = getInventoryForTE(tile);
if (inv != null) {
int[] accessibleSlots;
if (inv instanceof ISidedInventory) {
accessibleSlots = ((ISidedInventory) inv).getAccessibleSlotsFromSide(direction.ordinal());
} else {
accessibleSlots = new int[inv.getSizeInventory()];
for (int i = 0; i < accessibleSlots.length; i++) accessibleSlots[i] = i;
}
int itemsFound = 0;
for (int slot : accessibleSlots) {
ItemStack stack = inv.getStackInSlot(slot);
if (stack != null && ItemStackHelper.areStacksEqual(stack, requestedStack, fuzzySetting) && IOHelper.canExtractItemFromInventory(inv, requestedStack, slot, direction.ordinal())) {
if (!useItemCount) {
if (!simulate) {
inv.setInventorySlotContents(slot, null);
}
return stack;
}
itemsFound += stack.stackSize;
}
}
if (itemsFound >= requestedStack.stackSize) {
ItemStack exportedStack = null;
int itemsNeeded = requestedStack.stackSize;
for (int slot : accessibleSlots) {
ItemStack stack = inv.getStackInSlot(slot);
if (stack != null && ItemStackHelper.areStacksEqual(stack, requestedStack, fuzzySetting) && IOHelper.canExtractItemFromInventory(inv, requestedStack, slot, direction.ordinal())) {
int itemsSubstracted = Math.min(itemsNeeded, stack.stackSize);
if (itemsSubstracted > 0)
exportedStack = stack;
itemsNeeded -= itemsSubstracted;
if (!simulate) {
stack.stackSize -= itemsSubstracted;
if (stack.stackSize == 0)
inv.setInventorySlotContents(slot, null);
tile.markDirty();
}
}
}
exportedStack = exportedStack.copy();
exportedStack.stackSize = requestedStack.stackSize;
return exportedStack;
}
}
return null;
}
use of net.minecraft.inventory.ISidedInventory in project BluePower by Qmunity.
the class IOHelper method extractOneItem.
public static ItemStack extractOneItem(TileEntity tile, ForgeDirection dir) {
IInventory inv = getInventoryForTE(tile);
if (inv != null) {
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);
ItemStack retrievingStack = stack == null ? null : stack.copy().splitStack(1);
if (stack != null && IOHelper.canExtractItemFromInventory(inv, retrievingStack, slot, dir.ordinal())) {
ItemStack ret = stack.splitStack(1);
if (stack.stackSize == 0)
inv.setInventorySlotContents(slot, null);
tile.markDirty();
return ret;
}
}
}
return null;
}
use of net.minecraft.inventory.ISidedInventory in project BluePower by Qmunity.
the class TileRegulator method updateEntity.
@Override
public void updateEntity() {
super.updateEntity();
if (!worldObj.isRemote && isBufferEmpty()) {
boolean ratiosMatch = true;
for (int i = 0; i < 9; i++) {
if (inventory[i] != null) {
int inputFilterItems = getItemsInSection(inventory[i], EnumSection.INPUT_FILTER);
int bufferItems = getItemsInSection(inventory[i], EnumSection.BUFFER);
if (bufferItems < inputFilterItems) {
ratiosMatch = false;
break;
}
}
}
if (ratiosMatch && !isEjecting())
checkIndividualOutputFilterAndEject();
if (mode == 1 && !isEjecting()) {
// supply mode
IInventory inv = IOHelper.getInventoryForTE(getTileCache(getOutputDirection()));
if (inv != null) {
int[] accessibleSlots;
if (inv instanceof ISidedInventory) {
accessibleSlots = ((ISidedInventory) inv).getAccessibleSlotsFromSide(getFacingDirection().ordinal());
} else {
accessibleSlots = new int[inv.getSizeInventory()];
for (int i = 0; i < accessibleSlots.length; i++) accessibleSlots[i] = i;
}
for (int i = 18; i < 27; i++) {
if (inventory[i] != null) {
int outputFilterItems = getItemsInSection(inventory[i], EnumSection.OUTPUT_FILTER);
int supplyingInvCount = 0;
for (int slot : accessibleSlots) {
ItemStack stackInSlot = inv.getStackInSlot(slot);
if (stackInSlot != null && ItemStackHelper.areStacksEqual(stackInSlot, inventory[i], fuzzySetting) && IOHelper.canInsertItemToInventory(inv, inventory[i], slot, getFacingDirection().ordinal())) {
supplyingInvCount += stackInSlot.stackSize;
}
}
if (supplyingInvCount < outputFilterItems) {
ItemStack requestedStack = inventory[i].copy();
requestedStack.stackSize = outputFilterItems - supplyingInvCount;
// try
ItemStack bufferItems = IOHelper.extract(this, ForgeDirection.UNKNOWN, requestedStack, true, false, fuzzySetting);
// the buffer.
if (bufferItems != null) {
// insert into
ItemStack remainder = IOHelper.insert(inv, bufferItems, getFacingDirection().ordinal(), false);
// supplying inv.
if (remainder != null) {
// when not every item can be supplied, return
IOHelper.insert(this, remainder, ForgeDirection.UNKNOWN, false);
// those to the buffer.
}
}
}
}
}
}
}
boolean shouldEmitRedstone = isSatisfied() || animationTicker >= 0;
if (isEjecting() != shouldEmitRedstone) {
setOutputtingRedstone(shouldEmitRedstone);
sendUpdatePacket();
}
}
}
use of net.minecraft.inventory.ISidedInventory in project LogisticsPipes by RS485.
the class ModuleCrafter method spaceFor.
protected int spaceFor(ItemIdentifier item, boolean includeInTransit) {
Pair<String, ItemIdentifier> key = new Pair<>("spaceFor", item);
Object cache = _service.getCacheHolder().getCacheFor(CacheTypes.Inventory, key);
if (cache != null) {
int count = (Integer) cache;
if (includeInTransit) {
count -= _service.countOnRoute(item);
}
return count;
}
WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(getWorld(), _service.getX(), _service.getY(), _service.getZ());
//@formatter:off
int count = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).map(adjacent -> new Pair<>((IInventory) adjacent.tileEntity, adjacent.direction)).map(invDirPair -> {
if (invDirPair.getValue1() instanceof ISidedInventory) {
invDirPair.setValue1(new SidedInventoryMinecraftAdapter((ISidedInventory) invDirPair.getValue1(), invDirPair.getValue2().getOpposite(), false));
}
if (getUpgradeManager().hasSneakyUpgrade()) {
invDirPair.setValue2(getUpgradeManager().getSneakyOrientation());
}
IInventoryUtil inv = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(invDirPair.getValue1(), invDirPair.getValue2());
return inv.roomForItem(item, 9999);
}).reduce(Integer::sum).orElse(0);
_service.getCacheHolder().setCache(CacheTypes.Inventory, key, count);
if (includeInTransit) {
count -= _service.countOnRoute(item);
}
return count;
}
Aggregations