66 lines
1.6 KiB
Java
66 lines
1.6 KiB
Java
package appeng.core.sync.packets;
|
|
|
|
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.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) throws IOException {
|
|
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) throws IOException {
|
|
|
|
this.newGui = newGui;
|
|
|
|
if ( Platform.isClient() )
|
|
AEBaseGui.switchingGuis = true;
|
|
|
|
ByteBuf data = Unpooled.buffer();
|
|
|
|
data.writeInt( getPacketID() );
|
|
data.writeInt( newGui.ordinal() );
|
|
|
|
configureWrite( data );
|
|
}
|
|
}
|