Skip to content

Commit

Permalink
Fix chained world block exporter/exporter not able to work every tick
Browse files Browse the repository at this point in the history
This is done by making the exporter/importer sleep optimization only
take effect if these parts were unable to move anything for at least
three ticks.

Closes #319
  • Loading branch information
rubensworks committed Jan 8, 2025
1 parent e1ba701 commit 951bc4a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class GeneralConfig extends DummyConfig {
@ConfigurableProperty(category = "core", comment = "If the version checker should be enabled.")
public static boolean versionChecker = true;

@ConfigurableProperty(category = "core", comment = "For how many ticks importers/exporters should fail to process before they can start sleeping.", configLocation = ModConfig.Type.SERVER)
public static int inventoryUnchangedTickCount = 3;
@ConfigurableProperty(category = "core", comment = "How many ticks importers/exporters should sleep until checking targets again when they were previously unchanged.", configLocation = ModConfig.Type.SERVER)
public static int inventoryUnchangedTickTimeout = 10;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,6 @@ public void updateActiveHandSimulated() {

@Override
public void startSleeping(BlockPos blockPos) {
// Dp nothing
// Do nothing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
*/
public class TunnelHelpers {

private static final Cache<ITunnelConnection, Boolean> CACHE_INV_CHECKS = CacheBuilder.newBuilder()
private static final Cache<ITunnelConnection, Integer> CACHE_INV_CHECKS = CacheBuilder.newBuilder()
.expireAfterWrite(GeneralConfig.inventoryUnchangedTickTimeout * (1000 / MinecraftHelpers.SECOND_IN_TICKS),
TimeUnit.MILLISECONDS).build();

Expand Down Expand Up @@ -149,15 +149,18 @@ public static <T, M> T moveSingleStateOptimized(INetwork network, IPositionedAdd
}

// Don't do anything if we are sleeping for this connection
if (CACHE_INV_CHECKS.getIfPresent(connection) != null) {
Integer sleepCheck = CACHE_INV_CHECKS.getIfPresent(connection);
if (sleepCheck != null && sleepCheck >= GeneralConfig.inventoryUnchangedTickCount) {
return matcher.getEmptyInstance();
}

// Do the actual movement
T moved = moveSingle(source, sourceSlot, destination, destinationSlot, ingredientPredicate, movementPosition, false);
if (matcher.isEmpty(moved)) {
// Mark this connection as 'sleeping' if nothing was moved
CACHE_INV_CHECKS.put(connection, true);
CACHE_INV_CHECKS.put(connection, sleepCheck == null ? 1 : sleepCheck + 1);
} else if (sleepCheck != null) {
CACHE_INV_CHECKS.invalidate(connection);
}

// Schedule a new observation for the network, as its contents may have changed
Expand Down

0 comments on commit 951bc4a

Please sign in to comment.