Package appeng.core.sync.packets

Source Code of appeng.core.sync.packets.PacketSwitchGuis

package appeng.core.sync.packets;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.tileentity.TileEntity;
import appeng.client.gui.AEBaseGui;
import appeng.container.AEBaseContainer;
import appeng.container.ContainerOpenContext;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.GuiBridge;
import appeng.core.sync.network.INetworkInfo;
import appeng.util.Platform;

public class PacketSwitchGuis extends AppEngPacket
{

  final GuiBridge newGui;

  // automatic.
  public PacketSwitchGuis(ByteBuf stream)
  {
    newGui = GuiBridge.values()[stream.readInt()];
  }

  @Override
  public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player)
  {
    Container c = player.openContainer;
    if ( c instanceof AEBaseContainer )
    {
      AEBaseContainer bc = (AEBaseContainer) c;
      ContainerOpenContext context = bc.openContext;
      if ( context != null )
      {
        TileEntity te = context.getTile();
        Platform.openGUI( player, te, context.side, newGui );
      }
    }
  }

  @Override
  public void clientPacketData(INetworkInfo network, AppEngPacket packet, EntityPlayer player)
  {
    AEBaseGui.switchingGuis = true;
  }

  // api
  public PacketSwitchGuis(GuiBridge newGui)
  {
    this.newGui = newGui;

    if ( Platform.isClient() )
      AEBaseGui.switchingGuis = true;

    ByteBuf data = Unpooled.buffer();

    data.writeInt( getPacketID() );
    data.writeInt( newGui.ordinal() );

    configureWrite( data );
  }
}
TOP

Related Classes of appeng.core.sync.packets.PacketSwitchGuis

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.