Search in sources :

Example 46 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project Railcraft by Railcraft.

the class RailcraftPacket method getPacket.

public FMLProxyPacket getPacket() {
    ByteBuf byteBuf = Unpooled.buffer();
    try (ByteBufOutputStream out = new ByteBufOutputStream(byteBuf);
        RailcraftOutputStream data = new RailcraftOutputStream(out)) {
        data.writeByte(getID());
        writeData(data);
        return new FMLProxyPacket(new PacketBuffer(byteBuf), CHANNEL_NAME);
    } catch (IOException e) {
        Game.log().throwable("Error constructing packet: {0}", e, getClass());
        if (Game.DEVELOPMENT_VERSION)
            throw new RuntimeException(e);
    }
    PacketBuffer buffer = new PacketBuffer(byteBuf);
    buffer.writeByte(-1);
    return new FMLProxyPacket(buffer, CHANNEL_NAME);
}
Also used : ByteBufOutputStream(io.netty.buffer.ByteBufOutputStream) FMLProxyPacket(net.minecraftforge.fml.common.network.internal.FMLProxyPacket) IOException(java.io.IOException) ByteBuf(io.netty.buffer.ByteBuf) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 47 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project LogisticsPipes by RS485.

the class PacketHandler method toFMLPacket.

private static FMLProxyPacket toFMLPacket(ModernPacket msg, String channel) {
    ByteBuf buffer = Unpooled.buffer();
    fillByteBuf(msg, buffer);
    return new FMLProxyPacket(new PacketBuffer(buffer), channel);
}
Also used : FMLProxyPacket(net.minecraftforge.fml.common.network.internal.FMLProxyPacket) ByteBuf(io.netty.buffer.ByteBuf) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 48 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project pnc-repressurized by TeamPneumatic.

the class PacketUpdateGui method readField.

public static Object readField(ByteBuf buf, int type) {
    switch(type) {
        case 0:
            return buf.readInt();
        case 1:
            return buf.readFloat();
        case 2:
            return buf.readDouble();
        case 3:
            return buf.readBoolean();
        case 4:
            return ByteBufUtils.readUTF8String(buf);
        case 5:
            return buf.readByte();
        case 6:
            return ByteBufUtils.readItemStack(buf);
        case 7:
            if (!buf.readBoolean())
                return null;
            return new FluidStack(FluidRegistry.getFluid(ByteBufUtils.readUTF8String(buf)), buf.readInt(), ByteBufUtils.readTag(buf));
        case 8:
            try {
                PacketBuffer packetBuffer = new PacketBuffer(buf);
                NBTTagCompound tag = packetBuffer.readCompoundTag();
                if (tag == null)
                    return EmptyHandler.INSTANCE;
                ItemStackHandler handler = new ItemStackHandler();
                handler.deserializeNBT(tag);
                return handler;
            } catch (IOException e) {
                return EmptyHandler.INSTANCE;
            }
    }
    throw new IllegalArgumentException("Invalid sync type! " + type);
}
Also used : ItemStackHandler(net.minecraftforge.items.ItemStackHandler) FluidStack(net.minecraftforge.fluids.FluidStack) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOException(java.io.IOException) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 49 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project pnc-repressurized by TeamPneumatic.

the class PacketUpdateGui method writeField.

public static void writeField(ByteBuf buf, Object value, int type) {
    switch(type) {
        case 0:
            buf.writeInt((Integer) value);
            break;
        case 1:
            buf.writeFloat((Float) value);
            break;
        case 2:
            buf.writeDouble((Double) value);
            break;
        case 3:
            buf.writeBoolean((Boolean) value);
            break;
        case 4:
            ByteBufUtils.writeUTF8String(buf, (String) value);
            break;
        case 5:
            buf.writeByte((Byte) value);
            break;
        case 6:
            ByteBufUtils.writeItemStack(buf, (ItemStack) value);
            break;
        case 7:
            buf.writeBoolean(value != null);
            if (value != null) {
                FluidStack stack = (FluidStack) value;
                ByteBufUtils.writeUTF8String(buf, stack.getFluid().getName());
                buf.writeInt(stack.amount);
                ByteBufUtils.writeTag(buf, stack.tag);
            }
            break;
        case 8:
            NBTTagCompound tag = ((ItemStackHandler) value).serializeNBT();
            PacketBuffer packetBuffer = new PacketBuffer(buf);
            packetBuffer.writeCompoundTag(tag);
            break;
    }
}
Also used : ItemStackHandler(net.minecraftforge.items.ItemStackHandler) FluidStack(net.minecraftforge.fluids.FluidStack) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 50 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project pnc-repressurized by TeamPneumatic.

the class DescPacketHandler method getPacket.

public static FMLProxyPacket getPacket(PacketDescription packet) {
    ByteBuf buf = Unpooled.buffer();
    packet.toBytes(buf);
    return new FMLProxyPacket(new PacketBuffer(buf), CHANNEL);
}
Also used : FMLProxyPacket(net.minecraftforge.fml.common.network.internal.FMLProxyPacket) ByteBuf(io.netty.buffer.ByteBuf) PacketBuffer(net.minecraft.network.PacketBuffer)

Aggregations

PacketBuffer (net.minecraft.network.PacketBuffer)105 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)20 IOException (java.io.IOException)14 FMLProxyPacket (net.minecraftforge.fml.common.network.internal.FMLProxyPacket)14 ByteBuf (io.netty.buffer.ByteBuf)11 SPacketCustomPayload (net.minecraft.network.play.server.SPacketCustomPayload)7 BlockPos (net.minecraft.util.math.BlockPos)7 HashMap (java.util.HashMap)4 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)4 DimensionDescriptor (mcjty.rftoolsdim.dimensions.description.DimensionDescriptor)4 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 NetHandlerPlayServer (net.minecraft.network.NetHandlerPlayServer)3 Test (org.junit.Test)3 PacketBufferBC (buildcraft.lib.net.PacketBufferBC)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 PacketCustomTileData (gregtech.api.net.PacketCustomTileData)2 PacketUIWidgetUpdate (gregtech.api.net.PacketUIWidgetUpdate)2 AbstractData (hellfirepvp.fracture.common.data.AbstractData)2