Fixed devices not being updated when loading item list. Fix not applying loaded device data to existing devices.

Fixes initial robot state on placement.
This commit is contained in:
Florian Nücke
2022-01-09 09:53:37 +01:00
parent 1e59043b01
commit 728504900e
2 changed files with 13 additions and 3 deletions

View File

@@ -78,6 +78,16 @@ public abstract class AbstractGroupingDeviceBusElement<T extends AbstractGroupin
if (sideTag.contains(GROUP_DATA_TAG_NAME, NBTTagIds.TAG_COMPOUND)) {
groupData[i] = sideTag.getCompound(GROUP_DATA_TAG_NAME);
}
// Immediately load data into devices, if we already have some.
for (final T entry : groups.get(i)) {
final CompoundTag devicesTag = groupData[i];
entry.getDeviceDataKey().ifPresent(key -> {
if (devicesTag.contains(key, NBTTagIds.TAG_COMPOUND)) {
entry.getDevice().deserializeNBT(devicesTag.getCompound(key));
}
});
}
}
}

View File

@@ -55,13 +55,13 @@ public class DeviceItemStackHandler extends FixedSizeItemStackHandler {
public void loadItems(final CompoundTag tag) {
super.deserializeNBT(tag);
for (int slot = 0; slot < getSlots(); slot++) {
busElement.updateDevices(slot, getStackInSlot(slot));
}
}
public void loadDevices(final CompoundTag tag) {
busElement.load(tag);
for (int slot = 0; slot < getSlots(); slot++) {
busElement.updateDevices(slot, getStackInSlot(slot));
}
}
@Override