fix akashic bookshelves not properly disconnecting

This commit is contained in:
yrsegal@gmail.com 2022-04-08 12:27:00 -04:00
parent 0ab68324de
commit cd672a8af6
2 changed files with 10 additions and 11 deletions

View file

@ -84,8 +84,8 @@ public class BlockAkashicBookshelf extends BlockAkashicFloodfiller implements En
if (world.getBlockEntity(pos) instanceof BlockEntityAkashicBookshelf tile) { if (world.getBlockEntity(pos) instanceof BlockEntityAkashicBookshelf tile) {
var recordPos = BlockAkashicFloodfiller.floodFillFor(pos, world, var recordPos = BlockAkashicFloodfiller.floodFillFor(pos, world,
(here, bs, level) -> bs.is(HexBlocks.AKASHIC_RECORD.get())); (here, bs, level) -> bs.is(HexBlocks.AKASHIC_RECORD.get()));
if (recordPos != null) { if (pOldState.getBlock() != pState.getBlock()) {
tile.setNewData(recordPos, tile.getPattern(), DatumType.EMPTY); tile.setNewData(recordPos, recordPos == null ? null : tile.getPattern(), DatumType.EMPTY);
} }
} }
} }

View file

@ -52,22 +52,21 @@ public class BlockEntityAkashicBookshelf extends PaucalBlockEntity {
@Override @Override
protected void saveModData(CompoundTag compoundTag) { protected void saveModData(CompoundTag compoundTag) {
if (this.recordPos != null) { compoundTag.put(TAG_RECORD_POS, this.recordPos == null ? new CompoundTag() : NbtUtils.writeBlockPos(this.recordPos));
compoundTag.put(TAG_RECORD_POS, NbtUtils.writeBlockPos(this.recordPos)); compoundTag.put(TAG_PATTERN, this.pattern == null ? new CompoundTag() : this.pattern.serializeToNBT());
}
if (this.pattern != null) {
compoundTag.put(TAG_PATTERN, this.pattern.serializeToNBT());
}
} }
@Override @Override
protected void loadModData(CompoundTag compoundTag) { protected void loadModData(CompoundTag compoundTag) {
if (compoundTag.contains(TAG_RECORD_POS)) { CompoundTag recordPos = compoundTag.getCompound(TAG_RECORD_POS);
this.recordPos = NbtUtils.readBlockPos(compoundTag.getCompound(TAG_RECORD_POS)); CompoundTag pattern = compoundTag.getCompound(TAG_PATTERN);
if (!recordPos.isEmpty()) {
this.recordPos = NbtUtils.readBlockPos(recordPos);
} else { } else {
this.recordPos = null; this.recordPos = null;
} }
if (compoundTag.contains(TAG_PATTERN)) { if (!pattern.isEmpty()) {
this.pattern = HexPattern.DeserializeFromNBT(compoundTag.getCompound(TAG_PATTERN)); this.pattern = HexPattern.DeserializeFromNBT(compoundTag.getCompound(TAG_PATTERN));
} else { } else {
this.pattern = null; this.pattern = null;