From 423e6be0c83652764496bd0b6bca68e6b8dba551 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Sat, 12 Jul 2014 20:20:21 -0500 Subject: [PATCH] Create a sort order for interfaces based on their location. --- .../implementations/GuiInterfaceTerminal.java | 16 ++++++++++++---- client/me/ClientDCInternalInv.java | 15 ++++++++++++--- .../ContainerInterfaceTerminal.java | 11 ++++++++--- helpers/DualityInterface.java | 6 ++++++ 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/client/gui/implementations/GuiInterfaceTerminal.java b/client/gui/implementations/GuiInterfaceTerminal.java index 357d2685..a9e2bdf4 100644 --- a/client/gui/implementations/GuiInterfaceTerminal.java +++ b/client/gui/implementations/GuiInterfaceTerminal.java @@ -150,7 +150,7 @@ public class GuiInterfaceTerminal extends AEBaseGui { long id = Long.parseLong( key.substring( 1 ), Character.MAX_RADIX ); NBTTagCompound invData = in.getCompoundTag( key ); - ClientDCInternalInv current = getById( id, invData.getString( "un" ) ); + ClientDCInternalInv current = getById( id, invData.getLong( "sortBy" ), invData.getString( "un" ) ); for (int x = 0; x < current.inv.getSizeInventory(); x++) { @@ -182,21 +182,29 @@ public class GuiInterfaceTerminal extends AEBaseGui for (String n : names) { lines.add( n ); - for (ClientDCInternalInv i : byName.get( n )) + + ArrayList lset = new ArrayList(); + lset.addAll( byName.get( n ) ); + + Collections.sort( lset ); + + for (ClientDCInternalInv i : lset) + { lines.add( i ); + } } myScrollBar.setRange( 0, getTotalRows() - 6, 2 ); } } - private ClientDCInternalInv getById(long id, String string) + private ClientDCInternalInv getById(long id, long sortBy, String string) { ClientDCInternalInv o = byId.get( id ); if ( o == null ) { - byId.put( id, o = new ClientDCInternalInv( 9, id, string ) ); + byId.put( id, o = new ClientDCInternalInv( 9, id, sortBy, string ) ); refreshList = true; } diff --git a/client/me/ClientDCInternalInv.java b/client/me/ClientDCInternalInv.java index 760a6410..08268f95 100644 --- a/client/me/ClientDCInternalInv.java +++ b/client/me/ClientDCInternalInv.java @@ -2,18 +2,21 @@ package appeng.client.me; import net.minecraft.util.StatCollector; import appeng.tile.inventory.AppEngInternalInventory; +import appeng.util.ItemSorters; -public class ClientDCInternalInv +public class ClientDCInternalInv implements Comparable { final public String unlocalizedName; - final public long id; final public AppEngInternalInventory inv; + final public long id; + final public long sortBy; - public ClientDCInternalInv(int size, long id, String unlocalizedName) { + public ClientDCInternalInv(int size, long id, long sortBy, String unlocalizedName) { inv = new AppEngInternalInventory( null, size ); this.unlocalizedName = unlocalizedName; this.id = id; + this.sortBy = sortBy; } public String getName() @@ -24,4 +27,10 @@ public class ClientDCInternalInv return s; } + @Override + public int compareTo(ClientDCInternalInv o) + { + return ItemSorters.compareLong( sortBy, o.sortBy ); + } + } \ No newline at end of file diff --git a/container/implementations/ContainerInterfaceTerminal.java b/container/implementations/ContainerInterfaceTerminal.java index 6ee1f803..e63d1ab6 100644 --- a/container/implementations/ContainerInterfaceTerminal.java +++ b/container/implementations/ContainerInterfaceTerminal.java @@ -45,14 +45,16 @@ public class ContainerInterfaceTerminal extends AEBaseContainer long which = autoBase++; String unlocalizedName; - public InvTracker(IInventory patterns, String unlocalizedName) { + public InvTracker(DualityInterface dual, IInventory patterns, String unlocalizedName) { server = patterns; client = new AppEngInternalInventory( null, server.getSizeInventory() ); this.unlocalizedName = unlocalizedName; + this.sortBy = dual.getSortValue(); } IInventory client; IInventory server; + public long sortBy; }; @@ -263,14 +265,14 @@ public class ContainerInterfaceTerminal extends AEBaseContainer { IInterfaceHost ih = (IInterfaceHost) gn.getMachine(); DualityInterface dual = ih.getInterfaceDuality(); - diList.put( ih, new InvTracker( dual.getPatterns(), dual.getTermName() ) ); + diList.put( ih, new InvTracker( dual, dual.getPatterns(), dual.getTermName() ) ); } for (IGridNode gn : g.getMachines( PartInterface.class )) { IInterfaceHost ih = (IInterfaceHost) gn.getMachine(); DualityInterface dual = ih.getInterfaceDuality(); - diList.put( ih, new InvTracker( dual.getPatterns(), dual.getTermName() ) ); + diList.put( ih, new InvTracker( dual, dual.getPatterns(), dual.getTermName() ) ); } } } @@ -291,7 +293,10 @@ public class ContainerInterfaceTerminal extends AEBaseContainer NBTTagCompound invv = data.getCompoundTag( name ); if ( invv.hasNoTags() ) + { + invv.setLong( "sortBy", inv.sortBy ); invv.setString( "un", inv.unlocalizedName ); + } for (int x = 0; x < length; x++) { diff --git a/helpers/DualityInterface.java b/helpers/DualityInterface.java index e29487b6..2e0a8d60 100644 --- a/helpers/DualityInterface.java +++ b/helpers/DualityInterface.java @@ -1045,4 +1045,10 @@ public class DualityInterface implements IGridTickable, ISegmentedInventory, ISt return "Nothing"; } + + public long getSortValue() + { + TileEntity te = iHost.getTileEntity(); + return (te.zCoord << 24) ^ (te.xCoord << 8) ^ te.yCoord; + } }