block queue

This commit is contained in:
boy0001 2015-04-16 21:25:02 +10:00
parent e239a49be1
commit d650c3dd86
2 changed files with 84 additions and 1 deletions

View File

@ -71,7 +71,7 @@ public abstract class PlotGenerator extends ChunkGenerator {
h = (prime * h) + cx;
h = (prime * h) + cz;
this.random.state = h;
this.result = new short[256 / 16][];
this.result = new short[16][];
PlotWorld plotworld = PlotSquared.getPlotWorld(world.getName());
Biome biome = Biome.valueOf(plotworld.PLOT_BIOME);
this.X = cx << 4;

View File

@ -0,0 +1,83 @@
package com.intellectualcrafters.plot.util.bukkit;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
import com.intellectualcrafters.plot.util.TaskManager;
public class DebugSetBlockQueue {
private HashMap<Chunk, short[][]> blocks;
private int allocate = 100;
public void allocate(int t) {
this.allocate = t;
}
public DebugSetBlockQueue() {
blocks = new HashMap<>();
TaskManager.index.increment();
final int current = TaskManager.index.intValue();
int task = TaskManager.runTaskRepeat(new Runnable() {
@Override
public void run() {
if (blocks.size() == 0) {
blocks = null;
Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(current));
return;
}
long start = System.currentTimeMillis() + allocate;
Iterator<Entry<Chunk, short[][]>> i = blocks.entrySet().iterator();
while (System.currentTimeMillis() < start && i.hasNext()) {
Entry<Chunk, short[][]> n = i.next();
i.remove();
Chunk chunk = n.getKey();
int X = chunk.getX() << 4;
int Z = chunk.getZ() << 4;
short[][] blocks = n.getValue();
World world = chunk.getWorld();
for (int j = 0; j < blocks.length; j++) {
short[] blocksj = blocks[j];
if (blocksj != null) {
for (int k = 0; k < blocksj.length; k++) {
short id = blocksj[k];
if (id != 0) {
final int y = (j << 4) + (k >> 8);
final int a = (k - ((y & 0xF) << 8));
final int z = (a >> 4);
final int x = a - (z << 4);
BukkitSetBlockManager.setBlockManager.set(world, X + x, y, Z + z, id, (byte) 0);
}
}
}
}
}
}
}, 20);
TaskManager.tasks.put(current, task);
}
public void setBlock(final World world, int x, final int y, int z, final short blkid) {
int X = x >> 4;
int Z = z >> 4;
x -= X << 4;
z -= Z << 4;
Chunk chunk = world.getChunkAt(X, Z);
short[][] result = blocks.get(chunk);
if (!blocks.containsKey(chunk)) {
result = new short[16][];
blocks.put(chunk, result);
}
if (result[y >> 4] == null) {
result[y >> 4] = new short[4096];
}
result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blkid;
}
}