Better perf for merging

This commit is contained in:
Raoul Van den Berge
2016-05-20 14:00:44 +02:00
parent 90994bc5a4
commit b1aff2389d
2 changed files with 17 additions and 19 deletions

View File

@@ -73,7 +73,8 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
private List<WirelessGridConsumer> wirelessGridConsumers = new ArrayList<WirelessGridConsumer>();
private List<WirelessGridConsumer> wirelessGridConsumersToRemove = new ArrayList<WirelessGridConsumer>();
private List<Integer> combinedGroups = new ArrayList<Integer>();
private Set<Integer> combinedGroupsIndices = new HashSet<Integer>();
private List<ItemGroup> combinedGroups = new ArrayList<ItemGroup>();
private RedstoneMode redstoneMode = RedstoneMode.IGNORE;
@@ -127,12 +128,10 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
}
for (TileMachine machine : machines) {
if (!machine.mayUpdate()) {
continue;
}
if (machine.mayUpdate()) {
machine.updateMachine();
}
}
for (ICraftingTask taskToCancel : craftingTasksToCancel) {
taskToCancel.onCancelled(this);
@@ -329,40 +328,39 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
}
combinedGroups.clear();
combinedGroupsIndices.clear();
for (int i = 0; i < itemGroups.size(); ++i) {
ItemGroup group = itemGroups.get(i);
if (combinedGroups.contains(i)) {
if (combinedGroupsIndices.contains(i)) {
continue;
}
ItemGroup group = itemGroups.get(i);
// If the item doesn't exist anymore, remove it from storage to avoid crashes
if (group.getType() == null) {
combinedGroups.add(i);
combinedGroups.add(group);
combinedGroupsIndices.add(i);
} else {
for (int j = i + 1; j < itemGroups.size(); ++j) {
ItemGroup otherGroup = itemGroups.get(j);
if (combinedGroups.contains(j)) {
if (combinedGroupsIndices.contains(j)) {
continue;
}
ItemGroup otherGroup = itemGroups.get(j);
if (group.compareNoQuantity(otherGroup)) {
// We copy here so we don't modify the quantity of the item group IStorage uses
itemGroups.set(i, group.copy(group.getQuantity() + otherGroup.getQuantity()));
combinedGroups.add(j);
combinedGroups.add(otherGroup);
combinedGroupsIndices.add(j);
}
}
}
}
Collections.sort(combinedGroups, Collections.reverseOrder());
for (int i : combinedGroups) {
itemGroups.remove(i);
}
itemGroups.removeAll(combinedGroups);
}
public boolean push(ItemStack stack) {

View File

@@ -60,7 +60,7 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
if (inventory.getStackInSlot(i) != null) {
items.add(new ItemGroup(inventory.getStackInSlot(i)));
items.add(new ItemGroup(inventory.getStackInSlot(i).copy()));
}
}
}