Performance improvements to grids

This commit is contained in:
Raoul Van den Berge
2016-05-24 23:33:45 +02:00
parent b3bd96d9e1
commit a433532fe8
3 changed files with 15 additions and 5 deletions

View File

@@ -6,6 +6,7 @@
- Fixed going out of crafting GUI not restoring state (scrollbar and search term)
- Fixed not being able to create a pattern in disconnected Pattern Grid
- Fixed not being able to place cake or string
- Performance improvements to Grids
### 0.7
**Bugfixes**

View File

@@ -100,7 +100,7 @@ public class GuiGrid extends GuiBase {
while (t.hasNext()) {
ItemGroup group = t.next();
if (!group.toStack().getDisplayName().toLowerCase().contains(searchField.getText().toLowerCase())) {
if (!group.toCachedStack().getDisplayName().toLowerCase().contains(searchField.getText().toLowerCase())) {
t.remove();
}
}
@@ -110,9 +110,9 @@ public class GuiGrid extends GuiBase {
@Override
public int compare(ItemGroup left, ItemGroup right) {
if (grid.getSortingDirection() == TileGrid.SORTING_DIRECTION_ASCENDING) {
return right.toStack().getDisplayName().compareTo(left.toStack().getDisplayName());
return right.toCachedStack().getDisplayName().compareTo(left.toCachedStack().getDisplayName());
} else if (grid.getSortingDirection() == TileGrid.SORTING_DIRECTION_DESCENDING) {
return left.toStack().getDisplayName().compareTo(right.toStack().getDisplayName());
return left.toCachedStack().getDisplayName().compareTo(right.toCachedStack().getDisplayName());
}
return 0;
@@ -259,7 +259,7 @@ public class GuiGrid extends GuiBase {
text = String.valueOf(qty);
}
drawItem(x, y, items.get(slot).toStack(), true, text);
drawItem(x, y, items.get(slot).toCachedStack(), true, text);
}
if (inBounds(x, y, 16, 16, mouseX, mouseY) || !grid.isConnected()) {
@@ -287,7 +287,7 @@ public class GuiGrid extends GuiBase {
}
if (isHoveringOverItemInSlot()) {
drawTooltip(mouseX, mouseY, items.get(hoveringSlot).toStack());
drawTooltip(mouseX, mouseY, items.get(hoveringSlot).toCachedStack());
}
if (isHoveringOverClear(mouseX, mouseY)) {

View File

@@ -14,6 +14,7 @@ public class ItemGroup {
private NBTTagCompound tag;
// Used clientside
private int id;
private ItemStack cachedStack;
public ItemGroup(ByteBuf buf) {
this.id = buf.readInt();
@@ -165,4 +166,12 @@ public class ItemGroup {
return stack;
}
public ItemStack toCachedStack() {
if (cachedStack == null) {
cachedStack = toStack();
}
return cachedStack;
}
}