Search in sources :

Example 1 with NumberTag

use of cn.nukkit.nbt.tag.NumberTag in project Nukkit by Nukkit.

the class BaseFullChunk method initChunk.

public void initChunk() {
    if (this.getProvider() != null && !this.isInit) {
        boolean changed = false;
        if (this.NBTentities != null) {
            this.getProvider().getLevel().timings.syncChunkLoadEntitiesTimer.startTiming();
            for (CompoundTag nbt : NBTentities) {
                if (!nbt.contains("id")) {
                    this.setChanged();
                    continue;
                }
                ListTag pos = nbt.getList("Pos");
                if ((((NumberTag) pos.get(0)).getData().intValue() >> 4) != this.getX() || ((((NumberTag) pos.get(2)).getData().intValue() >> 4) != this.getZ())) {
                    changed = true;
                    continue;
                }
                Entity entity = Entity.createEntity(nbt.getString("id"), this, nbt);
                if (entity != null) {
                    changed = true;
                    continue;
                }
            }
            this.getProvider().getLevel().timings.syncChunkLoadEntitiesTimer.stopTiming();
            this.NBTentities = null;
        }
        if (this.NBTtiles != null) {
            this.getProvider().getLevel().timings.syncChunkLoadBlockEntitiesTimer.startTiming();
            for (CompoundTag nbt : NBTtiles) {
                if (nbt != null) {
                    if (!nbt.contains("id")) {
                        changed = true;
                        continue;
                    }
                    if ((nbt.getInt("x") >> 4) != this.getX() || ((nbt.getInt("z") >> 4) != this.getZ())) {
                        changed = true;
                        continue;
                    }
                    BlockEntity blockEntity = BlockEntity.createBlockEntity(nbt.getString("id"), this, nbt);
                    if (blockEntity == null) {
                        changed = true;
                        continue;
                    }
                }
            }
            this.getProvider().getLevel().timings.syncChunkLoadBlockEntitiesTimer.stopTiming();
            this.NBTtiles = null;
        }
        this.setChanged(changed);
        this.isInit = true;
    }
}
Also used : Entity(cn.nukkit.entity.Entity) BlockEntity(cn.nukkit.blockentity.BlockEntity) NumberTag(cn.nukkit.nbt.tag.NumberTag) ListTag(cn.nukkit.nbt.tag.ListTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag) BlockEntity(cn.nukkit.blockentity.BlockEntity)

Aggregations

BlockEntity (cn.nukkit.blockentity.BlockEntity)1 Entity (cn.nukkit.entity.Entity)1 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)1 ListTag (cn.nukkit.nbt.tag.ListTag)1 NumberTag (cn.nukkit.nbt.tag.NumberTag)1