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();
}
}
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);
}
}
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);
}
}
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));
}
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);
}
Aggregations