Search in sources :

Example 1 with AbstractData

use of hellfirepvp.fracture.common.data.AbstractData 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 2 with AbstractData

use of hellfirepvp.fracture.common.data.AbstractData 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 3 with AbstractData

use of hellfirepvp.fracture.common.data.AbstractData in project Fracture by HellFirePvP.

the class PktSyncData method toBytes.

@Override
public void toBytes(ByteBuf buf) {
    buf.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(buf, key);
        byte providerId = dat.getProviderID();
        buf.writeByte(providerId);
        try {
            CompressedStreamTools.write(cmp, new ByteBufOutputStream(buf));
        } catch (IOException ignored) {
        }
    }
}
Also used : AbstractData(hellfirepvp.fracture.common.data.AbstractData) ByteBufOutputStream(io.netty.buffer.ByteBufOutputStream) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOException(java.io.IOException)

Example 4 with AbstractData

use of hellfirepvp.fracture.common.data.AbstractData in project Fracture by HellFirePvP.

the class PktSyncData method fromBytes.

@Override
public void fromBytes(ByteBuf buf) {
    int size = buf.readInt();
    for (int i = 0; i < size; i++) {
        String key = ByteBufUtils.readString(buf);
        byte providerId = buf.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 = CompressedStreamTools.read(new ByteBufInputStream(buf), NBTSizeTracker.INFINITE);
        } 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) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) IOException(java.io.IOException)

Aggregations

AbstractData (hellfirepvp.fracture.common.data.AbstractData)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 IOException (java.io.IOException)3 PacketBuffer (net.minecraft.network.PacketBuffer)2 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)1 ByteBufOutputStream (io.netty.buffer.ByteBufOutputStream)1