本文整理汇总了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();
}
}
示例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;
}
示例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();
}
示例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;
}
}
}
}
示例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;
}
}
}
}
示例6: getChunkXZ
import cn.nukkit.level.format.Chunk; //导入依赖的package包/类
public static Chunk.Entry getChunkXZ(long hash) {
return new Chunk.Entry(getHashX(hash), getHashZ(hash));
}
示例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;
}
示例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]));
}
示例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();
}