Skip to content

Commit

Permalink
Short circuit a little logic to avoid looking up the side multiple ti…
Browse files Browse the repository at this point in the history
…mes for transporters, mostly bringing parity up to (#7748) except for the network wide changes
  • Loading branch information
pupnewfster committed Apr 15, 2024
1 parent d4eb85f commit 89e70aa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public void onUpdateServer() {
}
}
if (!transit.isEmpty()) {
BlockPos pos = getBlockPos();
InventoryNetwork network = getTransmitterNetwork();
//Update stack positions
IntSet deletes = new IntOpenHashSet();
Expand All @@ -160,7 +161,7 @@ public void onUpdateServer() {
if (stack.progress >= 100) {
BlockPos prevSet = null;
if (stack.hasPath()) {
int currentIndex = stack.getPath().indexOf(getBlockPos());
int currentIndex = stack.getPath().indexOf(pos);
if (currentIndex == 0) { //Necessary for transition reasons, not sure why
deletes.add(stackId);
continue;
Expand Down Expand Up @@ -221,15 +222,20 @@ public void onUpdateServer() {
tryRecalculate = true;
}
} else {
LogisticalTransporterBase nextTransmitter = network.getTransmitter(stack.getNext(this));
if (nextTransmitter == null && stack.getPathType().noTarget() && stack.getPath().size() == 2) {
//If there is no next transmitter, and it was an idle path, assume that we are idling
// in a single length transmitter, in which case we only recalculate it at 50 if it won't
// be able to go into that connection type
ConnectionType connectionType = getConnectionType(stack.getSide(this));
tryRecalculate = !connectionType.canSendTo();
BlockPos nextPos = stack.getNext(this);
if (nextPos == null) {
tryRecalculate = true;
} else {
tryRecalculate = !stack.canInsertToTransporter(nextTransmitter, stack.getSide(this), this);
Direction nextSide = stack.getSide(pos, nextPos);
LogisticalTransporterBase nextTransmitter = network.getTransmitter(nextPos);
if (nextTransmitter == null && stack.getPathType().noTarget() && stack.getPath().size() == 2) {
//If there is no next transmitter, and it was an idle path, assume that we are idling
// in a single length transmitter, in which case we only recalculate it at 50 if it won't
// be able to go into that connection type
tryRecalculate = !getConnectionType(nextSide).canSendTo();
} else {
tryRecalculate = !stack.canInsertToTransporter(nextTransmitter, nextSide, this);
}
}
}
if (tryRecalculate && !recalculate(stackId, stack, null)) {
Expand All @@ -240,7 +246,7 @@ public void onUpdateServer() {

if (!deletes.isEmpty() || !needsSync.isEmpty()) {
//Notify clients, so that we send the information before we start clearing our lists
PacketUtils.sendToAllTracking(new PacketTransporterBatch(getBlockPos(), deletes, needsSync), getTransmitterTile());
PacketUtils.sendToAllTracking(new PacketTransporterBatch(pos, deletes, needsSync), getTransmitterTile());
// Now remove any entries from transit that have been deleted
OfInt ofInt = deletes.iterator();
while (ofInt.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,12 @@ public boolean isFinal(LogisticalTransporterBase transporter) {
return pathToTarget.indexOf(transporter.getBlockPos()) == (getPathType().hasTarget() ? 1 : 0);
}

@Nullable
public BlockPos getNext(LogisticalTransporterBase transporter) {
return transporter.isRemote() ? clientNext : getNext(transporter.getBlockPos());
}

@Nullable
private BlockPos getNext(BlockPos pos) {
int index = pathToTarget.indexOf(pos) - 1;
if (index < 0) {
Expand Down Expand Up @@ -280,6 +282,15 @@ public Direction getSide(LogisticalTransporterBase transporter) {
return side == null ? Direction.DOWN : side;
}

public Direction getSide(BlockPos pos, @Nullable BlockPos target) {
Direction side = null;
if (target != null) {
side = WorldUtils.sideDifference(target, pos);
}
//TODO: See getSide(Transporter) for why we null check and then return down
return side == null ? Direction.DOWN : side;
}

@Contract("null, _, _ -> false")
public boolean canInsertToTransporter(@Nullable LogisticalTransporterBase transmitter, Direction from, @Nullable LogisticalTransporterBase transporterFrom) {
return transmitter != null && canInsertToTransporterNN(transmitter, from, transporterFrom);
Expand Down

0 comments on commit 89e70aa

Please sign in to comment.