use of buildcraft.api.transport.pipe.IPipe in project BuildCraft by BuildCraft.
the class PipeFlowPower method onTick.
@Override
public void onTick() {
if (pipe.getHolder().getPipeWorld().isRemote) {
return;
}
if (maxPower == -1) {
reconfigure();
}
step();
init();
for (EnumFacing face : EnumFacing.VALUES) {
Section s = sections.get(face);
if (s.internalPower > 0) {
long totalPowerQuery = 0;
for (EnumFacing face2 : EnumFacing.VALUES) {
if (face != face2) {
totalPowerQuery += sections.get(face2).powerQuery;
}
}
if (totalPowerQuery > 0) {
long unusedPowerQuery = totalPowerQuery;
for (EnumFacing face2 : EnumFacing.VALUES) {
if (face == face2) {
continue;
}
Section s2 = sections.get(face2);
if (s2.powerQuery > 0) {
long watts = Math.min(BigInteger.valueOf(s.internalPower).multiply(BigInteger.valueOf(s2.powerQuery)).divide(BigInteger.valueOf(unusedPowerQuery)).longValue(), s.internalPower);
unusedPowerQuery -= s2.powerQuery;
IPipe neighbour = pipe.getConnectedPipe(face2);
long leftover = watts;
if (neighbour != null && neighbour.getFlow() instanceof PipeFlowPower && neighbour.isConnected(face2.getOpposite())) {
PipeFlowPower oFlow = (PipeFlowPower) neighbour.getFlow();
leftover = oFlow.sections.get(face2.getOpposite()).receivePowerInternal(watts);
} else {
IMjReceiver receiver = pipe.getHolder().getCapabilityFromPipe(face2, MjAPI.CAP_RECEIVER);
if (receiver != null && receiver.canReceive()) {
leftover = receiver.receivePower(watts, false);
}
}
long used = watts - leftover;
s.internalPower -= used;
s2.debugPowerOutput += used;
s.powerAverage.push((int) used);
s2.powerAverage.push((int) used);
}
}
}
}
}
// Render compute goes here
for (Section s : sections.values()) {
s.powerAverage.tick();
long value = (long) s.powerAverage.getAverage();
long temp = Math.min(value * MjAPI.MJ / maxPower, 1 * MjAPI.MJ);
s.displayPower = (int) (temp);
}
// Compute the tiles requesting power that are not power pipes
for (EnumFacing face : EnumFacing.VALUES) {
if (pipe.getConnectedType(face) != ConnectedType.TILE) {
continue;
}
IMjReceiver recv = pipe.getHolder().getCapabilityFromPipe(face, MjAPI.CAP_RECEIVER);
if (recv != null && recv.canReceive()) {
long requested = recv.getPowerRequested();
if (requested > 0) {
requestPower(face, requested);
}
}
}
// Sum the amount of power requested on each side
long[] transferQueryTemp = new long[6];
for (EnumFacing face : EnumFacing.VALUES) {
if (!pipe.isConnected(face)) {
continue;
}
long query = 0;
for (EnumFacing face2 : EnumFacing.VALUES) {
if (face != face2) {
query += sections.get(face2).powerQuery;
}
}
transferQueryTemp[face.ordinal()] = query;
}
// Transfer requested power to neighbouring pipes
for (EnumFacing face : EnumFacing.VALUES) {
if (transferQueryTemp[face.ordinal()] <= 0 || !pipe.isConnected(face)) {
continue;
}
IPipe oPipe = pipe.getHolder().getNeighbourPipe(face);
if (oPipe == null || !(oPipe.getFlow() instanceof PipeFlowPower)) {
continue;
}
PipeFlowPower oFlow = (PipeFlowPower) oPipe.getFlow();
oFlow.requestPower(face.getOpposite(), transferQueryTemp[face.ordinal()]);
}
// if (tracker.markTimeIfDelay(pipe.getHolder().getPipeWorld())) {
if (!Arrays.equals(transferQuery, transferQueryTemp)) {
sendPayload(NET_POWER_AMOUNTS);
}
transferQuery = transferQueryTemp;
// }
}
use of buildcraft.api.transport.pipe.IPipe in project BuildCraft by BuildCraft.
the class ItemPluggableLens method onPlace.
@Override
public PipePluggable onPlace(@Nonnull ItemStack stack, IPipeHolder holder, EnumFacing side, EntityPlayer player, EnumHand hand) {
IPipe pipe = holder.getPipe();
if (pipe == null || !(pipe.getFlow() instanceof IFlowItems)) {
return null;
}
LensData data = getData(stack);
SoundUtil.playBlockPlace(holder.getPipeWorld(), holder.getPipePos(), Blocks.STONE.getDefaultState());
PluggableDefinition def = BCTransportPlugs.lens;
return new PluggableLens(def, holder, side, data.colour, data.isFilter);
}
use of buildcraft.api.transport.pipe.IPipe in project BuildCraft by BuildCraft.
the class BCTransportProxy method getServerGuiElement.
@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
BCTransportGuis gui = BCTransportGuis.get(id);
if (gui == null)
return null;
TileEntity tile = world.getTileEntity(new BlockPos(x, y, z));
switch(gui) {
case FILTERED_BUFFER:
{
if (tile instanceof TileFilteredBuffer) {
TileFilteredBuffer filteredBuffer = (TileFilteredBuffer) tile;
return new ContainerFilteredBuffer_BC8(player, filteredBuffer);
}
break;
}
case PIPE_DIAMOND:
{
if (tile instanceof IPipeHolder) {
IPipeHolder holder = (IPipeHolder) tile;
IPipe pipe = holder.getPipe();
if (pipe == null)
return null;
PipeBehaviour behaviour = pipe.getBehaviour();
if (behaviour instanceof PipeBehaviourDiamond) {
PipeBehaviourDiamond diaPipe = (PipeBehaviourDiamond) behaviour;
return new ContainerDiamondPipe(player, diaPipe);
}
}
break;
}
case PIPE_DIAMOND_WOOD:
{
if (tile instanceof IPipeHolder) {
IPipeHolder holder = (IPipeHolder) tile;
IPipe pipe = holder.getPipe();
if (pipe == null)
return null;
PipeBehaviour behaviour = pipe.getBehaviour();
if (behaviour instanceof PipeBehaviourWoodDiamond) {
PipeBehaviourWoodDiamond diaPipe = (PipeBehaviourWoodDiamond) behaviour;
return new ContainerDiamondWoodPipe(player, diaPipe);
}
}
break;
}
case PIPE_EMZULI:
{
if (tile instanceof IPipeHolder) {
IPipeHolder holder = (IPipeHolder) tile;
IPipe pipe = holder.getPipe();
if (pipe == null)
return null;
PipeBehaviour behaviour = pipe.getBehaviour();
if (behaviour instanceof PipeBehaviourEmzuli) {
PipeBehaviourEmzuli emPipe = (PipeBehaviourEmzuli) behaviour;
return new ContainerEmzuliPipe_BC8(player, emPipe);
}
}
break;
}
case GATE:
{
int ry = y >> 3;
EnumFacing gateSide = EnumFacing.getFront(y & 0x7);
tile = world.getTileEntity(new BlockPos(x, ry, z));
if (tile instanceof IPipeHolder) {
IPipeHolder holder = (IPipeHolder) tile;
PipePluggable plug = holder.getPluggable(gateSide);
if (plug instanceof PluggableGate) {
return new ContainerGate(player, ((PluggableGate) plug).logic);
}
}
break;
}
}
return null;
}
use of buildcraft.api.transport.pipe.IPipe in project BuildCraft by BuildCraft.
the class ItemPluggablePulsar method onPlace.
@Override
public PipePluggable onPlace(@Nonnull ItemStack stack, IPipeHolder holder, EnumFacing side, EntityPlayer player, EnumHand hand) {
IPipe pipe = holder.getPipe();
if (pipe == null) {
return null;
}
PipeBehaviour behaviour = pipe.getBehaviour();
if (behaviour instanceof IMjRedstoneReceiver) {
SoundUtil.playBlockPlace(holder.getPipeWorld(), holder.getPipePos());
return new PluggablePulsar(BCTransportPlugs.pulsar, holder, side);
} else {
return null;
}
}
use of buildcraft.api.transport.pipe.IPipe in project BuildCraft by BuildCraft.
the class WireManager method updateBetweens.
@Override
public void updateBetweens(boolean recursive) {
betweens.clear();
parts.forEach((part, color) -> {
for (EnumWireBetween between : EnumWireBetween.VALUES) {
EnumWirePart[] betweenParts = between.parts;
if (between.to == null) {
if ((betweenParts[0] == part && getColorOfPart(betweenParts[1]) == color) || (betweenParts[1] == part && getColorOfPart(betweenParts[0]) == color)) {
betweens.put(between, color);
}
} else if (WireSystem.canWireConnect(holder, between.to)) {
IPipe pipe = holder.getNeighbourPipe(between.to);
if (pipe != null) {
IWireManager wireManager = pipe.getHolder().getWireManager();
if (betweenParts[0] == part && wireManager.getColorOfPart(betweenParts[1]) == color) {
betweens.put(between, color);
}
}
}
}
});
if (!recursive) {
for (EnumFacing side : EnumFacing.VALUES) {
TileEntity tile = holder.getPipeWorld().getTileEntity(holder.getPipePos().offset(side));
if (tile instanceof IPipeHolder) {
((IPipeHolder) tile).getWireManager().updateBetweens(true);
}
}
}
}
Aggregations