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