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