mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
Ability to get block entities from a chunk without snapshots
This commit is contained in:
parent
d178f73bb8
commit
584836a2e4
1 changed files with 30 additions and 1 deletions
|
@ -174,6 +174,13 @@ public class CraftChunk implements Chunk {
|
|||
|
||||
@Override
|
||||
public BlockState[] getTileEntities() {
|
||||
// Paper start
|
||||
return getTileEntities(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState[] getTileEntities(boolean useSnapshot) {
|
||||
// Paper end
|
||||
if (!this.isLoaded()) {
|
||||
this.getWorld().getChunkAt(this.x, this.z); // Transient load for this tick
|
||||
}
|
||||
|
@ -183,7 +190,29 @@ public class CraftChunk implements Chunk {
|
|||
BlockState[] entities = new BlockState[chunk.blockEntities.size()];
|
||||
|
||||
for (BlockPos position : chunk.blockEntities.keySet()) {
|
||||
entities[index++] = this.worldServer.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()).getState();
|
||||
// Paper start
|
||||
entities[index++] = this.worldServer.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ()).getState(useSnapshot);
|
||||
}
|
||||
|
||||
return entities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<BlockState> getTileEntities(Predicate<? super Block> blockPredicate, boolean useSnapshot) {
|
||||
Preconditions.checkNotNull(blockPredicate, "blockPredicate");
|
||||
if (!this.isLoaded()) {
|
||||
this.getWorld().getChunkAt(this.x, this.z); // Transient load for this tick
|
||||
}
|
||||
ChunkAccess chunk = this.getHandle(ChunkStatus.FULL);
|
||||
|
||||
java.util.List<BlockState> entities = new java.util.ArrayList<>();
|
||||
|
||||
for (BlockPos position : chunk.blockEntities.keySet()) {
|
||||
Block block = this.worldServer.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ());
|
||||
if (blockPredicate.test(block)) {
|
||||
entities.add(block.getState(useSnapshot));
|
||||
}
|
||||
// Paper end
|
||||
}
|
||||
|
||||
return entities;
|
||||
|
|
Loading…
Reference in a new issue