use of com.simibubi.create.foundation.utility.BlockFace in project Create by Creators-of-Create.
the class MechanicalCrafterTileEntity method tryInsert.
public void tryInsert() {
if (!inserting.hasInventory() && !isTargetingBelt()) {
ejectWholeGrid();
return;
}
boolean chagedPhase = phase != Phase.INSERTING;
final List<Pair<Integer, Integer>> inserted = new LinkedList<>();
DirectBeltInputBehaviour behaviour = getTargetingBelt();
for (Entry<Pair<Integer, Integer>, ItemStack> entry : groupedItems.grid.entrySet()) {
Pair<Integer, Integer> pair = entry.getKey();
ItemStack stack = entry.getValue();
BlockFace face = getTargetFace(level, worldPosition, getBlockState());
ItemStack remainder = behaviour == null ? inserting.insert(stack.copy()) : behaviour.handleInsertion(stack, face.getFace(), false);
if (!remainder.isEmpty()) {
stack.setCount(remainder.getCount());
continue;
}
inserted.add(pair);
}
inserted.forEach(groupedItems.grid::remove);
if (groupedItems.grid.isEmpty())
ejectWholeGrid();
else
phase = Phase.INSERTING;
if (!inserted.isEmpty() || chagedPhase)
sendData();
}
use of com.simibubi.create.foundation.utility.BlockFace in project Create by Creators-of-Create.
the class PipeConnection method manageFlows.
public boolean manageFlows(Level world, BlockPos pos, FluidStack internalFluid, Predicate<FluidStack> extractionPredicate) {
// Only keep network if still valid
Optional<FluidNetwork> retainedNetwork = network;
network = Optional.empty();
// chunk border
if (!source.isPresent() && !determineSource(world, pos))
return false;
FlowSource flowSource = source.get();
if (!hasFlow()) {
if (!hasPressure())
return false;
// Try starting a new flow
boolean prioritizeInbound = comparePressure() < 0;
for (boolean trueFalse : Iterate.trueAndFalse) {
boolean inbound = prioritizeInbound == trueFalse;
if (pressure.get(inbound) == 0)
continue;
if (tryStartingNewFlow(inbound, inbound ? flowSource.provideFluid(extractionPredicate) : internalFluid))
return true;
}
return false;
}
// Manage existing flow
Flow flow = this.flow.get();
FluidStack provided = flow.inbound ? flowSource.provideFluid(extractionPredicate) : internalFluid;
if (!hasPressure() || provided.isEmpty() || !provided.isFluidEqual(flow.fluid)) {
this.flow = Optional.empty();
return true;
}
// Overwrite existing flow
if (flow.inbound != comparePressure() < 0) {
boolean inbound = !flow.inbound;
if (inbound && !provided.isEmpty() || !inbound && !internalFluid.isEmpty()) {
FluidPropagator.resetAffectedFluidNetworks(world, pos, side);
tryStartingNewFlow(inbound, inbound ? flowSource.provideFluid(extractionPredicate) : internalFluid);
return true;
}
}
flowSource.whileFlowPresent(world, flow.inbound);
if (!flowSource.isEndpoint())
return false;
if (!flow.inbound)
return false;
// Layer III
network = retainedNetwork;
if (!hasNetwork())
network = Optional.of(new FluidNetwork(world, new BlockFace(pos, side), flowSource::provideHandler));
network.get().tick();
return false;
}
use of com.simibubi.create.foundation.utility.BlockFace in project Create by Creators-of-Create.
the class PipeConnection method determineSource.
public boolean determineSource(Level world, BlockPos pos) {
BlockPos relative = pos.relative(side);
// cannot use world.isLoaded because it always returns true on client
if (world.getChunk(relative.getX() >> 4, relative.getZ() >> 4, ChunkStatus.FULL, false) == null)
return false;
BlockFace location = new BlockFace(pos, side);
if (FluidPropagator.isOpenEnd(world, pos, side)) {
if (previousSource.orElse(null) instanceof OpenEndedPipe)
source = previousSource;
else
source = Optional.of(new OpenEndedPipe(location));
return true;
}
if (FluidPropagator.hasFluidCapability(world, location.getConnectedPos(), side.getOpposite())) {
source = Optional.of(new FlowSource.FluidHandler(location));
return true;
}
FluidTransportBehaviour behaviour = TileEntityBehaviour.get(world, relative, FluidTransportBehaviour.TYPE);
source = Optional.of(behaviour == null ? new FlowSource.Blocked(location) : new FlowSource.OtherPipe(location));
return true;
}
use of com.simibubi.create.foundation.utility.BlockFace in project Create by Creators-of-Create.
the class PumpTileEntity method searchForEndpointRecursively.
protected boolean searchForEndpointRecursively(Map<BlockPos, Pair<Integer, Map<Direction, Boolean>>> pipeGraph, Set<BlockFace> targets, Map<Integer, Set<BlockFace>> validFaces, BlockFace currentFace, boolean pull) {
BlockPos currentPos = currentFace.getPos();
if (!pipeGraph.containsKey(currentPos))
return false;
Pair<Integer, Map<Direction, Boolean>> pair = pipeGraph.get(currentPos);
int distance = pair.getFirst();
boolean atLeastOneBranchSuccessful = false;
for (Direction nextFacing : Iterate.directions) {
if (nextFacing == currentFace.getFace())
continue;
Map<Direction, Boolean> map = pair.getSecond();
if (!map.containsKey(nextFacing))
continue;
BlockFace localTarget = new BlockFace(currentPos, nextFacing);
if (targets.contains(localTarget)) {
validFaces.computeIfAbsent(distance, $ -> new HashSet<>()).add(localTarget);
atLeastOneBranchSuccessful = true;
continue;
}
if (map.get(nextFacing) != pull)
continue;
if (!searchForEndpointRecursively(pipeGraph, targets, validFaces, new BlockFace(currentPos.relative(nextFacing), nextFacing.getOpposite()), pull))
continue;
validFaces.computeIfAbsent(distance, $ -> new HashSet<>()).add(localTarget);
atLeastOneBranchSuccessful = true;
}
if (atLeastOneBranchSuccessful)
validFaces.computeIfAbsent(distance, $ -> new HashSet<>()).add(currentFace);
return atLeastOneBranchSuccessful;
}
use of com.simibubi.create.foundation.utility.BlockFace in project Create by Creators-of-Create.
the class OpenEndedPipe method fromNBT.
public static OpenEndedPipe fromNBT(CompoundTag compound, BlockPos tilePos) {
BlockFace fromNBT = BlockFace.fromNBT(compound.getCompound("Location"));
OpenEndedPipe oep = new OpenEndedPipe(new BlockFace(tilePos, fromNBT.getFace()));
oep.fluidHandler.readFromNBT(compound);
oep.wasPulling = compound.getBoolean("Pulling");
return oep;
}
Aggregations