use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.
the class LogisticsCraftingTable method importFuzzyFlags.
@Override
public void importFuzzyFlags(TileEntity tile, ItemIdentifierInventory inventory, DictResource[] flags, DictResource output) {
if (!(tile instanceof LogisticsCraftingTableTileEntity)) {
return;
}
LogisticsCraftingTableTileEntity bench = (LogisticsCraftingTableTileEntity) tile;
if (!bench.isFuzzy()) {
return;
}
for (int i = 0; i < bench.fuzzyFlags.length; i++) {
if (i >= flags.length) {
break;
}
flags[i].loadFromBitSet(bench.fuzzyFlags[i].getBitSet());
}
output.loadFromBitSet(bench.outputFuzzyFlags.getBitSet());
for (int i = 0; i < 9; i++) {
final ItemIdentifierStack stackInSlot = inventory.getIDStackInSlot(i);
if (stackInSlot == null) {
continue;
}
final ItemIdentifier itemInSlot = stackInSlot.getItem();
for (int j = i + 1; j < 9; j++) {
final ItemIdentifierStack stackInOtherSlot = inventory.getIDStackInSlot(j);
if (stackInOtherSlot == null) {
continue;
}
if (itemInSlot.equals(stackInOtherSlot.getItem()) && flags[i].getBitSet().equals(flags[j].getBitSet())) {
stackInSlot.setStackSize(stackInSlot.getStackSize() + stackInOtherSlot.getStackSize());
inventory.clearInventorySlotContents(j);
// clear
flags[j].loadFromBitSet(new BitSet());
}
}
inventory.setInventorySlotContents(i, stackInSlot);
}
for (int i = 0; i < 9; i++) {
if (inventory.getStackInSlot(i) != null) {
continue;
}
for (int j = i + 1; j < 9; j++) {
if (inventory.getStackInSlot(j) == null) {
continue;
}
inventory.setInventorySlotContents(i, inventory.getStackInSlot(j));
flags[i].loadFromBitSet(flags[j].getBitSet());
inventory.clearInventorySlotContents(j);
// clear
flags[j].loadFromBitSet(new BitSet());
break;
}
}
return;
}
use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.
the class ItemAmountPipeSign method spread.
private void spread(Map<ItemIdentifier, Integer> availableItems, BitSet set) {
// Improve performance by updating a wall of Amount pipe signs all at once
IRouter router = pipe.getRouter();
if (set.get(router.getSimpleID()))
return;
set.set(router.getSimpleID());
for (ExitRoute exit : router.getIRoutersByCost()) {
// Only when the signs are in one wall. To not spread to far.
if (exit.distanceToDestination > 2)
break;
if (!exit.filters.isEmpty())
continue;
if (set.get(exit.destination.getSimpleID()))
continue;
if (exit.connectionDetails.contains(PipeRoutingConnectionType.canRequestFrom) && exit.connectionDetails.contains(PipeRoutingConnectionType.canRouteTo)) {
CoreRoutedPipe cachedPipe = exit.destination.getCachedPipe();
if (cachedPipe != null) {
List<Pair<ForgeDirection, IPipeSign>> pipeSigns = cachedPipe.getPipeSigns();
pipeSigns.stream().filter(signPair -> signPair != null && signPair.getValue2() instanceof ItemAmountPipeSign).forEach(signPair -> ((ItemAmountPipeSign) signPair.getValue2()).updateStats(availableItems, set));
}
}
}
}
use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.
the class ItemAmountPipeSign method updateServerSide.
@Override
public void updateServerSide() {
if (!pipe.isNthTick(20)) {
return;
}
if (hasUpdated) {
hasUpdated = false;
return;
}
int newAmount = 0;
if (itemTypeInv.getIDStackInSlot(0) != null) {
Map<ItemIdentifier, Integer> availableItems = SimpleServiceLocator.logisticsManager.getAvailableItems(pipe.getRouter().getIRoutersByCost());
if (availableItems != null) {
BitSet set = new BitSet(ServerRouter.getBiggestSimpleID());
spread(availableItems, set);
if (availableItems.containsKey(itemTypeInv.getIDStackInSlot(0).getItem())) {
newAmount = availableItems.get(itemTypeInv.getIDStackInSlot(0).getItem());
}
}
}
if (newAmount != amount) {
amount = newAmount;
sendUpdatePacket();
}
}
use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.
the class AssemblyAdvancedWorkbench method importRecipe.
@Override
public boolean importRecipe(TileEntity tile, ItemIdentifierInventory inventory) {
if (!(tile instanceof TileAdvancedCraftingTable)) {
return false;
}
TileAdvancedCraftingTable bench = (TileAdvancedCraftingTable) tile;
ItemStack result = bench.getOutputSlot().getStackInSlot(0);
if (result == null) {
return false;
}
inventory.setInventorySlotContents(9, result);
// Import
for (int i = 0; i < bench.getCraftingSlots().getSizeInventory(); i++) {
if (i >= inventory.getSizeInventory() - 2) {
break;
}
final ItemStack newStack = bench.getCraftingSlots().getStackInSlot(i) == null ? null : bench.getCraftingSlots().getStackInSlot(i).copy();
inventory.setInventorySlotContents(i, newStack);
}
// Compact
for (int i = 0; i < inventory.getSizeInventory() - 2; i++) {
final ItemIdentifierStack stackInSlot = inventory.getIDStackInSlot(i);
if (stackInSlot == null) {
continue;
}
final ItemIdentifier itemInSlot = stackInSlot.getItem();
for (int j = i + 1; j < inventory.getSizeInventory() - 2; j++) {
final ItemIdentifierStack stackInOtherSlot = inventory.getIDStackInSlot(j);
if (stackInOtherSlot == null) {
continue;
}
if (itemInSlot.equals(stackInOtherSlot.getItem())) {
stackInSlot.setStackSize(stackInSlot.getStackSize() + stackInOtherSlot.getStackSize());
inventory.setInventorySlotContents(i, stackInSlot);
inventory.clearInventorySlotContents(j);
}
}
}
for (int i = 0; i < inventory.getSizeInventory() - 2; i++) {
if (inventory.getStackInSlot(i) != null) {
continue;
}
for (int j = i + 1; j < inventory.getSizeInventory() - 2; j++) {
if (inventory.getStackInSlot(j) == null) {
continue;
}
inventory.setInventorySlotContents(i, inventory.getIDStackInSlot(j));
inventory.clearInventorySlotContents(j);
break;
}
}
return true;
}
use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.
the class AEInterfaceInventoryHandler method getItems.
@Override
public Set<ItemIdentifier> getItems() {
Set<ItemIdentifier> result = new TreeSet<>();
IStorageMonitorable tmp = tile.getMonitorable(dir, source);
if (tmp == null || tmp.getItemInventory() == null || tmp.getItemInventory().getStorageList() == null) {
return result;
}
for (IAEItemStack items : tmp.getItemInventory().getStorageList()) {
ItemIdentifier ident = ItemIdentifier.get(items.getItemStack());
result.add(ident);
}
return result;
}
Aggregations