use of buildcraft.api.core.EnumPipePart in project BuildCraft by BuildCraft.
the class BehaviourWood method selectNewDirection.
private void selectNewDirection() {
if (pipe.getWorld().isRemote) {
return;
}
EnumPipePart part = extractionFace;
if (part == EnumPipePart.CENTER)
part = part.next();
int left = 6;
while (left > 0) {
part = part.next();
left--;
IConnection_BC8 connection = pipe.getConnections().get(part.face);
if (isValidExtraction(connection)) {
extractionFace = part;
pipe.sendClientUpdate(this);
pipe.sendRenderUpdate();
return;
}
}
extractionFace = EnumPipePart.CENTER;
pipe.sendClientUpdate(this);
pipe.sendRenderUpdate();
}
use of buildcraft.api.core.EnumPipePart in project BuildCraft by BuildCraft.
the class PipeFlowFluids method readPayload.
@Override
public void readPayload(int id, PacketBuffer buf, Side side) throws IOException {
PacketBufferBC buffer = PacketBufferBC.asPacketBufferBc(buf);
if (side == Side.CLIENT) {
if (id == NET_FLUID_AMOUNTS || id == NET_ID_FULL_STATE) {
boolean full = id == NET_ID_FULL_STATE;
if (buffer.readBoolean()) {
int fluidId = buffer.readInt();
clientFluid = BuildCraftObjectCaches.CACHE_FLUIDS.client().retrieve(fluidId);
}
for (EnumPipePart part : EnumPipePart.VALUES) {
Section section = sections.get(part);
if (full || buffer.readBoolean()) {
section.target = buffer.readShort();
if (full) {
section.clientAmountLast = section.clientAmountThis = section.target;
}
}
Dir dir = buffer.readEnumValue(Dir.class);
section.ticksInDirection = dir == Dir.NONE ? 0 : dir == Dir.IN ? COOLDOWN_INPUT : COOLDOWN_OUTPUT;
}
lastMessageMinus1 = lastMessage;
lastMessage = pipe.getHolder().getPipeWorld().getTotalWorldTime();
}
}
}
use of buildcraft.api.core.EnumPipePart in project BuildCraft by BuildCraft.
the class PipeFlowFluids method moveFromPipe.
private void moveFromPipe() {
for (EnumPipePart part : EnumPipePart.FACES) {
Section section = sections.get(part);
if (section.getCurrentDirection().canOutput()) {
PipeEventFluid.SideCheck sideCheck = new PipeEventFluid.SideCheck(pipe.getHolder(), this, currentFluid);
sideCheck.disallowAllExcept(part.face);
pipe.getHolder().fireEvent(sideCheck);
if (sideCheck.getOrder().size() == 1) {
IFluidHandler fluidHandler = pipe.getHolder().getCapabilityFromPipe(part.face, CapUtil.CAP_FLUIDS);
if (fluidHandler == null)
continue;
FluidStack fluidToPush = new FluidStack(currentFluid, section.drainInternal(fluidTransferInfo.transferPerTick, false));
if (fluidToPush.amount > 0) {
int filled = fluidHandler.fill(fluidToPush, true);
if (filled > 0) {
section.drainInternal(filled, true);
section.ticksInDirection = COOLDOWN_OUTPUT;
}
}
}
}
}
}
use of buildcraft.api.core.EnumPipePart in project BuildCraft by BuildCraft.
the class PipeFlowFluids method getAmountsForRender.
@SideOnly(Side.CLIENT)
public double[] getAmountsForRender(float partialTicks) {
double[] arr = new double[7];
for (EnumPipePart part : EnumPipePart.VALUES) {
Section s = sections.get(part);
arr[part.getIndex()] = s.clientAmountLast * (1 - partialTicks) + s.clientAmountThis * (partialTicks);
}
return arr;
}
use of buildcraft.api.core.EnumPipePart in project BuildCraft by BuildCraft.
the class PipeFlowFluids method moveToCenter.
private void moveToCenter() {
int transferInCount = 0;
Section center = sections.get(EnumPipePart.CENTER);
int spaceAvailable = capacity - center.amount;
int flowRate = fluidTransferInfo.transferPerTick;
List<EnumPipePart> faces = new ArrayList<>();
Collections.addAll(faces, EnumPipePart.FACES);
Collections.shuffle(faces);
int[] inputPerTick = new int[6];
for (EnumPipePart part : faces) {
Section section = sections.get(part);
inputPerTick[part.getIndex()] = 0;
if (section.getCurrentDirection().canInput()) {
inputPerTick[part.getIndex()] = section.drainInternal(flowRate, false);
if (inputPerTick[part.getIndex()] > 0) {
transferInCount++;
}
}
}
int[] totalOffered = Arrays.copyOf(inputPerTick, 6);
PreMoveToCentre preMove = new PreMoveToCentre(pipe.getHolder(), this, currentFluid, Math.min(flowRate, spaceAvailable), totalOffered, inputPerTick);
// Event handlers edit the array in-place
pipe.getHolder().fireEvent(preMove);
int[] fluidLeavingSide = new int[6];
// Work out how much fluid should leave
int left = Math.min(flowRate, spaceAvailable);
float min = Math.min(flowRate * transferInCount, spaceAvailable) / (float) flowRate / transferInCount;
for (EnumPipePart part : EnumPipePart.FACES) {
Section section = sections.get(part);
// Move liquid from input sides to the centre
int i = part.getIndex();
if (inputPerTick[i] > 0) {
int amountToDrain = (int) (inputPerTick[i] * min);
if (amountToDrain < 1) {
amountToDrain++;
}
if (amountToDrain > left) {
amountToDrain = left;
}
int amountToPush = section.drainInternal(amountToDrain, false);
if (amountToPush > 0) {
fluidLeavingSide[i] = amountToPush;
left -= amountToPush;
}
}
}
int[] fluidEnteringCentre = Arrays.copyOf(fluidLeavingSide, 6);
OnMoveToCentre move = new OnMoveToCentre(pipe.getHolder(), this, currentFluid, fluidLeavingSide, fluidEnteringCentre);
pipe.getHolder().fireEvent(move);
for (EnumPipePart part : EnumPipePart.FACES) {
Section section = sections.get(part);
int i = part.getIndex();
int leaving = fluidLeavingSide[i];
if (leaving > 0) {
int actuallyDrained = section.drainInternal(leaving, true);
if (actuallyDrained != leaving) {
throw new IllegalStateException("Couldn't drain " + leaving + " from " + part + ", only drained " + actuallyDrained);
}
if (actuallyDrained > 0) {
section.ticksInDirection = COOLDOWN_INPUT;
}
int entering = fluidEnteringCentre[i];
if (entering > 0) {
int actuallyFilled = center.fill(entering, true);
if (actuallyFilled != entering) {
throw new IllegalStateException("Couldn't fill " + entering + " from " + part + ", only filled " + actuallyFilled);
}
}
}
}
}
Aggregations