Applied-Energistics-2-tiler.../core/sync/packets/PacketSwitchGuis.java

57 lines
1.4 KiB
Java
Raw Normal View History

package appeng.core.sync.packets;
2014-02-09 02:34:52 +01:00
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.tileentity.TileEntity;
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;
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 {
newGui = GuiBridge.values()[stream.readInt()];
}
@Override
2014-02-09 02:34:52 +01:00
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 )
{
2014-02-09 02:34:52 +01:00
TileEntity te = context.w.getTileEntity( context.x, context.y, context.z );
Platform.openGUI( player, te, context.side, newGui );
}
}
}
// api
public PacketSwitchGuis(GuiBridge newGui) throws IOException {
this.newGui = newGui;
2014-02-09 02:34:52 +01:00
ByteBuf data = Unpooled.buffer();
data.writeInt( getPacketID() );
data.writeInt( newGui.ordinal() );
2014-02-09 02:34:52 +01:00
configureWrite( data );
}
}