Skip to content

Commit 89e70aa

Browse files
committed
Short circuit a little logic to avoid looking up the side multiple times for transporters, mostly bringing parity up to (#7748) except for the network wide changes
1 parent d4eb85f commit 89e70aa

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

src/main/java/mekanism/common/content/network/transmitter/LogisticalTransporterBase.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public void onUpdateServer() {
139139
}
140140
}
141141
if (!transit.isEmpty()) {
142+
BlockPos pos = getBlockPos();
142143
InventoryNetwork network = getTransmitterNetwork();
143144
//Update stack positions
144145
IntSet deletes = new IntOpenHashSet();
@@ -160,7 +161,7 @@ public void onUpdateServer() {
160161
if (stack.progress >= 100) {
161162
BlockPos prevSet = null;
162163
if (stack.hasPath()) {
163-
int currentIndex = stack.getPath().indexOf(getBlockPos());
164+
int currentIndex = stack.getPath().indexOf(pos);
164165
if (currentIndex == 0) { //Necessary for transition reasons, not sure why
165166
deletes.add(stackId);
166167
continue;
@@ -221,15 +222,20 @@ public void onUpdateServer() {
221222
tryRecalculate = true;
222223
}
223224
} else {
224-
LogisticalTransporterBase nextTransmitter = network.getTransmitter(stack.getNext(this));
225-
if (nextTransmitter == null && stack.getPathType().noTarget() && stack.getPath().size() == 2) {
226-
//If there is no next transmitter, and it was an idle path, assume that we are idling
227-
// in a single length transmitter, in which case we only recalculate it at 50 if it won't
228-
// be able to go into that connection type
229-
ConnectionType connectionType = getConnectionType(stack.getSide(this));
230-
tryRecalculate = !connectionType.canSendTo();
225+
BlockPos nextPos = stack.getNext(this);
226+
if (nextPos == null) {
227+
tryRecalculate = true;
231228
} else {
232-
tryRecalculate = !stack.canInsertToTransporter(nextTransmitter, stack.getSide(this), this);
229+
Direction nextSide = stack.getSide(pos, nextPos);
230+
LogisticalTransporterBase nextTransmitter = network.getTransmitter(nextPos);
231+
if (nextTransmitter == null && stack.getPathType().noTarget() && stack.getPath().size() == 2) {
232+
//If there is no next transmitter, and it was an idle path, assume that we are idling
233+
// in a single length transmitter, in which case we only recalculate it at 50 if it won't
234+
// be able to go into that connection type
235+
tryRecalculate = !getConnectionType(nextSide).canSendTo();
236+
} else {
237+
tryRecalculate = !stack.canInsertToTransporter(nextTransmitter, nextSide, this);
238+
}
233239
}
234240
}
235241
if (tryRecalculate && !recalculate(stackId, stack, null)) {
@@ -240,7 +246,7 @@ public void onUpdateServer() {
240246

241247
if (!deletes.isEmpty() || !needsSync.isEmpty()) {
242248
//Notify clients, so that we send the information before we start clearing our lists
243-
PacketUtils.sendToAllTracking(new PacketTransporterBatch(getBlockPos(), deletes, needsSync), getTransmitterTile());
249+
PacketUtils.sendToAllTracking(new PacketTransporterBatch(pos, deletes, needsSync), getTransmitterTile());
244250
// Now remove any entries from transit that have been deleted
245251
OfInt ofInt = deletes.iterator();
246252
while (ofInt.hasNext()) {

src/main/java/mekanism/common/content/transporter/TransporterStack.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,12 @@ public boolean isFinal(LogisticalTransporterBase transporter) {
236236
return pathToTarget.indexOf(transporter.getBlockPos()) == (getPathType().hasTarget() ? 1 : 0);
237237
}
238238

239+
@Nullable
239240
public BlockPos getNext(LogisticalTransporterBase transporter) {
240241
return transporter.isRemote() ? clientNext : getNext(transporter.getBlockPos());
241242
}
242243

244+
@Nullable
243245
private BlockPos getNext(BlockPos pos) {
244246
int index = pathToTarget.indexOf(pos) - 1;
245247
if (index < 0) {
@@ -280,6 +282,15 @@ public Direction getSide(LogisticalTransporterBase transporter) {
280282
return side == null ? Direction.DOWN : side;
281283
}
282284

285+
public Direction getSide(BlockPos pos, @Nullable BlockPos target) {
286+
Direction side = null;
287+
if (target != null) {
288+
side = WorldUtils.sideDifference(target, pos);
289+
}
290+
//TODO: See getSide(Transporter) for why we null check and then return down
291+
return side == null ? Direction.DOWN : side;
292+
}
293+
283294
@Contract("null, _, _ -> false")
284295
public boolean canInsertToTransporter(@Nullable LogisticalTransporterBase transmitter, Direction from, @Nullable LogisticalTransporterBase transporterFrom) {
285296
return transmitter != null && canInsertToTransporterNN(transmitter, from, transporterFrom);

0 commit comments

Comments
 (0)