Search in sources :

Example 11 with FluidNetwork

use of micdoodle8.mods.galacticraft.core.fluid.FluidNetwork in project Galacticraft by micdoodle8.

the class FluidNetwork method split.

@Override
public void split(IBufferTransmitter<FluidStack> splitPoint) {
    if (splitPoint instanceof TileEntity) {
        this.pipes.remove(splitPoint);
        /**
         * Loop through the connected blocks and attempt to see if there are
         * connections between the two points elsewhere.
         */
        TileEntity[] connectedBlocks = splitPoint.getAdjacentConnections();
        for (TileEntity connectedBlockA : connectedBlocks) {
            if (connectedBlockA instanceof INetworkConnection) {
                for (final TileEntity connectedBlockB : connectedBlocks) {
                    if (connectedBlockA != connectedBlockB && connectedBlockB instanceof INetworkConnection) {
                        Pathfinder finder = new PathfinderChecker(((TileEntity) splitPoint).getWorld(), (INetworkConnection) connectedBlockB, NetworkType.FLUID, splitPoint);
                        finder.init(new BlockVec3(connectedBlockA));
                        if (finder.results.size() > 0) {
                            for (BlockVec3 node : finder.closedSet) {
                                TileEntity nodeTile = node.getTileEntity(((TileEntity) splitPoint).getWorld());
                                if (nodeTile instanceof INetworkProvider) {
                                    if (nodeTile != splitPoint) {
                                        ((INetworkProvider) nodeTile).setNetwork(this);
                                    }
                                }
                            }
                        } else {
                            /**
                             * The connections A and B are not connected
                             * anymore. Give both of them a new network.
                             */
                            FluidNetwork newNetwork = new FluidNetwork();
                            for (BlockVec3 node : finder.closedSet) {
                                TileEntity nodeTile = node.getTileEntity(((TileEntity) splitPoint).getWorld());
                                if (nodeTile instanceof IBufferTransmitter) {
                                    if (nodeTile != splitPoint) {
                                        newNetwork.pipes.add((IBufferTransmitter<FluidStack>) nodeTile);
                                        newNetwork.pipesAdded.add((IBufferTransmitter<FluidStack>) nodeTile);
                                        newNetwork.onTransmitterAdded((IBufferTransmitter<FluidStack>) nodeTile);
                                        this.pipes.remove(nodeTile);
                                    }
                                }
                            }
                            newNetwork.refresh();
                            newNetwork.register();
                        }
                    }
                }
            }
        }
        if (this.pipes.isEmpty()) {
            this.unregister();
        } else {
            this.updateCapacity();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Pathfinder(micdoodle8.mods.galacticraft.api.transmission.grid.Pathfinder) INetworkConnection(micdoodle8.mods.galacticraft.api.transmission.tile.INetworkConnection) FluidStack(net.minecraftforge.fluids.FluidStack) IBufferTransmitter(micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter) INetworkProvider(micdoodle8.mods.galacticraft.api.transmission.tile.INetworkProvider) PathfinderChecker(micdoodle8.mods.galacticraft.api.transmission.grid.PathfinderChecker) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 12 with FluidNetwork

use of micdoodle8.mods.galacticraft.core.fluid.FluidNetwork in project Galacticraft by micdoodle8.

the class TileEntityElectrolyzer method produceHydrogen.

private boolean produceHydrogen(EnumFacing outputDirection) {
    int provide = this.getHydrogenProvide(outputDirection);
    if (provide > 0) {
        TileEntity outputTile = new BlockVec3(this).modifyPositionFromSide(outputDirection).getTileEntity(this.worldObj);
        FluidNetwork outputNetwork = NetworkHelper.getFluidNetworkFromTile(outputTile, outputDirection);
        if (outputNetwork != null) {
            int gasRequested = outputNetwork.getRequest();
            if (gasRequested > 0) {
                int usedGas = outputNetwork.emitToBuffer(new FluidStack(FluidRegistry.getFluid("hydrogen"), Math.min(gasRequested, provide)), true);
                this.drawHydrogen(usedGas, true);
                return true;
            }
        } else if (outputTile instanceof TileEntityMethaneSynthesizer) {
            float requestedHydrogen = ((TileEntityMethaneSynthesizer) outputTile).getHydrogenRequest(outputDirection.getOpposite());
            if (requestedHydrogen > 0) {
                int toSend = Math.min(this.getHydrogenStored(), provide);
                int acceptedHydrogen = ((TileEntityMethaneSynthesizer) outputTile).receiveHydrogen(outputDirection.getOpposite(), toSend, true);
                this.drawHydrogen(acceptedHydrogen, true);
                return true;
            }
        }
    // else if (EnergyConfigHandler.isMekanismLoaded())
    // {
    // //TODO Gas item handling - internal tank (IGasItem)
    // //int acceptedHydrogen = GasTransmission.addGas(itemStack, type, amount);
    // //this.drawHydrogen(acceptedHydrogen, true);
    // 
    // if (outputTile instanceof IGasHandler && ((IGasHandler) outputTile).canReceiveGas(outputDirection.getOpposite(), (Gas) EnergyConfigHandler.gasHydrogen))
    // {
    // GasStack toSend = new GasStack((Gas) EnergyConfigHandler.gasHydrogen, (int) Math.floor(Math.min(this.getHydrogenStored(), provide)));
    // int acceptedHydrogen = 0;
    // try {
    // acceptedHydrogen = ((IGasHandler) outputTile).receiveGas(outputDirection.getOpposite(), toSend);
    // } catch (Exception e) { }
    // this.drawHydrogen(acceptedHydrogen, true);
    // return true;
    // }
    // }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidNetwork(micdoodle8.mods.galacticraft.core.fluid.FluidNetwork) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 13 with FluidNetwork

use of micdoodle8.mods.galacticraft.core.fluid.FluidNetwork in project Galacticraft by micdoodle8.

the class TileEntityFluidTransmitter method refresh.

@Override
public void refresh() {
    if (!this.worldObj.isRemote) {
        this.adjacentConnections = null;
        BlockVec3 thisVec = new BlockVec3(this);
        for (EnumFacing side : EnumFacing.VALUES) {
            TileEntity tileEntity = thisVec.getTileEntityOnSide(this.worldObj, side);
            if (tileEntity != null) {
                if (tileEntity.getClass() == this.getClass() && tileEntity instanceof INetworkProvider && ((INetworkProvider) tileEntity).hasNetwork()) {
                    if (!(tileEntity instanceof ITransmitter) || (((ITransmitter) tileEntity).canConnect(side.getOpposite(), ((ITransmitter) tileEntity).getNetworkType()))) {
                        if (!this.hasNetwork()) {
                            this.setNetwork(((INetworkProvider) tileEntity).getNetwork());
                            ((FluidNetwork) this.getNetwork()).addTransmitter(this);
                            ((FluidNetwork) this.getNetwork()).onTransmitterAdded(this);
                        } else if (this.hasNetwork() && !this.getNetwork().equals(((INetworkProvider) tileEntity).getNetwork())) {
                            this.setNetwork((IGridNetwork) this.getNetwork().merge(((INetworkProvider) tileEntity).getNetwork()));
                        }
                    }
                }
            }
        }
        this.getNetwork().refresh();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidNetwork(micdoodle8.mods.galacticraft.core.fluid.FluidNetwork) IGridNetwork(micdoodle8.mods.galacticraft.api.transmission.grid.IGridNetwork) EnumFacing(net.minecraft.util.EnumFacing) ITransmitter(micdoodle8.mods.galacticraft.api.transmission.tile.ITransmitter) INetworkProvider(micdoodle8.mods.galacticraft.api.transmission.tile.INetworkProvider) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 14 with FluidNetwork

use of micdoodle8.mods.galacticraft.core.fluid.FluidNetwork in project Galacticraft by micdoodle8.

the class TileEntityFluidTransmitter method resetNetwork.

protected void resetNetwork() {
    FluidNetwork network = new FluidNetwork();
    network.addTransmitter(this);
    network.register();
    this.setNetwork(network);
}
Also used : FluidNetwork(micdoodle8.mods.galacticraft.core.fluid.FluidNetwork)

Aggregations

FluidNetwork (micdoodle8.mods.galacticraft.core.fluid.FluidNetwork)13 TileEntity (net.minecraft.tileentity.TileEntity)10 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)8 IBufferTransmitter (micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter)3 INetworkProvider (micdoodle8.mods.galacticraft.api.transmission.tile.INetworkProvider)3 Footprint (micdoodle8.mods.galacticraft.core.wrappers.Footprint)3 EntitySpaceshipBase (micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase)2 IOxygenReceiver (micdoodle8.mods.galacticraft.api.transmission.tile.IOxygenReceiver)2 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)2 TileEntityFluidTank (micdoodle8.mods.galacticraft.core.tile.TileEntityFluidTank)2 ScheduledDimensionChange (micdoodle8.mods.galacticraft.core.wrappers.ScheduledDimensionChange)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 MinecraftServer (net.minecraft.server.MinecraftServer)2 WorldServer (net.minecraft.world.WorldServer)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 GameProfile (com.mojang.authlib.GameProfile)1 MinecraftProfileTexture (com.mojang.authlib.minecraft.MinecraftProfileTexture)1 Type (com.mojang.authlib.minecraft.MinecraftProfileTexture.Type)1 Property (com.mojang.authlib.properties.Property)1