• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Chunk类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中cn.nukkit.level.format.Chunk的典型用法代码示例。如果您正苦于以下问题:Java Chunk类的具体用法?Java Chunk怎么用?Java Chunk使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Chunk类属于cn.nukkit.level.format包,在下文中一共展示了Chunk类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: processChunkRequest

import cn.nukkit.level.format.Chunk; //导入依赖的package包/类
private void processChunkRequest() {
    if (!this.chunkSendQueue.isEmpty()) {
        this.timings.syncChunkSendTimer.startTiming();
        for (String index : new ArrayList<>(this.chunkSendQueue.keySet())) {
            if (this.chunkSendTasks.containsKey(index)) {
                continue;
            }
            Chunk.Entry chunkEntry = Level.getChunkXZ(index);
            int x = chunkEntry.chunkX;
            int z = chunkEntry.chunkZ;
            this.chunkSendTasks.put(index, true);
            if (this.chunkCache.containsKey(index)) {
                this.sendChunkFromCache(x, z);
                continue;
            }
            this.timings.syncChunkSendPrepareTimer.startTiming();
            AsyncTask task = this.provider.requestChunkTask(x, z);
            if (task != null) {
                this.server.getScheduler().scheduleAsyncTask(task);
            }
            this.timings.syncChunkSendPrepareTimer.stopTiming();
        }
        this.timings.syncChunkSendTimer.stopTiming();
    }
}
 
开发者ID:Creeperface01,项目名称:NukkitGT,代码行数:26,代码来源:Level.java


示例2: switchLevel

import cn.nukkit.level.format.Chunk; //导入依赖的package包/类
@Override
protected boolean switchLevel(Level targetLevel) {
    Level oldLevel = this.level;
    if (super.switchLevel(targetLevel)) {
        for (String index : new ArrayList<>(this.usedChunks.keySet())) {
            Chunk.Entry chunkEntry = Level.getChunkXZ(index);
            int chunkX = chunkEntry.chunkX;
            int chunkZ = chunkEntry.chunkZ;
            this.unloadChunk(chunkX, chunkZ, oldLevel);
        }

        this.usedChunks = new HashMap<>();
        SetTimePacket pk = new SetTimePacket();
        pk.time = this.level.getTime();
        pk.started = !this.level.stopTime;
        this.dataPacket(pk);
        return true;
    }
    return false;
}
 
开发者ID:Creeperface01,项目名称:NukkitGT,代码行数:21,代码来源:Player.java


示例3: doChunkGarbageCollection

import cn.nukkit.level.format.Chunk; //导入依赖的package包/类
public void doChunkGarbageCollection() {
    this.timings.doChunkGC.startTiming();
    // remove all invaild block entities.
    List<BlockEntity> toClose = new ArrayList<>();
    for (BlockEntity anBlockEntity : blockEntities.values()) {
        if (anBlockEntity == null)
            continue;
        if (anBlockEntity.isBlockEntityValid())
            continue;
        toClose.add(anBlockEntity);
    }
    for (BlockEntity be : toClose.toArray(new BlockEntity[toClose.size()])) {
        be.close();
    }

    for (String index : this.chunks.keySet()) {

        if (!this.unloadQueue.containsKey(index)) {
            Chunk.Entry chunkEntry = Level.getChunkXZ(index);
            int X = chunkEntry.chunkX;
            int Z = chunkEntry.chunkZ;
            if (!this.isSpawnChunk(X, Z)) {
                this.unloadChunkRequest(X, Z, true);
            }
        }
    }

    for (FullChunk chunk : new ArrayList<>(this.provider.getLoadedChunks().values())) {
        if (!this.chunks.containsKey(Level.chunkHash(chunk.getX(), chunk.getZ()))) {
            this.provider.unloadChunk(chunk.getX(), chunk.getZ(), false);
        }
    }

    this.provider.doGarbageCollection();
    this.timings.doChunkGC.stopTiming();
}
 
开发者ID:Creeperface01,项目名称:NukkitGT,代码行数:37,代码来源:Level.java


示例4: unloadChunks

import cn.nukkit.level.format.Chunk; //导入依赖的package包/类
public void unloadChunks(boolean force) {
    if (!this.unloadQueue.isEmpty()) {
        int maxUnload = 96;
        long now = System.currentTimeMillis();

        for (String index : new ArrayList<>(this.unloadQueue.keySet())) {
            long time = this.unloadQueue.get(index);

            Chunk.Entry chunkEntry = Level.getChunkXZ(index);
            int X = chunkEntry.chunkX;
            int Z = chunkEntry.chunkZ;

            if (!force) {
                if (maxUnload <= 0) {
                    break;
                } else if (time > (now - 30000)) {
                    continue;
                }
            }

            if (this.unloadChunk(X, Z, true)) {
                this.unloadQueue.remove(index);
                --maxUnload;
            }
        }
    }
}
 
开发者ID:Creeperface01,项目名称:NukkitGT,代码行数:28,代码来源:Level.java


示例5: unloadChunks

import cn.nukkit.level.format.Chunk; //导入依赖的package包/类
public void unloadChunks(boolean force) {
    if (!this.unloadQueue.isEmpty()) {
        int maxUnload = 96;
        long now = System.currentTimeMillis();

        for (Iterator<String> it = new ArrayList<>(this.unloadQueue.keySet()).iterator(); it.hasNext(); ) {
            String index = it.next();
            long time = this.unloadQueue.get(index);

            Chunk.Entry chunkEntry = Level.getChunkXZ(index);
            int X = chunkEntry.chunkX;
            int Z = chunkEntry.chunkZ;

            if (!force) {
                if (maxUnload <= 0) {
                    break;
                } else if (time > (now - 30000)) {
                    continue;
                }
            }

            if (this.unloadChunk(X, Z, true)) {
                this.unloadQueue.remove(index);
                --maxUnload;
            }
        }
    }
}
 
开发者ID:PrismarineMC,项目名称:MagmaBlock,代码行数:29,代码来源:Level.java


示例6: getChunkXZ

import cn.nukkit.level.format.Chunk; //导入依赖的package包/类
public static Chunk.Entry getChunkXZ(long hash) {
    return new Chunk.Entry(getHashX(hash), getHashZ(hash));
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:4,代码来源:Level.java


示例7: onUpdate

import cn.nukkit.level.format.Chunk; //导入依赖的package包/类
@Override
public boolean onUpdate() {
    if (this.closed) {
        return false;
    }

    this.timing.startTiming();

    if (!(this.chunk instanceof Chunk)) {
        return false;
    }

    if (!(this.canUpdate())) {
        return false;
    }

    if (this.namedTag.getInt("Delay") <= 0) {
        int success = 0;
        NukkitRandom random = new NukkitRandom();
        for (int i = 0; i < this.namedTag.getInt("SpawnCount"); ++i) {
            Vector3 pos = this.add(
                    this.getRandomSpawn(), 
                    NukkitMath.randomRange(random, -1, 1), 
                    this.getRandomSpawn());
            Block target = this.getLevel().getBlock(pos);
            Block ground = target.down();
            if (target.getId() == Block.AIR && ground.isSolid()) {
                ++success;
                CompoundTag nbt = new CompoundTag()
                        .putList(new ListTag<DoubleTag>("Pos")
                                .add(new DoubleTag("", pos.x))
                                .add(new DoubleTag("", pos.y))
                                .add(new DoubleTag("", pos.z)))
                        .putList(new ListTag<DoubleTag>("Motion")
                                .add(new DoubleTag("", 0))
                                .add(new DoubleTag("", 0))
                                .add(new DoubleTag("", 0)))
                        .putList(new ListTag<FloatTag>("Rotation")
                                .add(new FloatTag("", (float) Math.random() * 360))
                                .add(new FloatTag("", (float) 0)));

                Entity entity = Entity.createEntity(this.getNetworkId(), this.chunk, nbt);
                entity.spawnToAll();
            }
        }

        if (success > 0) {
            this.namedTag.putInt("Delay", NukkitMath.randomRange(random, this.namedTag.getInt("MinSpawnDelay"), this.namedTag.getInt("MaxSpawnDelay")));
        }

    } else {
        this.namedTag.putInt("Delay", this.namedTag.getInt("Delay") - 1);
    }

    this.timing.stopTiming();

    return true;
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:59,代码来源:BlockEntityMobSpawner.java


示例8: getChunkXZ

import cn.nukkit.level.format.Chunk; //导入依赖的package包/类
public static Chunk.Entry getChunkXZ(String hash) {
    String[] h = hash.split(":");
    return new Chunk.Entry(Integer.valueOf(h[0]), Integer.valueOf(h[1]));
}
 
开发者ID:Creeperface01,项目名称:NukkitGT,代码行数:5,代码来源:Level.java


示例9: sendNextChunk

import cn.nukkit.level.format.Chunk; //导入依赖的package包/类
protected void sendNextChunk() {
    if (!this.connected) {
        return;
    }

    Timings.playerChunkSendTimer.startTiming();

    int count = 0;

    List<Map.Entry<String, Integer>> entryList = new ArrayList<>(this.loadQueue.entrySet());
    entryList.sort(new Comparator<Map.Entry<String, Integer>>() {
        @Override
        public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
            return o1.getValue() - o2.getValue();
        }
    });

    for (Map.Entry<String, Integer> entry : entryList) {
        String index = entry.getKey();
        if (count >= this.chunksPerTick) {
            break;
        }

        Chunk.Entry chunkEntry = Level.getChunkXZ(index);
        int chunkX = chunkEntry.chunkX;
        int chunkZ = chunkEntry.chunkZ;

        ++count;

        this.usedChunks.put(index, false);
        this.level.registerChunkLoader(this, chunkX, chunkZ, false);

        if (!this.level.populateChunk(chunkX, chunkZ)) {
            if (this.spawned && this.teleportPosition == null) {
                continue;
            } else {
                break;
            }
        }

        this.loadQueue.remove(index);

        PlayerChunkRequestEvent ev = new PlayerChunkRequestEvent(this, chunkX, chunkZ);
        this.server.getPluginManager().callEvent(ev);
        if (!ev.isCancelled()) {
            this.level.requestChunk(chunkX, chunkZ, this);
        }
    }

    if (this.chunkLoadCount >= this.spawnThreshold && !this.spawned && this.teleportPosition == null) {
        this.doFirstSpawn();
    }
    Timings.playerChunkSendTimer.stopTiming();
}
 
开发者ID:Creeperface01,项目名称:NukkitGT,代码行数:55,代码来源:Player.java



注:本文中的cn.nukkit.level.format.Chunk类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CodeException类代码示例发布时间:2022-05-22
下一篇:
Java HttpResponse类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap