2013-10-30 20:22:43 +01:00
|
|
|
package mekanism.common.network;
|
|
|
|
|
2013-12-20 22:09:09 +01:00
|
|
|
import mekanism.api.Coord4D;
|
2013-10-30 20:22:43 +01:00
|
|
|
import mekanism.common.Mekanism;
|
2014-06-11 11:57:49 +02:00
|
|
|
import mekanism.common.PacketHandler;
|
|
|
|
import mekanism.common.network.PacketSimpleGui.SimpleGuiMessage;
|
2014-01-08 02:55:50 +01:00
|
|
|
import mekanism.common.tile.TileEntityBasicBlock;
|
2014-09-03 20:00:03 +02:00
|
|
|
|
2013-11-24 14:53:14 +01:00
|
|
|
import net.minecraft.client.gui.GuiScreen;
|
2013-10-30 20:22:43 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-11-22 03:37:03 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2013-10-30 20:22:43 +01:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import cpw.mods.fml.common.FMLCommonHandler;
|
2014-06-11 11:57:49 +02:00
|
|
|
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
|
|
|
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
|
|
|
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
2013-11-24 14:53:14 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2013-10-30 20:22:43 +01:00
|
|
|
|
2014-09-03 20:00:03 +02:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
2014-06-11 11:57:49 +02:00
|
|
|
public class PacketSimpleGui implements IMessageHandler<SimpleGuiMessage, IMessage>
|
2013-10-30 20:22:43 +01:00
|
|
|
{
|
2014-04-20 22:15:44 +02:00
|
|
|
@Override
|
2014-06-11 11:57:49 +02:00
|
|
|
public IMessage onMessage(SimpleGuiMessage message, MessageContext context)
|
2014-04-20 22:15:44 +02:00
|
|
|
{
|
2014-06-11 11:57:49 +02:00
|
|
|
EntityPlayer player = PacketHandler.getPlayer(context);
|
|
|
|
|
2014-06-02 17:33:19 +02:00
|
|
|
if(!player.worldObj.isRemote)
|
|
|
|
{
|
2014-06-11 11:57:49 +02:00
|
|
|
World worldServer = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(message.coord4D.dimensionId);
|
2014-04-20 22:15:44 +02:00
|
|
|
|
2014-06-11 11:57:49 +02:00
|
|
|
if(worldServer != null && message.coord4D.getTileEntity(worldServer) instanceof TileEntityBasicBlock)
|
2014-06-02 17:33:19 +02:00
|
|
|
{
|
2014-06-11 11:57:49 +02:00
|
|
|
if(message.guiId == -1)
|
2014-06-02 17:33:19 +02:00
|
|
|
{
|
2014-06-11 11:57:49 +02:00
|
|
|
return null;
|
2014-06-02 17:33:19 +02:00
|
|
|
}
|
|
|
|
|
2014-06-11 11:57:49 +02:00
|
|
|
SimpleGuiMessage.openServerGui(message.guiId, (EntityPlayerMP)player, player.worldObj, message.coord4D);
|
2014-06-02 17:33:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2014-06-11 11:57:49 +02:00
|
|
|
FMLCommonHandler.instance().showGuiScreen(SimpleGuiMessage.getGui(message.guiId, player, player.worldObj, message.coord4D));
|
2014-07-22 01:15:27 +02:00
|
|
|
player.openContainer.windowId = message.windowId;
|
2014-06-02 17:33:19 +02:00
|
|
|
}
|
2014-06-11 11:57:49 +02:00
|
|
|
|
|
|
|
return null;
|
2014-04-20 22:15:44 +02:00
|
|
|
}
|
2014-06-11 11:57:49 +02:00
|
|
|
|
|
|
|
public static class SimpleGuiMessage implements IMessage
|
2014-04-20 22:15:44 +02:00
|
|
|
{
|
2014-06-11 11:57:49 +02:00
|
|
|
public Coord4D coord4D;
|
|
|
|
|
|
|
|
public int guiId;
|
|
|
|
|
2014-07-22 01:15:27 +02:00
|
|
|
public int windowId;
|
|
|
|
|
2014-06-11 11:57:49 +02:00
|
|
|
public SimpleGuiMessage() {}
|
|
|
|
|
|
|
|
public SimpleGuiMessage(Coord4D coord, int gui)
|
|
|
|
{
|
|
|
|
coord4D = coord;
|
|
|
|
guiId = gui;
|
|
|
|
}
|
2014-07-22 01:15:27 +02:00
|
|
|
|
|
|
|
public SimpleGuiMessage(Coord4D coord, int gui, int id)
|
|
|
|
{
|
|
|
|
this(coord, gui);
|
|
|
|
windowId = id;
|
|
|
|
}
|
2014-06-11 11:57:49 +02:00
|
|
|
|
|
|
|
public static void openServerGui(int id, EntityPlayerMP playerMP, World world, Coord4D obj)
|
|
|
|
{
|
|
|
|
playerMP.closeContainer();
|
|
|
|
playerMP.getNextWindowId();
|
|
|
|
|
|
|
|
int window = playerMP.currentWindowId;
|
|
|
|
|
2014-07-22 01:15:27 +02:00
|
|
|
Mekanism.packetHandler.sendTo(new SimpleGuiMessage(obj, id, window), playerMP);
|
2014-06-11 11:57:49 +02:00
|
|
|
|
|
|
|
playerMP.openContainer = Mekanism.proxy.getServerGui(id, playerMP, world, obj.xCoord, obj.yCoord, obj.zCoord);
|
|
|
|
playerMP.openContainer.windowId = window;
|
|
|
|
playerMP.openContainer.addCraftingToCrafters(playerMP);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public static GuiScreen getGui(int id, EntityPlayer player, World world, Coord4D obj)
|
|
|
|
{
|
|
|
|
return (GuiScreen)Mekanism.proxy.getClientGui(id, player, world, obj.xCoord, obj.yCoord, obj.zCoord);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void toBytes(ByteBuf dataStream)
|
|
|
|
{
|
|
|
|
dataStream.writeInt(coord4D.xCoord);
|
|
|
|
dataStream.writeInt(coord4D.yCoord);
|
|
|
|
dataStream.writeInt(coord4D.zCoord);
|
|
|
|
|
|
|
|
dataStream.writeInt(coord4D.dimensionId);
|
|
|
|
|
|
|
|
dataStream.writeInt(guiId);
|
2014-07-22 01:15:27 +02:00
|
|
|
dataStream.writeInt(windowId);
|
2014-06-11 11:57:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void fromBytes(ByteBuf dataStream)
|
|
|
|
{
|
|
|
|
coord4D = new Coord4D(dataStream.readInt(), dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
|
|
|
|
|
|
|
|
guiId = dataStream.readInt();
|
2014-07-22 01:15:27 +02:00
|
|
|
windowId = dataStream.readInt();
|
2014-06-11 11:57:49 +02:00
|
|
|
}
|
2014-04-20 22:15:44 +02:00
|
|
|
}
|
2013-10-30 20:22:43 +01:00
|
|
|
}
|