Fix devices in unloaded chunks not being removed from element device list.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user