Skip to content

Instantly share code, notes, and snippets.

@adudewithapc
Created July 16, 2017 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adudewithapc/b25cf08bcfc8653faf0de6e7cdd25c27 to your computer and use it in GitHub Desktop.
Save adudewithapc/b25cf08bcfc8653faf0de6e7cdd25c27 to your computer and use it in GitHub Desktop.
package thatmartinguy.jeopardy.network;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import thatmartinguy.jeopardy.Jeopardy;
public class OpenGuiMessage implements IMessage
{
private int guiID = -1;
private int posX;
private int posY;
private int posZ;
public OpenGuiMessage() {}
public OpenGuiMessage(int id, Entity entity)
{
this(id, (int) entity.posX, (int) entity.posY, (int) entity.posZ);
}
public OpenGuiMessage(int id, BlockPos pos)
{
this(id, pos.getX(), pos.getY(), pos.getZ());
}
public OpenGuiMessage(int id, int posX, int posY, int posZ)
{
this.guiID = id;
this.posX = posX;
this.posY = posY;
this.posZ = posZ;
}
@Override
public void fromBytes(ByteBuf buf)
{
guiID = buf.readInt();
posX = buf.readInt();
posY = buf.readInt();
posZ = buf.readInt();
}
@Override
public void toBytes(ByteBuf buf)
{
buf.writeInt(guiID);
buf.writeInt(posX);
buf.writeInt(posY);
buf.writeInt(posZ);
}
public static class Handler implements IMessageHandler<OpenGuiMessage, IMessage>
{
@Override
public IMessage onMessage(OpenGuiMessage message, MessageContext ctx)
{
Jeopardy.proxy.getThreadListener(ctx).addScheduledTask(() ->
{
final EntityPlayer player = Jeopardy.proxy.getPlayer(ctx);
player.openGui(Jeopardy.instance, message.guiID, player.world, message.posX, message.posY, message.posZ);
});
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment