Fix devices in unloaded chunks not being removed from element device list.

This commit is contained in:
Florian Nücke
2022-02-13 17:36:16 +01:00
parent 356cf1f5c0
commit b92152c593
2 changed files with 20 additions and 2 deletions

View File

@@ -124,12 +124,13 @@ public abstract class AbstractGroupingDeviceBusElement<TEntry extends AbstractGr
saveGroup(index);
final HashSet<TEntry> removedEntries = new HashSet<>(oldEntries);
for (final TEntry entry : removedEntries) {
for (final TEntry entry : oldEntries) {
devices.removeInt(entry.getDevice());
onEntryRemoved(entry);
}
oldEntries.clear();
scanDevices();
}

View File

@@ -218,6 +218,23 @@ public class BlockDeviceBusControllerTests {
assertTrue(busController.getDevices().contains(deviceBlockEntity.getObjectDevice()));
}
@Test
public void unloadedDeviceIsRemovedFromElement() {
final BlockPos elementPos = new BlockPos(0, 0, 8);
final TestBusElementBlockEntity busElementInfo = new TestBusElementBlockEntity(elementPos);
final BlockPos devicePos = elementPos.west();
final TestDeviceBlockEntity deviceBlockEntity = new TestDeviceBlockEntity(devicePos);
busElementInfo.getBusElement().updateDevicesForNeighbor(Direction.WEST);
assertTrue(busElementInfo.getBusElement().getDevices().contains(deviceBlockEntity.getObjectDevice()));
fakeLevel.setChunkLoaded(new ChunkPos(devicePos), false);
busElementInfo.getBusElement().updateDevicesForNeighbor(Direction.WEST);
assertFalse(busElementInfo.getBusElement().getDevices().contains(deviceBlockEntity.getObjectDevice()));
}
@Test
public void devicesGetSerializedWhenUnloadedAndDeserializedWhenLoaded() {
final BlockPos controllerPos = new BlockPos(1, 0, 8);