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

@ -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

@ -165,7 +165,7 @@ public class FluidNetwork {
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)

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;
@ -482,6 +483,10 @@ public class PipeScenes {
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);
scene.world.setBlock(smartPos, AllBlocks.FLUID_PIPE.get()