Skip to content

Commit

Permalink
fix: Conduits now save filters saved between world reloads
Browse files Browse the repository at this point in the history
  • Loading branch information
vinni57 committed May 14, 2024
1 parent bf0a380 commit 749e9c9
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ public CompoundTag serializeNBT() {
element.putInt(KEY_INSERT, dynamicState.insert().ordinal());
element.putInt(KEY_REDSTONE_CONTROL, dynamicState.control().ordinal());
element.putInt(KEY_REDSTONE_CHANNEL, dynamicState.redstoneChannel().ordinal());
for(SlotType slotType : SlotType.values()){
element.put(slotType.name(), dynamicState.getItem(slotType).serializeNBT());
}
}
tag.put(String.valueOf(i), element);
}
Expand All @@ -144,18 +147,19 @@ public void deserializeNBT(CompoundTag tag) {
var insertIndex = nbt.getInt(KEY_INSERT);
var redControl = nbt.getInt(KEY_REDSTONE_CONTROL);
var redChannel = nbt.getInt(KEY_REDSTONE_CHANNEL);
IConnectionState prev = connectionStates[i];
Optional<DynamicConnectionState> dyn = Optional.ofNullable(prev instanceof DynamicConnectionState dynState ? dynState : null);
var filterInsert = ItemStack.of(nbt.getCompound(SlotType.FILTER_INSERT.name()));
var filterExtract = ItemStack.of(nbt.getCompound(SlotType.FILTER_EXTRACT.name()));
var upgradeExtract = ItemStack.of(nbt.getCompound(SlotType.UPGRADE_EXTRACT.name()));
connectionStates[i] = new DynamicConnectionState(
isInsert,
ColorControl.values()[insertIndex],
isExtract,
ColorControl.values()[extractIndex],
RedstoneControl.values()[redControl],
ColorControl.values()[redChannel],
dyn.map(DynamicConnectionState::filterInsert).orElse(ItemStack.EMPTY),
dyn.map(DynamicConnectionState::filterExtract).orElse(ItemStack.EMPTY),
dyn.map(DynamicConnectionState::upgradeExtract).orElse(ItemStack.EMPTY)
filterInsert,
filterExtract,
upgradeExtract
);
}
}
Expand Down

0 comments on commit 749e9c9

Please sign in to comment.