Search in sources :

Example 21 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project Solar by ArekkuusuJerii.

the class ClientToServerPacket method toBytes.

@Override
public void toBytes(ByteBuf buf) {
    PacketBuffer beef = new PacketBuffer(buf);
    try {
        buf.writeInt(PacketHandler.HANDLERS.indexOf(handler));
        beef.writeCompoundTag(data);
    } catch (Exception e) {
        Solar.LOG.error("[Packet] Failed to send packet");
        e.printStackTrace();
    }
}
Also used : PacketBuffer(net.minecraft.network.PacketBuffer)

Example 22 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project SomeModjam5Mod by HellFirePvP.

the class PktSyncData method toBytes.

@Override
public void toBytes(ByteBuf buf) {
    PacketBuffer pb = new PacketBuffer(buf);
    pb.writeInt(data.size());
    for (String key : data.keySet()) {
        AbstractData dat = data.get(key);
        NBTTagCompound cmp = new NBTTagCompound();
        if (shouldSyncAll) {
            dat.writeAllDataToPacket(cmp);
        } else {
            dat.writeToPacket(cmp);
        }
        ByteBufUtils.writeString(pb, key);
        byte providerId = dat.getProviderID();
        pb.writeByte(providerId);
        pb.writeCompoundTag(cmp);
    }
}
Also used : AbstractData(hellfirepvp.fracture.common.data.AbstractData) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 23 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project SomeModjam5Mod by HellFirePvP.

the class PktSyncData method fromBytes.

@Override
public void fromBytes(ByteBuf buf) {
    PacketBuffer pb = new PacketBuffer(buf);
    int size = pb.readInt();
    for (int i = 0; i < size; i++) {
        String key = ByteBufUtils.readString(pb);
        byte providerId = pb.readByte();
        AbstractData.AbstractDataProvider<? extends AbstractData> provider = AbstractData.Registry.getProvider(providerId);
        if (provider == null) {
            Fracture.log.warn("[Fracture] Provider for ID " + providerId + " doesn't exist! Skipping...");
            continue;
        }
        NBTTagCompound cmp;
        try {
            cmp = pb.readCompoundTag();
        } catch (IOException e) {
            Fracture.log.warn("[Fracture] Provider Compound of " + providerId + " threw an IOException! Skipping...");
            Fracture.log.warn("[Fracture] Exception message: " + e.getMessage());
            continue;
        }
        AbstractData dat = provider.provideNewInstance();
        dat.readRawFromPacket(cmp);
        data.put(key, dat);
    }
}
Also used : AbstractData(hellfirepvp.fracture.common.data.AbstractData) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOException(java.io.IOException) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 24 with PacketBuffer

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

the class VanillaChannelRegistrar method registerChannels.

public void registerChannels(NetHandlerPlayServer netHandler) {
    // Register our channel list on the client
    String channels = CHANNEL_JOINER.join(this.channels.keySet());
    PacketBuffer buffer = new PacketBuffer(Unpooled.wrappedBuffer(channels.getBytes(StandardCharsets.UTF_8)));
    netHandler.sendPacket(new SPacketCustomPayload(REGISTER_CHANNEL, buffer));
}
Also used : SPacketCustomPayload(net.minecraft.network.play.server.SPacketCustomPayload) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 25 with PacketBuffer

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

the class VanillaRawDataChannel method createPacket.

private SPacketCustomPayload createPacket(Consumer<ChannelBuf> consumer) {
    PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
    consumer.accept((ChannelBuf) buffer);
    return new SPacketCustomPayload(getName(), buffer);
}
Also used : SPacketCustomPayload(net.minecraft.network.play.server.SPacketCustomPayload) PacketBuffer(net.minecraft.network.PacketBuffer)

Aggregations

PacketBuffer (net.minecraft.network.PacketBuffer)103 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)18 FMLProxyPacket (net.minecraftforge.fml.common.network.internal.FMLProxyPacket)14 IOException (java.io.IOException)13 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