Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Loading