use of micdoodle8.mods.galacticraft.core.tile.FluidTankGC in project Galacticraft by micdoodle8.
the class NetworkUtil method readFluidTankGC.
public static FluidTankGC readFluidTankGC(ByteBuf buffer, World world) throws IOException {
BlockPos pos = new BlockPos(buffer.readInt(), buffer.readInt(), buffer.readInt());
TileEntity tile = world.getTileEntity(pos);
int capacity = buffer.readInt();
String fluidName = ByteBufUtils.readUTF8String(buffer);
FluidTankGC fluidTank = new FluidTankGC(capacity, tile);
int amount = buffer.readInt();
if (fluidName.equals("")) {
fluidTank.setFluid(null);
} else {
Fluid fluid = FluidRegistry.getFluid(fluidName);
fluidTank.setFluid(new FluidStack(fluid, amount));
}
return fluidTank;
}
use of micdoodle8.mods.galacticraft.core.tile.FluidTankGC in project Galacticraft by micdoodle8.
the class NetworkUtil method encodeData.
public static void encodeData(ByteBuf buffer, Collection<Object> sendData) throws IOException {
for (Object dataValue : sendData) {
if (dataValue instanceof Integer) {
buffer.writeInt((Integer) dataValue);
} else if (dataValue instanceof Float) {
buffer.writeFloat((Float) dataValue);
} else if (dataValue instanceof Double) {
buffer.writeDouble((Double) dataValue);
} else if (dataValue instanceof Byte) {
buffer.writeByte((Byte) dataValue);
} else if (dataValue instanceof Boolean) {
buffer.writeBoolean((Boolean) dataValue);
} else if (dataValue instanceof String) {
ByteBufUtils.writeUTF8String(buffer, (String) dataValue);
} else if (dataValue instanceof Short) {
buffer.writeShort((Short) dataValue);
} else if (dataValue instanceof Long) {
buffer.writeLong((Long) dataValue);
} else if (dataValue instanceof EnergyStorage) {
EnergyStorage storage = (EnergyStorage) dataValue;
buffer.writeFloat(storage.getCapacityGC());
buffer.writeFloat(storage.getMaxReceive());
buffer.writeFloat(storage.getMaxExtract());
buffer.writeFloat(storage.getEnergyStoredGC());
} else if (dataValue instanceof NBTTagCompound) {
NetworkUtil.writeNBTTagCompound((NBTTagCompound) dataValue, buffer);
} else if (dataValue instanceof FluidTankGC) {
FluidTankGC tankGC = (FluidTankGC) dataValue;
BlockPos pos = tankGC.getTilePosition();
buffer.writeInt(pos.getX());
buffer.writeInt(pos.getY());
buffer.writeInt(pos.getZ());
NetworkUtil.writeFluidTank((FluidTank) dataValue, buffer);
} else if (dataValue instanceof FluidTank) {
NetworkUtil.writeFluidTank((FluidTank) dataValue, buffer);
} else if (dataValue instanceof Entity) {
buffer.writeInt(((Entity) dataValue).getEntityId());
} else if (dataValue instanceof Vector3) {
buffer.writeDouble(((Vector3) dataValue).x);
buffer.writeDouble(((Vector3) dataValue).y);
buffer.writeDouble(((Vector3) dataValue).z);
} else if (dataValue instanceof BlockVec3) {
buffer.writeInt(((BlockVec3) dataValue).x);
buffer.writeInt(((BlockVec3) dataValue).y);
buffer.writeInt(((BlockVec3) dataValue).z);
} else if (dataValue instanceof byte[]) {
int size = ((byte[]) dataValue).length;
buffer.writeInt(size);
int pos = buffer.writerIndex();
buffer.capacity(pos + size);
buffer.setBytes(pos, (byte[]) dataValue);
buffer.writerIndex(pos + size);
} else if (dataValue instanceof UUID) {
buffer.writeLong(((UUID) dataValue).getLeastSignificantBits());
buffer.writeLong(((UUID) dataValue).getMostSignificantBits());
} else if (dataValue instanceof Collection) {
NetworkUtil.encodeData(buffer, (Collection<Object>) dataValue);
} else if (dataValue instanceof FlagData) {
buffer.writeInt(((FlagData) dataValue).getWidth());
buffer.writeInt(((FlagData) dataValue).getHeight());
for (int i = 0; i < ((FlagData) dataValue).getWidth(); i++) {
for (int j = 0; j < ((FlagData) dataValue).getHeight(); j++) {
Vector3 vec = ((FlagData) dataValue).getColorAt(i, j);
buffer.writeByte((byte) (vec.x * 256 - 128));
buffer.writeByte((byte) (vec.y * 256 - 128));
buffer.writeByte((byte) (vec.z * 256 - 128));
}
}
} else if (dataValue instanceof Integer[]) {
Integer[] array = (Integer[]) dataValue;
buffer.writeInt(array.length);
for (int i = 0; i < array.length; i++) {
buffer.writeInt(array[i]);
}
} else if (dataValue instanceof String[]) {
String[] array = (String[]) dataValue;
buffer.writeInt(array.length);
for (int i = 0; i < array.length; i++) {
ByteBufUtils.writeUTF8String(buffer, array[i]);
}
} else if (dataValue instanceof Footprint[]) {
Footprint[] array = (Footprint[]) dataValue;
buffer.writeInt(array.length);
for (int i = 0; i < array.length; i++) {
buffer.writeInt(array[i].dimension);
buffer.writeFloat((float) array[i].position.x);
buffer.writeFloat((float) array[i].position.y + 1);
buffer.writeFloat((float) array[i].position.z);
buffer.writeFloat(array[i].rotation);
buffer.writeShort(array[i].age);
ByteBufUtils.writeUTF8String(buffer, array[i].owner);
}
} else if (dataValue instanceof EnumFacing) {
buffer.writeInt(((EnumFacing) dataValue).getIndex());
} else if (dataValue instanceof BlockPos) {
BlockPos pos = (BlockPos) dataValue;
buffer.writeInt(pos.getX());
buffer.writeInt(pos.getY());
buffer.writeInt(pos.getZ());
} else if (dataValue instanceof EnumDyeColor) {
buffer.writeInt(((EnumDyeColor) dataValue).getDyeDamage());
} else {
if (dataValue == null) {
GCLog.severe("Cannot construct PacketSimple with null data, this is a bug.");
}
GCLog.info("Could not find data type to encode!: " + dataValue);
}
}
}
use of micdoodle8.mods.galacticraft.core.tile.FluidTankGC in project Galacticraft by micdoodle8.
the class NetworkUtil method cloneNetworkedObject.
public static Object cloneNetworkedObject(Object a) {
// We only need to clone mutable objects
if (a instanceof EnergyStorage) {
EnergyStorage prevStorage = (EnergyStorage) a;
EnergyStorage storage = new EnergyStorage(prevStorage.getCapacityGC(), prevStorage.getMaxReceive(), prevStorage.getMaxExtract());
storage.setEnergyStored(prevStorage.getEnergyStoredGC());
return storage;
} else if (a instanceof FluidTankGC) {
FluidTankGC prevTank = (FluidTankGC) a;
FluidTankGC tank = new FluidTankGC(prevTank.getFluid(), prevTank.getCapacity(), prevTank.getTile());
return tank;
} else if (a instanceof FluidTank) {
FluidTank prevTank = (FluidTank) a;
FluidStack prevFluid = prevTank.getFluid();
prevFluid = prevFluid == null ? null : prevFluid.copy();
FluidTank tank = new FluidTank(prevFluid, prevTank.getCapacity());
return tank;
} else {
return a;
}
}
Aggregations