Skip to content

Commit

Permalink
Search chunk palettes when recording taters
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 committed Jun 19, 2024
1 parent 4934c9d commit 1f5a41f
Showing 1 changed file with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public Item getPolymerItem(ItemStack stack, ServerPlayerEntity player) {
private static void recordToGuidebook(ServerPlayerEntity player, SetMultimap<Item, BlockPos> taterPositions, ItemStack stack) {
int initialCount = taterPositions.size();

var pos = new BlockPos.Mutable();
var chunkManager = player.getServerWorld().getChunkManager();

var chunkStorage = chunkManager.threadedAnvilChunkStorage;
Expand All @@ -85,7 +84,7 @@ private static void recordToGuidebook(ServerPlayerEntity player, SetMultimap<Ite
var chunk = holder.getWorldChunk();

if (chunk != null) {
recordChunk(chunk, pos, taterPositions);
recordChunk(chunk, taterPositions);
}
}

Expand All @@ -97,19 +96,12 @@ private static void recordToGuidebook(ServerPlayerEntity player, SetMultimap<Ite
player.sendMessage(Text.translatable("text.nucleoid_extras.tater_guidebook.recorded", difference), true);
}

private static void recordChunk(Chunk chunk, BlockPos.Mutable pos, SetMultimap<Item, BlockPos> taterPositions) {
for (int z = 0; z < 16; z++) {
for (int y = chunk.getBottomY(); y < chunk.getTopY(); y++) {
for (int x = 0; x < 16; x++) {
pos.set(x, y, z);
var state = chunk.getBlockState(pos);

if (state.getBlock() instanceof TinyPotatoBlock taterBlock) {
taterPositions.put(taterBlock.asItem(), chunk.getPos().getBlockPos(x, y, z));
}
}
}
}
private static void recordChunk(Chunk chunk, SetMultimap<Item, BlockPos> taterPositions) {
chunk.forEachBlockMatchingPredicate(state -> {
return state.getBlock() instanceof TinyPotatoBlock;
}, (pos, state) -> {
taterPositions.put(state.getBlock().asItem(), pos.toImmutable());
});
}

private static void showGuidebook(ServerPlayerEntity player, SetMultimap<Item, BlockPos> taterPositionMap, ItemStack stack) {
Expand Down

0 comments on commit 1f5a41f

Please sign in to comment.