Considerable progress on Interface terminal.

This commit is contained in:
AlgorithmX2 2014-07-07 22:48:21 -05:00
parent a0427da1ae
commit 813c1bcb58
12 changed files with 427 additions and 66 deletions

View file

@ -0,0 +1,126 @@
package appeng.client.gui.implementations;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import appeng.client.gui.AEBaseGui;
import appeng.container.implementations.ContainerInterfaceTerminal;
import appeng.core.localization.GuiText;
import appeng.parts.reporting.PartMonitor;
import appeng.tile.inventory.AppEngInternalInventory;
import com.google.common.collect.HashMultimap;
public class GuiInterfaceTerminal extends AEBaseGui
{
class ClientFakeInv
{
String unlocalizedName;
long id;
AppEngInternalInventory inv = new AppEngInternalInventory( null, 9 );
public String getName()
{
return StatCollector.translateToLocal( unlocalizedName + ".name" );
}
};
HashMap<Long, ClientFakeInv> byId = new HashMap();
HashMultimap<String, ClientFakeInv> byName = HashMultimap.create();
ArrayList<String> names = new ArrayList();
public GuiInterfaceTerminal(InventoryPlayer inventoryPlayer, PartMonitor te) {
super( new ContainerInterfaceTerminal( inventoryPlayer, te ) );
xSize = 195;
ySize = 222;
}
@Override
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY)
{
bindTexture( "guis/interfaceterminal.png" );
this.drawTexturedModalRect( offsetX, offsetY, 0, 0, xSize, ySize );
}
@Override
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY)
{
fontRendererObj.drawString( getGuiDisplayName( GuiText.InterfaceTerminal.getLocal() ), 8, 6, 4210752 );
fontRendererObj.drawString( GuiText.inventory.getLocal(), 8, ySize - 96 + 3, 4210752 );
int offset = 0;
for (String name : names)
{
fontRendererObj.drawString( name, 8, 30 + offset, 4210752 );
offset += 18;
}
}
boolean refreshList = false;
public void postUpdate(NBTTagCompound in)
{
if ( in.getBoolean( "clear" ) )
byId.clear();
for (Object oKey : in.func_150296_c())
{
String key = (String) oKey;
if ( key.startsWith( "=" ) )
{
try
{
long id = Long.parseLong( key.substring( 1 ), Character.MAX_RADIX );
NBTTagCompound invData = in.getCompoundTag( key );
ClientFakeInv current = getById( id );
current.unlocalizedName = invData.getString( "un" );
for (int x = 0; x < current.inv.getSizeInventory(); x++)
{
String which = Integer.toString( x );
if ( invData.hasKey( which ) )
current.inv.setInventorySlotContents( x, ItemStack.loadItemStackFromNBT( invData.getCompoundTag( which ) ) );
}
}
catch (NumberFormatException ex)
{
}
}
}
if ( refreshList )
{
byName.clear();
for (ClientFakeInv o : byId.values())
byName.put( o.getName(), o );
names.clear();
names.addAll( byName.keySet() );
Collections.sort( names );
}
}
private ClientFakeInv getById(long id)
{
ClientFakeInv o = byId.get( id );
if ( o == null )
{
byId.put( id, o = new ClientFakeInv() );
refreshList = true;
}
return o;
}
}

View file

@ -27,8 +27,10 @@ public enum CableBusTextures
PartPatternTerm_Bright("PartPatternTerm_Bright"), PartPatternTerm_Colored("PartPatternTerm_Colored"), PartPatternTerm_Dark("PartPatternTerm_Dark"),
PartConvMonitor_Bright("PartConvMonitor_Bright"), PartConvMonitor_Colored("PartConvMonitor_Colored"), PartConvMonitor_Dark("PartConvMonitor_Dark"), PartCraftingMonitor_Bright(
"PartCraftingMonitor_Bright"), PartCraftingMonitor_Colored("PartCraftingMonitor_Colored"), PartCraftingMonitor_Dark("PartCraftingMonitor_Dark"),
PartConvMonitor_Bright("PartConvMonitor_Bright"), PartConvMonitor_Colored("PartConvMonitor_Colored"), PartConvMonitor_Dark("PartConvMonitor_Dark"),
PartInterfaceTerm_Bright("PartInterfaceTerm_Bright"), PartInterfaceTerm_Colored("PartInterfaceTerm_Colored"), PartInterfaceTerm_Dark(
"PartInterfaceTerm_Dark"),
PartCraftingTerm_Bright("PartCraftingTerm_Bright"), PartCraftingTerm_Colored("PartCraftingTerm_Colored"), PartCraftingTerm_Dark("PartCraftingTerm_Dark"), //

View file

@ -1,112 +1,182 @@
package appeng.container.implementations;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
import appeng.container.AEBaseContainer;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketCompressedNBT;
import appeng.helpers.DualityInterface;
import appeng.helpers.IInterfaceHost;
import appeng.parts.misc.PartInterface;
import appeng.parts.reporting.PartMonitor;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.misc.TileInterface;
import appeng.util.Platform;
public class ContainerInterfaceTerminal extends AEBaseContainer{
class InvTracker {
public InvTracker(IInventory patterns) {
public class ContainerInterfaceTerminal extends AEBaseContainer
{
/**
* this stuff is all server side..
*/
static private long autoBase = Long.MIN_VALUE;
class InvTracker
{
long which = autoBase++;
String unlocalizedName;
public InvTracker(IInventory patterns, String unlocalizedName) {
server = patterns;
client = new AppEngInternalInventory(null,server.getSizeInventory());
client = new AppEngInternalInventory( null, server.getSizeInventory() );
this.unlocalizedName = unlocalizedName;
}
IInventory client;
IInventory server;
};
Map<IInterfaceHost,InvTracker> diList = new HashMap();
Map<IInterfaceHost, InvTracker> diList = new HashMap();
IGrid g;
public ContainerInterfaceTerminal(InventoryPlayer ip, IInterfaceHost anchor) {
super(ip, anchor);
g = anchor.getActionableNode().getGrid();
public ContainerInterfaceTerminal(InventoryPlayer ip, PartMonitor anchor) {
super( ip, anchor );
if ( Platform.isServer() )
g = anchor.getActionableNode().getGrid();
bindPlayerInventory( ip, 0, 222 - /* height of playerinventory */82 );
}
NBTTagCompound data = new NBTTagCompound();
@Override
public void detectAndSendChanges() {
public void detectAndSendChanges()
{
super.detectAndSendChanges();
int total = 0;
boolean missing=false;
if ( g == null )
return;
for ( IGridNode gn : g.getMachines( TileInterface.class ) )
int total = 0;
boolean missing = false;
for (IGridNode gn : g.getMachines( TileInterface.class ))
{
IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
missing = missing || ! diList.containsKey( ih );
missing = missing || !diList.containsKey( ih );
}
for ( IGridNode gn : g.getMachines( PartInterface.class ) )
for (IGridNode gn : g.getMachines( PartInterface.class ))
{
IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
missing = missing || ! diList.containsKey( ih );
missing = missing || !diList.containsKey( ih );
}
if ( total != diList.size() || missing )
regenList();
regenList( data );
else
{
for ( Entry<IInterfaceHost,InvTracker> en : diList.entrySet() )
for (Entry<IInterfaceHost, InvTracker> en : diList.entrySet())
{
InvTracker inv = en.getValue();
for ( int x = 0; x < inv.server.getSizeInventory(); x++ )
for (int x = 0; x < inv.server.getSizeInventory(); x++)
{
if ( isDifferent( inv.server.getStackInSlot(x), inv.client.getStackInSlot(x) ) )
syncSlots(en.getKey(), x, x );
if ( isDifferent( inv.server.getStackInSlot( x ), inv.client.getStackInSlot( x ) ) )
addItems( data, inv, x, 1 );
}
}
}
if ( !data.hasNoTags() )
{
try
{
NetworkHandler.instance.sendTo( new PacketCompressedNBT( data ), (EntityPlayerMP) getPlayerInv().player );
}
catch (IOException e)
{
// :P
}
data = new NBTTagCompound();
}
}
private boolean isDifferent(ItemStack a, ItemStack b) {
private boolean isDifferent(ItemStack a, ItemStack b)
{
if ( a == null && b == null )
return false;
if ( a == null || b == null )
return true;
return !a.equals(b);
return !a.equals( b );
}
private void regenList() {
private void regenList(NBTTagCompound data)
{
diList.clear();
for ( IGridNode gn : g.getMachines( TileInterface.class ) )
for (IGridNode gn : g.getMachines( TileInterface.class ))
{
IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
diList.put( ih, new InvTracker( ih.getInterfaceDuality().getPatterns() ));
DualityInterface dual = ih.getInterfaceDuality();
diList.put( ih, new InvTracker( dual.getPatterns(), dual.getTermName() ) );
}
for ( IGridNode gn : g.getMachines( PartInterface.class ) )
for (IGridNode gn : g.getMachines( PartInterface.class ))
{
IInterfaceHost ih = (IInterfaceHost) gn.getMachine();
diList.put( ih, new InvTracker(ih.getInterfaceDuality().getPatterns()) );
DualityInterface dual = ih.getInterfaceDuality();
diList.put( ih, new InvTracker( dual.getPatterns(), dual.getTermName() ) );
}
for ( IInterfaceHost ih : diList.keySet() )
syncSlots(ih, 0, 8);
data.setBoolean( "clear", true );
for (Entry<IInterfaceHost, InvTracker> en : diList.entrySet())
{
InvTracker inv = en.getValue();
addItems( data, inv, 0, inv.server.getSizeInventory() );
}
}
void syncSlots( IInterfaceHost ih, int from, int to )
private void addItems(NBTTagCompound data, InvTracker inv, int offset, int length)
{
}
String name = "=" + Long.toString( inv.which, Character.MAX_RADIX );
NBTTagCompound invv = data.getCompoundTag( name );
if ( invv.hasNoTags() )
invv.setString( "un", inv.unlocalizedName );
for (int x = 0; x < length; x++)
{
NBTTagCompound itemNBT = new NBTTagCompound();
ItemStack is = inv.server.getStackInSlot( x + offset );
// "update" client side.
inv.client.setInventorySlotContents( x + offset, is == null ? null : is.copy() );
if ( is != null )
is.writeToNBT( itemNBT );
invv.setTag( Integer.toString( x + offset ), itemNBT );
}
data.setTag( name, invv );
}
}

View file

@ -52,7 +52,7 @@ public enum AEFeature
enableFacadeCrafting("Crafting"), inWorldSingularity("Crafting"), inWorldFluix("Crafting"), inWorldPurification("Crafting"), UpdateLogging("Misc", false),
AlphaPass("Rendering"), PaintBalls("Tools"), PacketLogging("Misc", false), CraftingLog("Misc", false);
AlphaPass("Rendering"), PaintBalls("Tools"), PacketLogging("Misc", false), CraftingLog("Misc", false), InterfaceTerminal("Crafting");
String Category;
boolean visible = true;

View file

@ -32,7 +32,7 @@ public enum GuiText
OfSecondOutput, NoSecondOutput, RFTunnel, Stores, Next, SelectAmount, Lumen, Empty, ConfirmCrafting,
Stored, Crafting, Scheduled, CraftingStatus, Cancel, FromStorage, ToCraft, CraftingPlan, CalculatingWait, Start, Bytes, CraftingCPU, Automatic, CoProcessors, Simulation, Missing;
Stored, Crafting, Scheduled, CraftingStatus, Cancel, FromStorage, ToCraft, CraftingPlan, CalculatingWait, Start, Bytes, CraftingCPU, Automatic, CoProcessors, Simulation, Missing, InterfaceTerminal;
String root;

View file

@ -11,6 +11,7 @@ import appeng.core.sync.packets.PacketAssemblerAnimation;
import appeng.core.sync.packets.PacketClick;
import appeng.core.sync.packets.PacketCompassRequest;
import appeng.core.sync.packets.PacketCompassResponse;
import appeng.core.sync.packets.PacketCompressedNBT;
import appeng.core.sync.packets.PacketConfigButton;
import appeng.core.sync.packets.PacketCraftRequest;
import appeng.core.sync.packets.PacketInventoryAction;
@ -79,7 +80,9 @@ public class AppEngPacketHandlerBase
PACKET_CRAFTING_REQUEST(PacketCraftRequest.class),
PAKCET_ASSEMBLER_ANIMATION(PacketAssemblerAnimation.class);
PACKET_ASSEMBLER_ANIMATION(PacketAssemblerAnimation.class),
PACKET_COMPRESSED_NBT(PacketCompressedNBT.class);
final public Class pc;
final public Constructor con;

View file

@ -45,6 +45,7 @@ import appeng.container.implementations.ContainerGrinder;
import appeng.container.implementations.ContainerIOPort;
import appeng.container.implementations.ContainerInscriber;
import appeng.container.implementations.ContainerInterface;
import appeng.container.implementations.ContainerInterfaceTerminal;
import appeng.container.implementations.ContainerLevelEmitter;
import appeng.container.implementations.ContainerMAC;
import appeng.container.implementations.ContainerMEMonitorable;
@ -71,6 +72,7 @@ import appeng.parts.automation.PartFormationPlane;
import appeng.parts.automation.PartLevelEmitter;
import appeng.parts.misc.PartStorageBus;
import appeng.parts.reporting.PartCraftingTerminal;
import appeng.parts.reporting.PartMonitor;
import appeng.parts.reporting.PartPatternTerminal;
import appeng.server.AccessType;
import appeng.tile.crafting.TileCraftingTile;
@ -157,7 +159,9 @@ public enum GuiBridge implements IGuiHandler
GUI_CRAFTING_AMOUNT(ContainerCraftAmount.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT),
GUI_CRAFTING_CONFIRM(ContainerCraftConfirm.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT);
GUI_CRAFTING_CONFIRM(ContainerCraftConfirm.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT),
GUI_INTERFACE_TERMINAL(ContainerInterfaceTerminal.class, PartMonitor.class, WORLD, SecurityPermissions.BUILD);
private Class Tile;
private Class Gui;

View file

@ -0,0 +1,95 @@
package appeng.core.sync.packets;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import appeng.client.gui.implementations.GuiInterfaceTerminal;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PacketCompressedNBT extends AppEngPacket
{
// output...
final private ByteBuf data;
final private GZIPOutputStream compressFrame;
int writtenBytes = 0;
boolean empty = true;
// input.
final NBTTagCompound in;
// automatic.
public PacketCompressedNBT(final ByteBuf stream) throws IOException {
data = null;
compressFrame = null;
GZIPInputStream gzReader = new GZIPInputStream( new InputStream() {
@Override
public int read() throws IOException
{
if ( stream.readableBytes() <= 0 )
return -1;
return (int) stream.readByte() & 0xff;
}
} );
in = CompressedStreamTools.read( new DataInputStream( gzReader ) );
}
@Override
@SideOnly(Side.CLIENT)
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
{
GuiScreen gs = Minecraft.getMinecraft().currentScreen;
if ( gs instanceof GuiInterfaceTerminal )
((GuiInterfaceTerminal) gs).postUpdate( in );
}
// api
public PacketCompressedNBT(NBTTagCompound din) throws IOException {
data = Unpooled.buffer( 2048 );
data.writeInt( getPacketID() );
in = din;
compressFrame = new GZIPOutputStream( new OutputStream() {
@Override
public void write(int value) throws IOException
{
data.writeByte( value );
}
} );
CompressedStreamTools.write( din, new DataOutputStream( compressFrame ) );
compressFrame.close();
configureWrite( data );
}
}

View file

@ -5,12 +5,15 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.AEApi;
@ -45,6 +48,7 @@ import appeng.api.util.AECableType;
import appeng.api.util.DimensionalCoord;
import appeng.api.util.IConfigManager;
import appeng.api.util.IConfigureableObject;
import appeng.core.localization.GuiText;
import appeng.core.settings.TickRates;
import appeng.me.GridAccessException;
import appeng.me.helpers.AENetworkProxy;
@ -922,4 +926,40 @@ public class DualityInterface implements IGridTickable, ISegmentedInventory, ISt
craftingTracker.jobStateChange( link );
}
public String getTermName()
{
TileEntity tile = iHost.getTileEntity();
World w = tile.getWorldObj();
EnumSet<ForgeDirection> possibleDirections = iHost.getTargets();
for (ForgeDirection s : possibleDirections)
{
Vec3 from = Vec3.createVectorHelper( (double) tile.xCoord + 0.5, (double) tile.yCoord + 0.5, (double) tile.zCoord + 0.5 );
from = from.addVector( s.offsetX * 0.501, s.offsetY * 0.501, s.offsetZ * 0.501 );
Vec3 to = from.addVector( s.offsetX, s.offsetY, s.offsetZ );
Block blk = w.getBlock( tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ );
MovingObjectPosition mop = w.rayTraceBlocks( from, to, true );
TileEntity te = w.getTileEntity( tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ );
ItemStack what = new ItemStack( blk.getItem( w, tile.xCoord, tile.yCoord, tile.zCoord ) );
if ( mop != null )
{
if ( te instanceof ICraftingMachine || InventoryAdaptor.getAdaptor( te, s.getOpposite() ) != null )
{
if ( mop.blockX == te.xCoord && mop.blockY == te.yCoord && mop.blockZ == te.zCoord )
{
ItemStack g = blk.getPickBlock( mop, w, te.xCoord, te.yCoord, te.zCoord );
if ( g != null )
what = g;
}
}
}
return what.getUnlocalizedName();
}
return GuiText.Interface.getUnlocalized();
}
}

View file

@ -31,6 +31,7 @@ import appeng.parts.p2p.PartP2PTunnelME;
import appeng.parts.reporting.PartConversionMonitor;
import appeng.parts.reporting.PartCraftingTerminal;
import appeng.parts.reporting.PartDarkMonitor;
import appeng.parts.reporting.PartInterfaceTerminal;
import appeng.parts.reporting.PartMonitor;
import appeng.parts.reporting.PartPatternTerminal;
import appeng.parts.reporting.PartSemiDarkMonitor;
@ -101,7 +102,9 @@ public enum PartType
P2PTunnelEU(465, AEFeature.P2PTunnelEU, PartP2PIC2Power.class, GuiText.EUTunnel),
P2PTunnelRF(466, AEFeature.P2PTunnelRF, PartP2PRFPower.class, GuiText.RFTunnel);
P2PTunnelRF(466, AEFeature.P2PTunnelRF, PartP2PRFPower.class, GuiText.RFTunnel),
InterfaceTerminal(480, AEFeature.InterfaceTerminal, PartInterfaceTerminal.class);
private final EnumSet<AEFeature> features;
private final Class<? extends IPart> myPart;

View file

@ -1,17 +0,0 @@
package appeng.parts.reporting;
import net.minecraft.item.ItemStack;
import appeng.client.texture.CableBusTextures;
public class PartCraftingMonitor extends PartMonitor
{
public PartCraftingMonitor(ItemStack is) {
super( PartCraftingMonitor.class, is,true );
frontBright = CableBusTextures.PartCraftingMonitor_Bright;
frontColored = CableBusTextures.PartCraftingMonitor_Colored;
frontDark = CableBusTextures.PartCraftingMonitor_Dark;
// frontSolid = CableBusTextures.PartCraftingMonitor_Solid;
}
}

View file

@ -0,0 +1,35 @@
package appeng.parts.reporting;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Vec3;
import appeng.client.texture.CableBusTextures;
import appeng.core.sync.GuiBridge;
import appeng.util.Platform;
public class PartInterfaceTerminal extends PartMonitor
{
public PartInterfaceTerminal(ItemStack is) {
super( PartInterfaceTerminal.class, is, true );
frontBright = CableBusTextures.PartInterfaceTerm_Bright;
frontColored = CableBusTextures.PartInterfaceTerm_Colored;
frontDark = CableBusTextures.PartInterfaceTerm_Dark;
}
@Override
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
{
if ( !player.isSneaking() )
{
if ( Platform.isClient() )
return true;
Platform.openGUI( player, getHost().getTile(), side, GuiBridge.GUI_INTERFACE_TERMINAL );
return true;
}
return false;
}
}