Search in sources :

Example 1 with FluidTankGC

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidStack(net.minecraftforge.fluids.FluidStack) FluidTankGC(micdoodle8.mods.galacticraft.core.tile.FluidTankGC) Fluid(net.minecraftforge.fluids.Fluid) BlockPos(net.minecraft.util.BlockPos) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint)

Example 2 with FluidTankGC

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);
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) EnergyStorage(micdoodle8.mods.galacticraft.core.energy.tile.EnergyStorage) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) FlagData(micdoodle8.mods.galacticraft.core.wrappers.FlagData) BlockPos(net.minecraft.util.BlockPos) UUID(java.util.UUID) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) FluidTankGC(micdoodle8.mods.galacticraft.core.tile.FluidTankGC) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3) EnumDyeColor(net.minecraft.item.EnumDyeColor) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) FluidTank(net.minecraftforge.fluids.FluidTank) Collection(java.util.Collection)

Example 3 with FluidTankGC

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;
    }
}
Also used : FluidTank(net.minecraftforge.fluids.FluidTank) FluidStack(net.minecraftforge.fluids.FluidStack) EnergyStorage(micdoodle8.mods.galacticraft.core.energy.tile.EnergyStorage) FluidTankGC(micdoodle8.mods.galacticraft.core.tile.FluidTankGC)

Aggregations

FluidTankGC (micdoodle8.mods.galacticraft.core.tile.FluidTankGC)3 EnergyStorage (micdoodle8.mods.galacticraft.core.energy.tile.EnergyStorage)2 Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)2 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockPos (net.minecraft.util.BlockPos)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 FluidTank (net.minecraftforge.fluids.FluidTank)2 Collection (java.util.Collection)1 UUID (java.util.UUID)1 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)1 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)1 FlagData (micdoodle8.mods.galacticraft.core.wrappers.FlagData)1 Entity (net.minecraft.entity.Entity)1 EnumDyeColor (net.minecraft.item.EnumDyeColor)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 EnumFacing (net.minecraft.util.EnumFacing)1 Fluid (net.minecraftforge.fluids.Fluid)1