cpw.mods.fml.common.network.internal.FMLProxyPacket Java Examples

The following examples show how to use cpw.mods.fml.common.network.internal.FMLProxyPacket. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DragonsRadioProtector.java    From ehacks-pro with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean isPacketOk(Object packet, PacketHandler.Side side) {
    try {
        if (packet instanceof FMLProxyPacket && "DragonsRadioMod".equals(((FMLProxyPacket) packet).channel()) && side == PacketHandler.Side.IN) {
            FMLProxyPacket fmlPacket = (FMLProxyPacket) packet;
            ByteBuf buf = Unpooled.copiedBuffer(fmlPacket.payload());
            if (buf.readByte() != 0) {
                return true;
            }
            buf.readInt();
            TileEntity entity = Wrapper.INSTANCE.world().getTileEntity((int) buf.readDouble(), (int) buf.readDouble(), (int) buf.readDouble());
            return !(entity == null || !Class.forName("eu.thesociety.DragonbornSR.DragonsRadioMod.Block.TileEntity.TileEntityRadio").isInstance(entity));
        } else {
            return true;
        }
    } catch (Exception e) {
        return false;
    }
}
 
Example #2
Source File: ASMessagePipeline.java    From archimedes-ships with MIT License 6 votes vote down vote up
@Override
protected void encode(ChannelHandlerContext ctx, ASMessage msg, List<Object> out) throws Exception
{
	ByteBuf buffer = Unpooled.buffer();
	Class<? extends ASMessage> clazz = msg.getClass();
	if (!packets.contains(msg.getClass()))
	{
		throw new NullPointerException("No Packet Registered for: " + msg.getClass().getCanonicalName());
	}
	
	byte discriminator = (byte) packets.indexOf(clazz);
	buffer.writeByte(discriminator);
	try
	{
		msg.encodeInto(ctx, buffer);
	} catch (IOException e)
	{
		e.printStackTrace();
		throw e;
	}
	FMLProxyPacket proxyPacket = new FMLProxyPacket(buffer, ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
	out.add(proxyPacket);
}
 
Example #3
Source File: PacketPipeline.java    From NBTEdit with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception {
    ByteBuf payload = msg.payload();
    byte discriminator = payload.readByte();
    Class<? extends AbstractPacket> clazz = this.packets.get(discriminator);

    AbstractPacket pkt = clazz.newInstance();
    pkt.decodeInto(ctx, payload.slice());

    switch (FMLCommonHandler.instance().getEffectiveSide()) {
        case CLIENT:
            pkt.handleClientSide(this.getClientPlayer());
            break;
        case SERVER:
            INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
            pkt.handleServerSide(((NetHandlerPlayServer) netHandler).playerEntity);
            break;
        default:
        	break;
    }

    out.add(pkt);
}
 
Example #4
Source File: PacketCreateView.java    From LookingGlass with GNU General Public License v3.0 6 votes vote down vote up
@SideOnly(Side.CLIENT)
public static FMLProxyPacket createPacket(WorldView worldview) {
	// This line may look like black magic (and, well, it is), but it's actually just returning a class reference for this class. Copy-paste safe.
	ByteBuf data = PacketHandlerBase.createDataBuffer((Class<? extends PacketHandlerBase>) new Object() {}.getClass().getEnclosingClass());

	int x = 0;
	int y = -1;
	int z = 0;
	if (worldview.coords != null) {
		x = worldview.coords.posX >> 4;
		y = worldview.coords.posY >> 4;
		z = worldview.coords.posZ >> 4;
	}

	data.writeInt(worldview.getWorldObj().provider.dimensionId);
	data.writeInt(x);
	data.writeInt(y);
	data.writeInt(z);
	data.writeByte(Math.min(ModConfigs.renderDistance, Minecraft.getMinecraft().gameSettings.renderDistanceChunks));

	return buildPacket(data);
}
 
Example #5
Source File: TileEntityAdvancedMod.java    From AdvancedMod with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Packet getDescriptionPacket(){
    ByteBuf buf = Unpooled.buffer();
    buf.writeInt(xCoord);
    buf.writeInt(yCoord);
    buf.writeInt(zCoord);
    writeToPacket(buf);
    return new FMLProxyPacket(buf, DescriptionHandler.CHANNEL);
}
 
Example #6
Source File: DescriptionHandler.java    From AdvancedMod with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext ctx, FMLProxyPacket msg) throws Exception{
    ByteBuf buf = msg.payload();
    int x = buf.readInt();
    int y = buf.readInt();
    int z = buf.readInt();
    TileEntity te = AdvancedMod.proxy.getClientPlayer().worldObj.getTileEntity(x, y, z);
    if(te instanceof TileEntityAdvancedMod) {
        ((TileEntityAdvancedMod)te).readFromPacket(buf);
    }
}
 
Example #7
Source File: PacketPipeline.java    From NBTEdit with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void encode(ChannelHandlerContext ctx, AbstractPacket msg, List<Object> out) throws Exception {
    ByteBuf buffer = Unpooled.buffer();
    Class<? extends AbstractPacket> clazz = msg.getClass();
    
    byte discriminator = (byte) this.packets.indexOf(clazz);
    buffer.writeByte(discriminator);
    msg.encodeInto(ctx, buffer);
    FMLProxyPacket proxyPacket = new FMLProxyPacket(buffer.copy(), ctx.channel().attr(NetworkRegistry.FML_CHANNEL).get());
    out.add(proxyPacket);
}
 
Example #8
Source File: PacketRequestChunk.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
public static FMLProxyPacket createPacket(int xPos, int yPos, int zPos, int dim) {
	// This line may look like black magic (and, well, it is), but it's actually just returning a class reference for this class. Copy-paste safe.
	ByteBuf data = PacketHandlerBase.createDataBuffer((Class<? extends PacketHandlerBase>) new Object() {}.getClass().getEnclosingClass());

	data.writeInt(dim);
	data.writeInt(xPos);
	data.writeInt(yPos);
	data.writeInt(zPos);

	return buildPacket(data);
}
 
Example #9
Source File: PacketRequestWorldInfo.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
@SideOnly(Side.CLIENT)
public static FMLProxyPacket createPacket(int xPos, int yPos, int zPos, int dim) {
	// This line may look like black magic (and, well, it is), but it's actually just returning a class reference for this class. Copy-paste safe.
	ByteBuf data = PacketHandlerBase.createDataBuffer((Class<? extends PacketHandlerBase>) new Object() {}.getClass().getEnclosingClass());

	data.writeInt(dim);

	return buildPacket(data);
}
 
Example #10
Source File: PacketTileEntityNBT.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
public static FMLProxyPacket createPacket(int xPos, int yPos, int zPos, NBTTagCompound nbt, int dim) {
	// This line may look like black magic (and, well, it is), but it's actually just returning a class reference for this class. Copy-paste safe.
	ByteBuf data = PacketHandlerBase.createDataBuffer((Class<? extends PacketHandlerBase>) new Object() {}.getClass().getEnclosingClass());

	data.writeInt(dim);
	data.writeInt(xPos);
	data.writeInt(yPos);
	data.writeInt(zPos);
	ByteBufUtils.writeTag(data, nbt);

	return buildPacket(data);
}
 
Example #11
Source File: PacketChunkInfo.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
public static FMLProxyPacket createPacket(Chunk chunk, boolean includeinit, int subid, int dim) {
	int xPos = chunk.xPosition;
	int zPos = chunk.zPosition;
	Extracted extracted = getMapChunkData(chunk, includeinit, subid);
	int yMSBPos = extracted.field_150281_c;
	int yPos = extracted.field_150280_b;
	byte[] chunkData = extracted.field_150282_a;

	deflateGate.acquireUninterruptibly();
	byte[] compressedChunkData = new byte[chunkData.length];
	int len = deflate(chunkData, compressedChunkData);
	deflateGate.release();

	// This line may look like black magic (and, well, it is), but it's actually just returning a class reference for this class. Copy-paste safe.
	ByteBuf data = PacketHandlerBase.createDataBuffer((Class<? extends PacketHandlerBase>) new Object() {}.getClass().getEnclosingClass());

	data.writeInt(dim);
	data.writeInt(xPos);
	data.writeInt(zPos);
	data.writeBoolean(includeinit);
	data.writeShort((short) (yPos & 65535));
	data.writeShort((short) (yMSBPos & 65535));
	data.writeInt(len);
	data.writeInt(chunkData.length);
	data.ensureWritable(len);
	data.writeBytes(compressedChunkData, 0, len);

	return buildPacket(data);
}
 
Example #12
Source File: PacketWorldInfo.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
public static FMLProxyPacket createPacket(int dimension) {
	WorldServer world = MinecraftServer.getServer().worldServerForDimension(dimension);
	if (world == null) {
		LoggerUtils.warn("Server-side world for dimension %i is null!", dimension);
		return null;
	}
	ChunkCoordinates cc = world.provider.getSpawnPoint();
	int posX = cc.posX;
	int posY = cc.posY;
	int posZ = cc.posZ;
	int skylightSubtracted = world.skylightSubtracted;
	float thunderingStrength = world.thunderingStrength;
	float rainingStrength = world.rainingStrength;
	long worldTime = world.provider.getWorldTime();

	// This line may look like black magic (and, well, it is), but it's actually just returning a class reference for this class. Copy-paste safe.
	ByteBuf data = PacketHandlerBase.createDataBuffer((Class<? extends PacketHandlerBase>) new Object() {}.getClass().getEnclosingClass());

	data.writeInt(dimension);
	data.writeInt(posX);
	data.writeInt(posY);
	data.writeInt(posZ);
	data.writeInt(skylightSubtracted);
	data.writeFloat(thunderingStrength);
	data.writeFloat(rainingStrength);
	data.writeLong(worldTime);

	return buildPacket(data);
}
 
Example #13
Source File: PacketRequestTE.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
public static FMLProxyPacket createPacket(int xPos, int yPos, int zPos, int dim) {
	// This line may look like black magic (and, well, it is), but it's actually just returning a class reference for this class. Copy-paste safe.
	ByteBuf data = PacketHandlerBase.createDataBuffer((Class<? extends PacketHandlerBase>) new Object() {}.getClass().getEnclosingClass());

	data.writeInt(dim);
	data.writeInt(xPos);
	data.writeInt(yPos);
	data.writeInt(zPos);

	return buildPacket(data);
}
 
Example #14
Source File: PacketCloseView.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
@SideOnly(Side.CLIENT)
public static FMLProxyPacket createPacket(WorldView worldview) {
	// This line may look like black magic (and, well, it is), but it's actually just returning a class reference for this class. Copy-paste safe.
	ByteBuf data = PacketHandlerBase.createDataBuffer((Class<? extends PacketHandlerBase>) new Object() {}.getClass().getEnclosingClass());

	return buildPacket(data);
}
 
Example #15
Source File: LookingGlassPacketManager.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onPacketData(ClientCustomPacketEvent event) {
	FMLProxyPacket pkt = event.packet;

	onPacketData(event.manager, pkt, Minecraft.getMinecraft().thePlayer);
}
 
Example #16
Source File: Debug.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
public static void sendProxyPacket(String channel, Object... data) {
    ByteBuf buf = Unpooled.buffer();
    for (Object o : data) {
        if (o instanceof Integer) {
            buf.writeInt(((int) o));
            continue;
        }
        if (o instanceof Byte) {
            buf.writeByte(((byte) o));
            continue;
        }
        if (o instanceof Short) {
            buf.writeShort(((short) o));
            continue;
        }
        if (o instanceof String) {
            ByteBufUtils.writeUTF8String(buf, ((String) o));
            continue;
        }
        if (o instanceof ItemStack) {
            ByteBufUtils.writeItemStack(buf, ((ItemStack) o));
            continue;
        }
        if (!(o instanceof NBTTagCompound)) {
            continue;
        }
        ByteBufUtils.writeTag(buf, ((NBTTagCompound) o));
    }
    NetworkDispatcher.get(Wrapper.INSTANCE.mc().getNetHandler().getNetworkManager()).sendProxy(new FMLProxyPacket(buf, channel));
}
 
Example #17
Source File: ASMessagePipeline.java    From archimedes-ships with MIT License 4 votes vote down vote up
@Override
protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception
{
	ByteBuf payload = msg.payload();
	byte discriminator = payload.readByte();
	Class<? extends ASMessage> clazz = packets.get(discriminator);
	if (clazz == null)
	{
		throw new NullPointerException("No packet registered for discriminator: " + discriminator);
	}
	
	EntityPlayer player = null;
	Side side = FMLCommonHandler.instance().getEffectiveSide();
	switch (side)
	{
	case CLIENT:
		player = getClientPlayer();
		break;
	case SERVER:
		INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
		player = ((NetHandlerPlayServer) netHandler).playerEntity;
		break;
	default:
	}
	
	ASMessage pkt = clazz.newInstance();
	try
	{
		pkt.decodeInto(ctx, payload.slice(), player);
	} catch (IOException e)
	{
		e.printStackTrace();
		throw e;
	}
	
	switch (side)
	{
	case CLIENT:
		pkt.handleClientSide(player);
		break;
	case SERVER:
		pkt.handleServerSide(player);
		break;
	default:
	}
	
	out.add(pkt);
}
 
Example #18
Source File: DescPacketHandler.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext ctx, FMLProxyPacket msg) throws Exception{
    PacketDescription packet = new PacketDescription();
    packet.fromBytes(msg.payload());
    packet.handleClientSide(packet, PneumaticCraft.proxy.getPlayer());
}
 
Example #19
Source File: DescPacketHandler.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public static FMLProxyPacket getPacket(PacketDescription packet){
    ByteBuf buf = Unpooled.buffer();
    packet.toBytes(buf);
    return new FMLProxyPacket(buf, CHANNEL);
}
 
Example #20
Source File: BW_Network.java    From bartworks with MIT License 4 votes vote down vote up
protected void decode(ChannelHandlerContext aContext, FMLProxyPacket aPacket, List<Object> aOutput) throws Exception {
    ByteArrayDataInput aData = ByteStreams.newDataInput(aPacket.payload().array());
    aOutput.add(this.mSubChannels[aData.readByte()].decode(aData));
}
 
Example #21
Source File: QCraft.java    From qcraft-mod with Apache License 2.0 4 votes vote down vote up
private static FMLProxyPacket encode( QCraftPacket packet )
{
    ByteBuf buffer = Unpooled.buffer();
    packet.toBytes( buffer );
    return new FMLProxyPacket( buffer, "qCraft" );
}
 
Example #22
Source File: ServerPacketDispatcher.java    From LookingGlass with GNU General Public License v3.0 4 votes vote down vote up
public void addPacket(EntityPlayer player, FMLProxyPacket packet) {
	synchronized (this) {
		packets.add(new PacketHolder(player, packet));
		this.notify();
	}
}
 
Example #23
Source File: PacketHolder.java    From LookingGlass with GNU General Public License v3.0 4 votes vote down vote up
public PacketHolder(EntityPlayer player, FMLProxyPacket packet) {
	this.player = player;
	this.packet = packet;
}
 
Example #24
Source File: LookingGlassPacketManager.java    From LookingGlass with GNU General Public License v3.0 4 votes vote down vote up
@SubscribeEvent
public void onPacketData(ServerCustomPacketEvent event) {
	FMLProxyPacket pkt = event.packet;

	onPacketData(event.manager, pkt, ((NetHandlerPlayServer) event.handler).playerEntity);
}
 
Example #25
Source File: BW_Network.java    From bartworks with MIT License 4 votes vote down vote up
protected void encode(ChannelHandlerContext aContext, GT_Packet aPacket, List<Object> aOutput) throws Exception {
    aOutput.add(new FMLProxyPacket(Unpooled.buffer().writeByte(aPacket.getPacketID()).writeBytes(aPacket.encode()).copy(), (String) aContext.channel().attr(NetworkRegistry.FML_CHANNEL).get()));
}
 
Example #26
Source File: PacketHandlerBase.java    From LookingGlass with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Used by the progeny of this class in order to produce a packet object from the data buffer. Automatically uses our packet channel so that the manager on
 * the other side will receive the packet.
 */
protected static FMLProxyPacket buildPacket(ByteBuf payload) {
	return new FMLProxyPacket(payload, LookingGlassPacketManager.CHANNEL);
}