Skip to content
Open
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
24 changes: 13 additions & 11 deletions src/main/java/cn/nukkit/blockentity/BlockEntitySpawnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,36 @@ public BlockEntitySpawnable(FullChunk chunk, CompoundTag nbt) {

public abstract CompoundTag getSpawnCompound();

public void spawnTo(Player player) {
if (this.closed) {
return;
}

public BlockEntityDataPacket createSpawnPacket() {
CompoundTag tag = this.getSpawnCompound();
BlockEntityDataPacket pk = new BlockEntityDataPacket();
pk.x = (int) this.x;
pk.y = (int) this.y;
pk.z = (int) this.z;

try {
pk.namedTag = NBTIO.write(tag, ByteOrder.LITTLE_ENDIAN, true);
} catch (IOException e) {
throw new RuntimeException(e);
}
player.dataPacket(pk);

return pk;
}

public void spawnToAll() {
public void spawnTo(Player player) {
if (this.closed) {
return;
}

for (Player player : this.getLevel().getChunkPlayers(this.chunk.getX(), this.chunk.getZ()).values()) {
if (player.spawned) {
this.spawnTo(player);
}
player.dataPacket(this.createSpawnPacket());
}

public void spawnToAll() {
if (this.closed) {
return;
}

this.level.addChunkPacket(this.chunk.getX(), this.chunk.getZ(), this.createSpawnPacket());
}

/**
Expand Down