Create a sort order for interfaces based on their location.

This commit is contained in:
AlgorithmX2 2014-07-12 20:20:21 -05:00
parent f343ac36e8
commit 423e6be0c8
4 changed files with 38 additions and 10 deletions

View file

@ -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<ClientDCInternalInv> 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;
}

View file

@ -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<ClientDCInternalInv>
{
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 );
}
}

View file

@ -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++)
{

View file

@ -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;
}
}