Paranoia: when removing cable/interface, ensure previously known devices are disposed via controller, even if they're currently in unloaded chunks.

This commit is contained in:
Florian Nücke
2022-02-13 16:56:08 +01:00
parent 3fdf49f3af
commit f98d457774
2 changed files with 17 additions and 6 deletions

View File

@@ -251,12 +251,7 @@ public final class BusCableBlockEntity extends ModBlockEntity {
super.unloadServer(isRemove);
if (isRemove) {
// Bus element will usually be discovered via bus scan, not via capability request, so
// automatic invalidation via capability will *not* necessarily schedule a scan on the
// controller of our current bus. So we need to trigger that manually.
// The controller already listens to chunk unloads, so we don't want to call this when
// the containing chunk gets unloaded, only when we're being removed.
busElement.scheduleScan();
busElement.setRemoved();
}
for (final NeighborTracker tracker : neighborTrackers) {

View File

@@ -87,6 +87,22 @@ public abstract class AbstractBlockDeviceBusElement extends AbstractGroupingDevi
);
}
public void setRemoved() {
final LevelAccessor level = getLevel();
if (level == null || level.isClientSide()) {
return;
}
for (final Direction side : Direction.values()) {
final int index = side.get3DDataValue();
final BlockPos pos = getPosition().relative(side);
final BlockDeviceQuery query = Devices.makeQuery(level, pos, side.getOpposite());
setEntriesForGroup(index, new BlockQueryResult(query, Collections.emptySet()));
}
scheduleScan();
}
///////////////////////////////////////////////////////////////////
protected boolean canScanContinueTowards(@Nullable final Direction direction) {