Search in sources :

Example 71 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project SpongeVanilla by SpongePowered.

the class VanillaIndexedMessageChannel method createPacket.

private SPacketCustomPayload createPacket(Message message) {
    Class<? extends Message> messageClass = message.getClass();
    IndexedMessageType<?> type = this.messageClasses.get(messageClass);
    checkNotNull(type, "Unknown message type %s of %s", messageClass, message);
    PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
    buffer.writeByte(type.id);
    buffer.markWriterIndex();
    message.writeTo(SpongeNetworkManager.toChannelBuf(buffer));
    return new SPacketCustomPayload(getName(), buffer);
}
Also used : SPacketCustomPayload(net.minecraft.network.play.server.SPacketCustomPayload) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 72 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project Bewitchment by Um-Mitternacht.

the class ParticleMessage method toBytes.

@Override
public void toBytes(ByteBuf byteBuf) {
    PacketBuffer buf = new PacketBuffer(byteBuf);
    buf.writeEnumValue(particleF);
    buf.writeDouble(x);
    buf.writeDouble(y);
    buf.writeDouble(z);
    buf.writeInt(amount);
    buf.writeDouble(xSpeed);
    buf.writeDouble(ySpeed);
    buf.writeDouble(zSpeed);
    buf.writeInt(args.length);
    for (int arg : args) {
        buf.writeInt(arg);
    }
}
Also used : PacketBuffer(net.minecraft.network.PacketBuffer)

Example 73 with PacketBuffer

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

the class MessageWireSystems method toBytes.

@Override
public void toBytes(ByteBuf buf) {
    PacketBuffer pb = new PacketBuffer(buf);
    pb.writeInt(wireSystems.size());
    wireSystems.forEach((wiresHashCode, wireSystem) -> {
        pb.writeInt(wiresHashCode);
        List<WireSystem.WireElement> elements = wireSystem.elements.stream().filter(element -> element.type == WireSystem.WireElement.Type.WIRE_PART).collect(Collectors.toList());
        pb.writeInt(elements.size());
        elements.forEach(element -> element.toBytes(pb));
    });
}
Also used : List(java.util.List) ByteBuf(io.netty.buffer.ByteBuf) Map(java.util.Map) IMessage(net.minecraftforge.fml.common.network.simpleimpl.IMessage) IMessageHandler(net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) PacketBuffer(net.minecraft.network.PacketBuffer) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 74 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project artisan-worktables by codetaylor.

the class CPacketWorktableFluidUpdate method toBytes.

@Override
public void toBytes(ByteBuf buf) {
    super.toBytes(buf);
    PacketBuffer packetBuffer = new PacketBuffer(buf);
    packetBuffer.writeCompoundTag(this.fluidTank.writeToNBT(new NBTTagCompound()));
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 75 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project artisan-worktables by codetaylor.

the class CPacketWorktableFluidUpdate method fromBytes.

@Override
public void fromBytes(ByteBuf buf) {
    super.fromBytes(buf);
    PacketBuffer packetBuffer = new PacketBuffer(buf);
    try {
        NBTTagCompound compound = packetBuffer.readCompoundTag();
        this.fluidTank = new FluidTank(0);
        if (compound != null) {
            this.fluidTank.readFromNBT(compound);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : FluidTank(net.minecraftforge.fluids.FluidTank) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOException(java.io.IOException) 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