Ordered Crafter slots

- Connected Mechanical Crafters now strictly distribute added items from top to bottom, left to right
- Fixed smart pipe ponder scene no longer showing milk in the basin
- Added timed invalidation to refresh fluid handler references observed by pipe ends
This commit is contained in:
simibubi 2021-10-13 03:14:57 +02:00
parent d1810f5173
commit 2bd10af1bc
4 changed files with 36 additions and 11 deletions

View file

@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
@ -22,6 +23,8 @@ import net.minecraft.nbt.ListNBT;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Direction;
import net.minecraft.util.Direction.Axis;
import net.minecraft.util.Direction.AxisDirection;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants.NBT;
@ -181,7 +184,24 @@ public class ConnectedInputHandler {
return input.getItemHandler(world, controllerPos);
}
Direction facing = Direction.SOUTH;
BlockState blockState = world.getBlockState(pos);
if (blockState.hasProperty(MechanicalCrafterBlock.HORIZONTAL_FACING))
facing = blockState.getValue(MechanicalCrafterBlock.HORIZONTAL_FACING);
AxisDirection axisDirection = facing.getAxisDirection();
Axis compareAxis = facing.getClockWise()
.getAxis();
Comparator<BlockPos> invOrdering = (p1, p2) -> {
int compareY = -Integer.compare(p1.getY(), p2.getY());
int modifier = axisDirection.getStep() * (compareAxis == Axis.Z ? -1 : 1);
int c1 = compareAxis.choose(p1.getX(), p1.getY(), p1.getZ());
int c2 = compareAxis.choose(p2.getX(), p2.getY(), p2.getZ());
return compareY != 0 ? compareY : modifier * Integer.compare(c1, c2);
};
List<IItemHandlerModifiable> list = data.stream()
.sorted(invOrdering)
.map(l -> CrafterHelper.getCrafter(world, pos.offset(l)))
.filter(Objects::nonNull)
.map(crafter -> crafter.getInventory())

View file

@ -52,7 +52,7 @@ public abstract class FlowSource {
public abstract boolean isEndpoint();
public void manageSource(World world) {}
public void whileFlowPresent(World world, boolean pulling) {}
public LazyOptional<IFluidHandler> provideHandler() {
@ -68,7 +68,7 @@ public abstract class FlowSource {
}
public void manageSource(World world) {
if (fluidHandler.isPresent())
if (fluidHandler.isPresent() && world.getGameTime() % 20 != 0)
return;
TileEntity tileEntity = world.getBlockEntity(location.getConnectedPos());
if (tileEntity != null)

View file

@ -91,7 +91,7 @@ public class FluidNetwork {
if (!pipeConnection.hasFlow())
continue;
Flow flow = pipeConnection.flow.get();
if (!fluid.isEmpty() && !flow.fluid.isFluidEqual(fluid)) {
iterator.remove();
@ -104,7 +104,7 @@ public class FluidNetwork {
}
if (!flow.complete)
continue;
if (fluid.isEmpty())
fluid = flow.fluid;
@ -158,14 +158,14 @@ public class FluidNetwork {
source = sourceSupplier.get();
if (!source.isPresent())
return;
keepPortableFluidInterfaceEngaged();
if (targets.isEmpty())
return;
for (Pair<BlockFace, LazyOptional<IFluidHandler>> pair : targets) {
if (pair.getSecond()
.isPresent())
.isPresent() && world.getGameTime() % 40 != 0)
continue;
PipeConnection pipeConnection = get(pair.getFirst());
if (pipeConnection == null)
@ -183,7 +183,7 @@ public class FluidNetwork {
IFluidHandler handler = source.orElse(null);
if (handler == null)
return;
FluidStack transfer = FluidStack.EMPTY;
for (int i = 0; i < handler.getTanks(); i++) {
FluidStack contained = handler.getFluidInTank(i);
@ -194,13 +194,13 @@ public class FluidNetwork {
FluidStack toExtract = FluidHelper.copyStackWithAmount(contained, flowSpeed);
transfer = handler.drain(toExtract, action);
}
if (transfer.isEmpty()) {
FluidStack genericExtract = handler.drain(flowSpeed, action);
if (!genericExtract.isEmpty() && genericExtract.isFluidEqual(fluid))
transfer = genericExtract;
}
if (transfer.isEmpty())
return;
@ -258,7 +258,7 @@ public class FluidNetwork {
private void keepPortableFluidInterfaceEngaged() {
IFluidHandler handler = source.orElse(null);
if (!(handler instanceof InterfaceFluidHandler))
if (!(handler instanceof InterfaceFluidHandler))
return;
if (frontier.isEmpty())
return;

View file

@ -35,6 +35,7 @@ import net.minecraft.util.Direction.Axis;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraftforge.common.ForgeMod;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction;
@ -481,6 +482,10 @@ public class PipeScenes {
Selection pump = util.select.position(1, 1, 2);
Selection basin = util.select.position(basinPos);
BlockPos smartPos = util.grid.at(3, 1, 1);
scene.world.modifyTileEntity(basinPos, BasinTileEntity.class,
te -> te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)
.ifPresent(ifh -> ifh.fill(new FluidStack(ForgeMod.MILK.get(), 1000), FluidAction.EXECUTE)));
scene.world.setBlock(util.grid.at(3, 1, 3), AllBlocks.FLUID_PIPE.get()
.getAxisState(Axis.X), false);