use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 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.api.vector.BlockVec3 in project Galacticraft by micdoodle8.
the class NetworkUtil method decodeData.
public static ArrayList<Object> decodeData(Class<?>[] types, ByteBuf buffer) {
ArrayList<Object> objList = new ArrayList<Object>();
for (Class clazz : types) {
if (clazz.equals(Integer.class)) {
objList.add(buffer.readInt());
} else if (clazz.equals(Float.class)) {
objList.add(buffer.readFloat());
} else if (clazz.equals(Double.class)) {
objList.add(buffer.readDouble());
} else if (clazz.equals(Byte.class)) {
objList.add(buffer.readByte());
} else if (clazz.equals(Boolean.class)) {
objList.add(buffer.readBoolean());
} else if (clazz.equals(String.class)) {
objList.add(ByteBufUtils.readUTF8String(buffer));
} else if (clazz.equals(Short.class)) {
objList.add(buffer.readShort());
} else if (clazz.equals(Long.class)) {
objList.add(buffer.readLong());
} else if (clazz.equals(byte[].class)) {
int size = buffer.readInt();
byte[] bytes = new byte[size];
buffer.readBytes(bytes, 0, size);
objList.add(bytes);
} else if (clazz.equals(EnergyStorage.class)) {
EnergyStorage storage = new EnergyStorage(buffer.readFloat(), buffer.readFloat(), buffer.readFloat());
storage.setEnergyStored(buffer.readFloat());
objList.add(storage);
} else if (clazz.equals(NBTTagCompound.class)) {
try {
objList.add(NetworkUtil.readNBTTagCompound(buffer));
} catch (IOException e) {
e.printStackTrace();
}
} else if (clazz.equals(BlockVec3.class)) {
objList.add(new BlockVec3(buffer.readInt(), buffer.readInt(), buffer.readInt()));
} else if (clazz.equals(UUID.class)) {
objList.add(new UUID(buffer.readLong(), buffer.readLong()));
} else if (clazz.equals(Vector3.class)) {
objList.add(new Vector3(buffer.readDouble(), buffer.readDouble(), buffer.readDouble()));
} else if (clazz.equals(FlagData.class)) {
int width = buffer.readInt();
int height = buffer.readInt();
FlagData flagData = new FlagData(width, height);
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
flagData.setColorAt(i, j, new Vector3(buffer.readByte() + 128, buffer.readByte() + 128, buffer.readByte() + 128));
}
}
objList.add(flagData);
} else if (clazz.equals(Integer[].class)) {
int size = buffer.readInt();
for (int i = 0; i < size; i++) {
objList.add(buffer.readInt());
}
} else if (clazz.equals(String[].class)) {
int size = buffer.readInt();
for (int i = 0; i < size; i++) {
objList.add(ByteBufUtils.readUTF8String(buffer));
}
} else if (clazz.equals(Footprint[].class)) {
int size = buffer.readInt();
for (int i = 0; i < size; i++) {
objList.add(new Footprint(buffer.readInt(), new Vector3(buffer.readFloat(), buffer.readFloat(), buffer.readFloat()), buffer.readFloat(), buffer.readShort(), ByteBufUtils.readUTF8String(buffer)));
}
} else if (clazz.equals(EnumFacing.class)) {
objList.add(EnumFacing.getFront(buffer.readInt()));
} else if (clazz.equals(BlockPos.class)) {
objList.add(new BlockPos(buffer.readInt(), buffer.readInt(), buffer.readInt()));
} else if (clazz.equals(EnumDyeColor.class)) {
objList.add(EnumDyeColor.byDyeDamage(buffer.readInt()));
}
}
return objList;
}
use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 in project Galacticraft by micdoodle8.
the class TileEntityPainter method onChunkUnload.
@Override
public void onChunkUnload() {
this.getLoadedTiles(this.worldObj).remove(new BlockVec3(this.pos));
super.onChunkUnload();
}
use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 in project Galacticraft by micdoodle8.
the class TileEntityScreen method canJoinUp.
private boolean canJoinUp() {
int meta = this.getBlockMetadata();
TileEntity te = new BlockVec3(this).getTileEntityOnSide(this.worldObj, 1);
if (!(te instanceof TileEntityScreen)) {
return false;
}
TileEntityScreen screenTile = (TileEntityScreen) te;
if (screenTile.getBlockMetadata() != meta) {
return false;
}
if (screenTile.connectionsLeft != this.connectionsLeft) {
return false;
}
if (screenTile.connectionsRight != this.connectionsRight) {
return false;
}
if (this.connectionsLeft + this.connectionsRight > 0) {
return true;
}
if (this.connectionsDown > 0) {
return false;
}
if (screenTile.connectionsUp > 0) {
return false;
}
return true;
}
use of micdoodle8.mods.galacticraft.api.vector.BlockVec3 in project Galacticraft by micdoodle8.
the class TileEntityOxygenSealer method sendUpdateToClient.
@Override
public void sendUpdateToClient(EntityPlayerMP player) {
if (this.sealed || this.threadSeal == null || this.threadSeal.leakTrace == null || this.threadSeal.leakTrace.isEmpty()) {
return;
}
Integer[] data = new Integer[this.threadSeal.leakTrace.size()];
int index = 0;
for (BlockVec3 vec : this.threadSeal.leakTrace) {
int dx = vec.x - this.pos.getX() + 128;
int dz = vec.z - this.pos.getZ() + 128;
int dy = vec.y;
if (dx < 0 || dx > 255 || dz < 0 || dz > 255)
continue;
int composite = dz + ((dy + (dx << 8)) << 8);
data[index++] = composite;
}
GalacticraftCore.packetPipeline.sendTo(new PacketSimple(EnumSimplePacket.C_LEAK_DATA, GCCoreUtil.getDimensionID(player.worldObj), new Object[] { ((TileEntity) this).getPos(), data }), player);
}
Aggregations