2013-12-27 23:59:59 +01:00
|
|
|
package appeng.core.sync.packets;
|
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
import java.io.DataInputStream;
|
|
|
|
import java.io.DataOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
import net.minecraft.client.gui.GuiScreen;
|
2014-01-05 09:39:48 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.network.INetworkManager;
|
|
|
|
import net.minecraft.network.packet.Packet250CustomPayload;
|
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
|
|
|
import appeng.client.gui.implementations.GuiMEMonitorable;
|
2014-01-23 17:28:12 +01:00
|
|
|
import appeng.client.gui.implementations.GuiNetworkStatus;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.core.sync.AppEngPacket;
|
|
|
|
import appeng.util.item.AEItemStack;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
public class PacketMEInventoryUpdate extends AppEngPacket
|
|
|
|
{
|
|
|
|
|
|
|
|
// output...
|
|
|
|
final private ByteArrayOutputStream bytes;
|
|
|
|
final private DataOutputStream data;
|
|
|
|
boolean empty = true;
|
|
|
|
|
|
|
|
// input.
|
|
|
|
final List<IAEItemStack> list;
|
|
|
|
|
|
|
|
// automatic.
|
|
|
|
public PacketMEInventoryUpdate(DataInputStream stream) throws IOException {
|
|
|
|
bytes = null;
|
|
|
|
data = null;
|
|
|
|
list = new LinkedList();
|
|
|
|
while (stream.available() > 0)
|
|
|
|
list.add( AEItemStack.loadItemStackFromPacket( stream ) );
|
|
|
|
empty = list.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
2014-01-05 09:39:48 +01:00
|
|
|
public void clientPacketData(INetworkManager network, AppEngPacket packet, EntityPlayer player)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
GuiScreen gs = Minecraft.getMinecraft().currentScreen;
|
2014-01-23 17:28:12 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( gs instanceof GuiMEMonitorable )
|
|
|
|
((GuiMEMonitorable) gs).postUpdate( list );
|
2014-01-23 17:28:12 +01:00
|
|
|
|
|
|
|
if ( gs instanceof GuiNetworkStatus )
|
|
|
|
((GuiNetworkStatus) gs).postUpdate( list );
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Packet250CustomPayload getPacket()
|
|
|
|
{
|
|
|
|
isChunkDataPacket = false;
|
|
|
|
configureWrite( bytes.toByteArray() );
|
|
|
|
return super.getPacket();
|
|
|
|
}
|
|
|
|
|
|
|
|
// api
|
|
|
|
public PacketMEInventoryUpdate() throws IOException {
|
|
|
|
bytes = new ByteArrayOutputStream();
|
|
|
|
data = new DataOutputStream( bytes );
|
|
|
|
list = null;
|
|
|
|
data.writeInt( getPacketID() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public void appendItem(IAEItemStack is) throws IOException
|
|
|
|
{
|
|
|
|
is.writeToPacket( data );
|
|
|
|
empty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isEmpty()
|
|
|
|
{
|
|
|
|
return empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|