diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/akashic/BlockAkashicRecord.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/akashic/BlockAkashicRecord.java index db3f96ac14..7ad6a1724c 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/blocks/akashic/BlockAkashicRecord.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/akashic/BlockAkashicRecord.java @@ -22,24 +22,25 @@ public BlockAkashicRecord(Properties p_49795_) { */ public @Nullable BlockPos addNewDatum(BlockPos herePos, Level level, HexPattern key, Iota datum) { - var clobbereePos = AkashicFloodfiller.floodFillFor(herePos, level, + // Look for existing shelf with the same pattern to overwrite + var targetPos = AkashicFloodfiller.floodFillFor(herePos, level, (pos, bs, world) -> world.getBlockEntity(pos) instanceof BlockEntityAkashicBookshelf tile && tile.getPattern() != null && tile.getPattern().sigsEqual(key)); - if (clobbereePos != null) { - return null; + if (targetPos == null) { + // Otherwise find an empty shelf + targetPos = AkashicFloodfiller.floodFillFor(herePos, level, 0.9f, + (pos, bs, world) -> + world.getBlockEntity(pos) instanceof BlockEntityAkashicBookshelf tile + && tile.getPattern() == null, 128); } - var openPos = AkashicFloodfiller.floodFillFor(herePos, level, 0.9f, - (pos, bs, world) -> - world.getBlockEntity(pos) instanceof BlockEntityAkashicBookshelf tile - && tile.getPattern() == null, 128); - if (openPos != null) { - var tile = (BlockEntityAkashicBookshelf) level.getBlockEntity(openPos); + if (targetPos != null) { + var tile = (BlockEntityAkashicBookshelf) level.getBlockEntity(targetPos); tile.setNewMapping(key, datum); - return openPos; + return targetPos; } else { return null; } diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/akashic/BlockEntityAkashicBookshelf.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/akashic/BlockEntityAkashicBookshelf.java index d6e4cd8041..1cf96afb52 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/blocks/akashic/BlockEntityAkashicBookshelf.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/akashic/BlockEntityAkashicBookshelf.java @@ -44,13 +44,14 @@ public void setNewMapping(HexPattern pattern, Iota iota) { this.pattern = pattern; this.iotaTag = IotaType.serialize(iota); + var oldBs = this.getBlockState(); if (previouslyEmpty) { - var oldBs = this.getBlockState(); var newBs = oldBs.setValue(BlockAkashicBookshelf.HAS_BOOKS, true); this.level.setBlock(this.getBlockPos(), newBs, 3); this.level.sendBlockUpdated(this.getBlockPos(), oldBs, newBs, 3); } else { this.setChanged(); + this.level.sendBlockUpdated(this.getBlockPos(), oldBs, oldBs, 3); } }