Nameable CPUs.

This commit is contained in:
AlgorithmX2 2014-07-15 22:26:12 -05:00
parent e64bf91789
commit e49864e295
9 changed files with 121 additions and 9 deletions

View file

@ -110,7 +110,16 @@ public class GuiCraftConfirm extends AEBaseGui
{
String btnTextText = GuiText.CraftingCPU.getLocal() + ": " + GuiText.Automatic;
if ( ccc.selectedCpu >= 0 )// && ccc.selectedCpu < ccc.cpus.size() )
btnTextText = GuiText.CraftingCPU.getLocal() + ": #" + ccc.selectedCpu;
{
if ( ccc.myName.length() > 0 )
{
String name = ccc.myName.substring( 0, Math.min( 20, ccc.myName.length() ) );
btnTextText = GuiText.CraftingCPU.getLocal() + ": " + name;
}
else
btnTextText = GuiText.CraftingCPU.getLocal() + ": #" + ccc.selectedCpu;
}
if ( ccc.noCPU )
btnTextText = GuiText.NoCraftingCPUs.getLocal();

View file

@ -244,7 +244,7 @@ public class GuiCraftingCPU extends AEBaseGui implements ISortSource
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY)
{
fontRendererObj.drawString( GuiText.CraftingStatus.getLocal(), 8, 7, 4210752 );
fontRendererObj.drawString( getGuiDisplayName( GuiText.CraftingStatus.getLocal() ), 8, 7, 4210752 );
int sectionLength = 67;

View file

@ -578,7 +578,7 @@ public abstract class AEBaseContainer extends Container
{
if ( syncData.containsKey( idx ) )
{
syncData.get( idx ).update( value );
syncData.get( idx ).update( (long) value );
return;
}
@ -588,13 +588,22 @@ public abstract class AEBaseContainer extends Container
{
if ( syncData.containsKey( idx ) )
{
syncData.get( idx ).update( value );
syncData.get( idx ).update( (long) value );
return;
}
updateProgressBar( idx, (int) value );
}
public void stringSync(int idx, String value)
{
if ( syncData.containsKey( idx ) )
{
syncData.get( idx ).update( value );
return;
}
}
private void prepareSync()
{
for (Field f : getClass().getFields())
@ -625,6 +634,12 @@ public abstract class AEBaseContainer extends Container
if ( tileEntity instanceof ICustomNameObject )
name = (ICustomNameObject) tileEntity;
if ( obj instanceof ICustomNameObject )
name = (ICustomNameObject) obj;
if ( this instanceof ICustomNameObject )
name = (ICustomNameObject) this;
if ( name != null )
{
if ( name.hasCustomName() )
@ -1055,4 +1070,5 @@ public abstract class AEBaseContainer extends Container
{
}
}

View file

@ -10,6 +10,7 @@ import appeng.container.AEBaseContainer;
import appeng.core.AELog;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketProgressBar;
import appeng.core.sync.packets.PacketValueConfig;
public class SyncDat
{
@ -59,12 +60,15 @@ public class SyncDat
}
}
public void update(long val)
public void update(Object val)
{
try
{
Object oldValue = field.get( source );
updateValue( oldValue, val );
if ( val instanceof String )
updateString( oldValue, (String) val );
else
updateValue( oldValue, (Long) val );
}
catch (IllegalArgumentException e)
{
@ -77,6 +81,22 @@ public class SyncDat
}
private void updateString(Object oldValue, String val)
{
try
{
field.set( source, val );
}
catch (IllegalArgumentException e)
{
AELog.error( e );
}
catch (IllegalAccessException e)
{
AELog.error( e );
}
}
private void updateValue(Object oldValue, long val)
{
try
@ -123,7 +143,12 @@ public class SyncDat
private void send(ICrafting o, Object val) throws IOException
{
if ( field.getType().isEnum() )
if ( val instanceof String )
{
if ( o instanceof EntityPlayerMP )
NetworkHandler.instance.sendTo( new PacketValueConfig( "SyncDat." + channel, (String) val ), (EntityPlayerMP) o );
}
else if ( field.getType().isEnum() )
{
o.sendProgressBarUpdate( source, channel, ((Enum) val).ordinal() );
}

View file

@ -71,6 +71,9 @@ public class ContainerCraftConfirm extends AEBaseContainer
@GuiSync(6)
public boolean noCPU = true;
@GuiSync(7)
public String myName = "";
protected long cpuIdx = Long.MIN_VALUE;
public class CraftingCPURecord implements Comparable<CraftingCPURecord>
@ -82,10 +85,13 @@ public class ContainerCraftConfirm extends AEBaseContainer
long size;
int processors;
public String myName;
CraftingCPURecord(long size, int proc, ICraftingCPU server) {
this.size = size;
this.processors = proc;
this.cpu = server;
myName = server.getName();
}
@Override
@ -115,9 +121,11 @@ public class ContainerCraftConfirm extends AEBaseContainer
selectedCpu = -1;
cpuBytesAvail = 0;
cpuCoProcessors = 0;
myName = "";
}
else if ( selectedCpu != -1 )
{
myName = cpus.get( selectedCpu ).myName;
cpuBytesAvail = cpus.get( selectedCpu ).size;
cpuCoProcessors = cpus.get( selectedCpu ).processors;
}
@ -139,9 +147,11 @@ public class ContainerCraftConfirm extends AEBaseContainer
{
cpuBytesAvail = 0;
cpuCoProcessors = 0;
myName = "";
}
else
{
myName = cpus.get( selectedCpu ).myName;
cpuBytesAvail = cpus.get( selectedCpu ).size;
cpuCoProcessors = cpus.get( selectedCpu ).processors;
}

View file

@ -20,15 +20,17 @@ import appeng.api.storage.data.IItemList;
import appeng.container.AEBaseContainer;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketMEInventoryUpdate;
import appeng.helpers.ICustomNameObject;
import appeng.me.cluster.IAECluster;
import appeng.me.cluster.implementations.CraftingCPUCluster;
import appeng.tile.crafting.TileCraftingTile;
import appeng.util.Platform;
public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorHandlerReceiver<IAEItemStack>
public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorHandlerReceiver<IAEItemStack>, ICustomNameObject
{
CraftingCPUCluster monitor = null;
String cpuName = null;
IGrid network;
IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList();
@ -49,6 +51,8 @@ public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorH
IAECluster c = ((TileCraftingTile) te).getCluster();
if ( c instanceof CraftingCPUCluster )
{
cpuName = ((CraftingCPUCluster) c).getName();
monitor = (CraftingCPUCluster) c;
if ( monitor != null )
{
@ -162,4 +166,16 @@ public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorH
{
}
@Override
public String getCustomName()
{
return cpuName;
}
@Override
public boolean hasCustomName()
{
return cpuName != null && cpuName.length() > 0;
}
}

View file

@ -186,6 +186,10 @@ public class PacketValueConfig extends AppEngPacket
{
((AEBaseContainer) c).customName = Value;
}
else if ( Name.startsWith( "SyncDat." ) )
{
((AEBaseContainer) c).stringSync( Integer.parseInt( Name.substring( 8 ) ), Value );
}
else if ( c instanceof IConfigureableObject )
{
IConfigManager cm = ((IConfigureableObject) c).getConfigManager();

View file

@ -83,6 +83,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
public ICraftingLink myLastLink;
MachineSource machineSrc = null;
public String myName = "";
int accelerator = 0;
public WorldCoord min;
@ -244,7 +245,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
te.isCoreBlock = false;
te.markDirty();
tiles.add( te );
tiles.push( te );
if ( te.isStorage() )
{
@ -995,6 +996,7 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
}
updateCPU();
updateName();
}
@Override
@ -1003,4 +1005,27 @@ public class CraftingCPUCluster implements IAECluster, ICraftingCPU
return machineSrc;
}
@Override
public String getName()
{
return myName;
}
public void updateName()
{
myName = "";
for (TileCraftingTile te : tiles)
{
if ( te.hasCustomName() )
{
if ( myName.length() > 0 )
myName += " " + te.getCustomName();
else
myName = te.getCustomName();
}
}
}
}

View file

@ -72,6 +72,13 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IP
calc.calculateMultiblock( worldObj, getLocation() );
}
public void setName(String name)
{
super.setName( name );
if ( clust != null )
clust.updateName();
}
private class CraftingHandler extends AETileEventHandler
{