2014-01-27 05:00:36 +01:00
|
|
|
package appeng.core.sync.packets;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
import io.netty.buffer.Unpooled;
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.inventory.Container;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-06-03 04:04:47 +02:00
|
|
|
import appeng.client.gui.AEBaseGui;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.container.AEBaseContainer;
|
|
|
|
import appeng.container.ContainerOpenContext;
|
|
|
|
import appeng.core.sync.AppEngPacket;
|
|
|
|
import appeng.core.sync.GuiBridge;
|
2014-02-09 02:34:52 +01:00
|
|
|
import appeng.core.sync.network.INetworkInfo;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.util.Platform;
|
|
|
|
|
|
|
|
public class PacketSwitchGuis extends AppEngPacket
|
|
|
|
{
|
|
|
|
|
|
|
|
final GuiBridge newGui;
|
|
|
|
|
|
|
|
// automatic.
|
2014-02-09 02:34:52 +01:00
|
|
|
public PacketSwitchGuis(ByteBuf stream) throws IOException {
|
2014-01-27 05:00:36 +01:00
|
|
|
newGui = GuiBridge.values()[stream.readInt()];
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
|
2014-01-27 05:00:36 +01:00
|
|
|
{
|
|
|
|
Container c = player.openContainer;
|
|
|
|
if ( c instanceof AEBaseContainer )
|
|
|
|
{
|
|
|
|
AEBaseContainer bc = (AEBaseContainer) c;
|
|
|
|
ContainerOpenContext context = bc.openContext;
|
|
|
|
if ( context != null )
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
TileEntity te = context.w.getTileEntity( context.x, context.y, context.z );
|
2014-01-27 05:00:36 +01:00
|
|
|
Platform.openGUI( player, te, context.side, newGui );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-27 19:31:25 +02:00
|
|
|
@Override
|
|
|
|
public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
|
|
|
|
{
|
|
|
|
AEBaseGui.switchingGuis = true;
|
|
|
|
}
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
// api
|
|
|
|
public PacketSwitchGuis(GuiBridge newGui) throws IOException {
|
|
|
|
|
|
|
|
this.newGui = newGui;
|
|
|
|
|
2014-07-27 19:31:25 +02:00
|
|
|
if ( Platform.isClient() )
|
|
|
|
AEBaseGui.switchingGuis = true;
|
2014-06-03 04:04:47 +02:00
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
ByteBuf data = Unpooled.buffer();
|
2014-01-27 05:00:36 +01:00
|
|
|
|
|
|
|
data.writeInt( getPacketID() );
|
|
|
|
data.writeInt( newGui.ordinal() );
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
configureWrite( data );
|
2014-01-27 05:00:36 +01:00
|
|
|
}
|
|
|
|
}
|