From 2bd10af1bc25d4c1f7c50951edbf4eed0631b1fd Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Wed, 13 Oct 2021 03:14:57 +0200 Subject: [PATCH] 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 --- .../crafter/ConnectedInputHandler.java | 20 +++++++++++++++++++ .../contraptions/fluids/FlowSource.java | 4 ++-- .../contraptions/fluids/FluidNetwork.java | 18 ++++++++--------- .../ponder/content/fluid/PipeScenes.java | 5 +++++ 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/ConnectedInputHandler.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/ConnectedInputHandler.java index 39e725e9b..2c4c78fa2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/ConnectedInputHandler.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/ConnectedInputHandler.java @@ -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 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 list = data.stream() + .sorted(invOrdering) .map(l -> CrafterHelper.getCrafter(world, pos.offset(l))) .filter(Objects::nonNull) .map(crafter -> crafter.getInventory()) diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/FlowSource.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/FlowSource.java index 4df90ba50..22aa2cd07 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/FlowSource.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/FlowSource.java @@ -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 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) diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidNetwork.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidNetwork.java index f6b08b2e8..eedcc0cd9 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidNetwork.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/FluidNetwork.java @@ -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> 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; diff --git a/src/main/java/com/simibubi/create/foundation/ponder/content/fluid/PipeScenes.java b/src/main/java/com/simibubi/create/foundation/ponder/content/fluid/PipeScenes.java index adc80a419..8f84ac781 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/content/fluid/PipeScenes.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/content/fluid/PipeScenes.java @@ -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);