Fixed crash when quickly toggling sorting direction in Grid, fixes #186
This commit is contained in:
@@ -14,7 +14,7 @@ import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import refinedstorage.apiimpl.storage.ClientStack;
|
||||
import refinedstorage.gui.grid.ClientStack;
|
||||
import refinedstorage.proxy.CommonProxy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.network.IGuiHandler;
|
||||
import refinedstorage.RefinedStorageGui;
|
||||
import refinedstorage.container.*;
|
||||
import refinedstorage.gui.grid.GuiGrid;
|
||||
import refinedstorage.tile.*;
|
||||
import refinedstorage.tile.controller.TileController;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package refinedstorage.apiimpl.storage;
|
||||
package refinedstorage.gui.grid;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -12,12 +12,6 @@ public class ClientStack {
|
||||
private ItemStack stack;
|
||||
private boolean craftable;
|
||||
|
||||
public ClientStack(int id, ItemStack stack, boolean craftable) {
|
||||
this.id = id;
|
||||
this.stack = stack;
|
||||
this.craftable = craftable;
|
||||
}
|
||||
|
||||
public ClientStack(ByteBuf buf) {
|
||||
stack = new ItemStack(Item.getItemById(buf.readInt()), buf.readInt(), buf.readInt());
|
||||
stack.setTagCompound(ByteBufUtils.readTag(buf));
|
||||
@@ -1,4 +1,4 @@
|
||||
package refinedstorage.gui;
|
||||
package refinedstorage.gui.grid;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
@@ -8,8 +8,8 @@ import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.apiimpl.network.GridHandler;
|
||||
import refinedstorage.apiimpl.storage.ClientStack;
|
||||
import refinedstorage.container.ContainerCraftingSettings;
|
||||
import refinedstorage.gui.GuiBase;
|
||||
import refinedstorage.network.MessageGridCraftingStart;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -1,4 +1,4 @@
|
||||
package refinedstorage.gui;
|
||||
package refinedstorage.gui.grid;
|
||||
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
@@ -13,9 +13,12 @@ import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.api.network.GridExtractFlags;
|
||||
import refinedstorage.apiimpl.storage.ClientStack;
|
||||
import refinedstorage.block.EnumGridType;
|
||||
import refinedstorage.container.ContainerGrid;
|
||||
import refinedstorage.gui.GuiBase;
|
||||
import refinedstorage.gui.Scrollbar;
|
||||
import refinedstorage.gui.grid.sorting.GridSortingName;
|
||||
import refinedstorage.gui.grid.sorting.GridSortingQuantity;
|
||||
import refinedstorage.gui.sidebutton.*;
|
||||
import refinedstorage.jei.RefinedStorageJEIPlugin;
|
||||
import refinedstorage.network.MessageGridCraftingClear;
|
||||
@@ -30,38 +33,8 @@ import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class GuiGrid extends GuiBase {
|
||||
private Comparator<ClientStack> quantityComparator = new Comparator<ClientStack>() {
|
||||
@Override
|
||||
public int compare(ClientStack left, ClientStack right) {
|
||||
int leftSize = left.getStack().stackSize;
|
||||
int rightSize = right.getStack().stackSize;
|
||||
|
||||
if (leftSize == rightSize) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (grid.getSortingDirection() == TileGrid.SORTING_DIRECTION_ASCENDING) {
|
||||
return (leftSize > rightSize) ? 1 : -1;
|
||||
} else if (grid.getSortingDirection() == TileGrid.SORTING_DIRECTION_DESCENDING) {
|
||||
return (rightSize > leftSize) ? 1 : -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
private Comparator<ClientStack> nameComparator = new Comparator<ClientStack>() {
|
||||
@Override
|
||||
public int compare(ClientStack left, ClientStack right) {
|
||||
if (grid.getSortingDirection() == TileGrid.SORTING_DIRECTION_ASCENDING) {
|
||||
return left.getStack().getDisplayName().compareTo(right.getStack().getDisplayName());
|
||||
} else if (grid.getSortingDirection() == TileGrid.SORTING_DIRECTION_DESCENDING) {
|
||||
return right.getStack().getDisplayName().compareTo(left.getStack().getDisplayName());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
private GridSortingQuantity quantitySorting = new GridSortingQuantity();
|
||||
private GridSortingName nameSorting = new GridSortingName();
|
||||
|
||||
private GuiTextField searchField;
|
||||
|
||||
@@ -171,10 +144,13 @@ public class GuiGrid extends GuiBase {
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(items, nameComparator);
|
||||
nameSorting.setSortingDirection(grid.getSortingDirection());
|
||||
quantitySorting.setSortingDirection(grid.getSortingDirection());
|
||||
|
||||
Collections.sort(items, nameSorting);
|
||||
|
||||
if (grid.getSortingType() == TileGrid.SORTING_TYPE_QUANTITY) {
|
||||
Collections.sort(items, quantityComparator);
|
||||
Collections.sort(items, quantitySorting);
|
||||
}
|
||||
}
|
||||
|
||||
13
src/main/java/refinedstorage/gui/grid/sorting/GridSorting.java
Executable file
13
src/main/java/refinedstorage/gui/grid/sorting/GridSorting.java
Executable file
@@ -0,0 +1,13 @@
|
||||
package refinedstorage.gui.grid.sorting;
|
||||
|
||||
import refinedstorage.gui.grid.ClientStack;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public abstract class GridSorting implements Comparator<ClientStack> {
|
||||
protected int sortingDirection;
|
||||
|
||||
public void setSortingDirection(int sortingDirection) {
|
||||
this.sortingDirection = sortingDirection;
|
||||
}
|
||||
}
|
||||
20
src/main/java/refinedstorage/gui/grid/sorting/GridSortingName.java
Executable file
20
src/main/java/refinedstorage/gui/grid/sorting/GridSortingName.java
Executable file
@@ -0,0 +1,20 @@
|
||||
package refinedstorage.gui.grid.sorting;
|
||||
|
||||
import refinedstorage.gui.grid.ClientStack;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
public class GridSortingName extends GridSorting {
|
||||
@Override
|
||||
public int compare(ClientStack left, ClientStack right) {
|
||||
String leftName = left.getStack().getDisplayName();
|
||||
String rightName = right.getStack().getDisplayName();
|
||||
|
||||
if (sortingDirection == TileGrid.SORTING_DIRECTION_ASCENDING) {
|
||||
return leftName.compareTo(rightName);
|
||||
} else if (sortingDirection == TileGrid.SORTING_DIRECTION_DESCENDING) {
|
||||
return rightName.compareTo(leftName);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
22
src/main/java/refinedstorage/gui/grid/sorting/GridSortingQuantity.java
Executable file
22
src/main/java/refinedstorage/gui/grid/sorting/GridSortingQuantity.java
Executable file
@@ -0,0 +1,22 @@
|
||||
package refinedstorage.gui.grid.sorting;
|
||||
|
||||
import refinedstorage.gui.grid.ClientStack;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
public class GridSortingQuantity extends GridSorting {
|
||||
@Override
|
||||
public int compare(ClientStack left, ClientStack right) {
|
||||
int leftSize = left.getStack().stackSize;
|
||||
int rightSize = right.getStack().stackSize;
|
||||
|
||||
if (leftSize != rightSize) {
|
||||
if (sortingDirection == TileGrid.SORTING_DIRECTION_ASCENDING) {
|
||||
return (leftSize > rightSize) ? 1 : -1;
|
||||
} else if (sortingDirection == TileGrid.SORTING_DIRECTION_DESCENDING) {
|
||||
return (rightSize > leftSize) ? 1 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package refinedstorage.gui.sidebutton;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.gui.GuiBase;
|
||||
import refinedstorage.gui.GuiGrid;
|
||||
import refinedstorage.gui.grid.GuiGrid;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
public class SideButtonGridSearchBoxMode extends SideButton {
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.api.network.INetworkMaster;
|
||||
import refinedstorage.apiimpl.storage.ClientStack;
|
||||
import refinedstorage.gui.grid.ClientStack;
|
||||
|
||||
public class MessageGridDelta implements IMessage, IMessageHandler<MessageGridDelta, IMessage> {
|
||||
private INetworkMaster network;
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.api.network.INetworkMaster;
|
||||
import refinedstorage.apiimpl.storage.ClientStack;
|
||||
import refinedstorage.gui.grid.ClientStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
Reference in New Issue
Block a user