use of net.minecraft.inventory.IInventory 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.IInventory in project BluePower by Qmunity.
the class TileSortingMachine method triggerSorting.
private void triggerSorting() {
if (isBufferEmpty()) {
ForgeDirection dir = getOutputDirection().getOpposite();
// might need opposite
TileEntity inputTE = getTileCache(dir);
if (inputTE instanceof IInventory) {
IInventory inputInv = (IInventory) inputTE;
int[] accessibleSlots;
if (inputInv instanceof ISidedInventory) {
accessibleSlots = ((ISidedInventory) inputInv).getAccessibleSlotsFromSide(dir.getOpposite().ordinal());
} else {
accessibleSlots = new int[inputInv.getSizeInventory()];
for (int i = 0; i < accessibleSlots.length; i++) accessibleSlots[i] = i;
}
for (int slot : accessibleSlots) {
ItemStack stack = inputInv.getStackInSlot(slot);
if (stack != null && IOHelper.canExtractItemFromInventory(inputInv, stack, slot, dir.getOpposite().ordinal())) {
if (tryProcessItem(stack, false)) {
if (stack.stackSize == 0)
inputInv.setInventorySlotContents(slot, null);
return;
}
}
}
if (sortMode == SortMode.ANYSTACK_SEQUENTIAL) {
for (int i = curColumn; i < inventory.length; i += 8) {
ItemStack filterStack = inventory[i];
if (filterStack != null) {
ItemStack extractedStack = IOHelper.extract(inputTE, dir.getOpposite(), filterStack, true, false);
if (extractedStack != null) {
addItemToOutputBuffer(extractedStack.copy(), colors[curColumn]);
gotoNextNonEmptyColumn();
break;
}
}
}
} else if (sortMode == SortMode.ALLSTACK_SEQUENTIAL) {
if (matchAndProcessColumn(inputInv, accessibleSlots, curColumn)) {
gotoNextNonEmptyColumn();
}
} else if (sortMode == SortMode.RANDOM_ALLSTACKS) {
for (int i = 0; i < 8; i++) {
if (matchAndProcessColumn(inputInv, accessibleSlots, i)) {
break;
}
}
}
}
}
}
use of net.minecraft.inventory.IInventory 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;
}
use of net.minecraft.inventory.IInventory in project LogisticsPipes by RS485.
the class ModuleSatellite method spaceFor.
private int spaceFor(ItemIdentifier item, boolean includeInTransit) {
WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(pipe.container);
//@formatter:off
int count = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).map(adjacent -> {
IInventory inv = (IInventory) adjacent.tileEntity;
if (inv instanceof net.minecraft.inventory.ISidedInventory) {
inv = new SidedInventoryMinecraftAdapter((net.minecraft.inventory.ISidedInventory) inv, adjacent.direction.getOpposite(), false);
}
IInventoryUtil util = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(inv, adjacent.direction);
return util.roomForItem(item, 9999);
}).reduce(Integer::sum).orElse(0);
if (includeInTransit) {
count -= pipe.countOnRoute(item);
}
return count;
}
use of net.minecraft.inventory.IInventory in project LogisticsPipes by RS485.
the class ModuleCrafterMK3 method tick.
@Override
public void tick() {
super.tick();
if (inv.isEmpty()) {
return;
}
if (!_service.isNthTick(6)) {
return;
}
//Add from internal buffer
List<AdjacentTileEntity> crafters = locateCrafters();
boolean change = false;
for (AdjacentTileEntity adjacent : crafters) {
for (int i = inv.getSizeInventory() - 1; i >= 0; i--) {
ItemIdentifierStack slot = inv.getIDStackInSlot(i);
if (slot == null) {
continue;
}
ForgeDirection insertion = adjacent.direction.getOpposite();
if (getUpgradeManager().hasSneakyUpgrade()) {
insertion = getUpgradeManager().getSneakyOrientation();
}
ItemIdentifierStack toadd = slot.clone();
toadd.setStackSize(Math.min(toadd.getStackSize(), toadd.getItem().getMaxStackSize()));
if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING)) {
toadd.setStackSize(Math.min(toadd.getStackSize(), ((IInventory) adjacent.tileEntity).getInventoryStackLimit()));
ItemStack added = InventoryHelper.getTransactorFor(adjacent.tileEntity, adjacent.direction.getOpposite()).add(toadd.makeNormalStack(), insertion, true);
slot.setStackSize(slot.getStackSize() - added.stackSize);
if (added.stackSize != 0) {
change = true;
}
} else {
_service.queueRoutedItem(SimpleServiceLocator.routedItemHelper.createNewTravelItem(toadd), adjacent.direction.getOpposite());
slot.setStackSize(slot.getStackSize() - toadd.getStackSize());
change = true;
}
if (slot.getStackSize() <= 0) {
inv.clearInventorySlotContents(i);
} else {
inv.setInventorySlotContents(i, slot);
}
}
}
if (change) {
inv.markDirty();
_service.getCacheHolder().trigger(CacheTypes.Inventory);
}
}
Aggregations