From d650c3dd8617b856a76d817227ad4404724230a2 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Thu, 16 Apr 2015 21:25:02 +1000 Subject: [PATCH] block queue --- .../plot/object/PlotGenerator.java | 2 +- .../plot/util/bukkit/DebugSetBlockQueue.java | 83 +++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/DebugSetBlockQueue.java diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java index f38c8731e..9bff22155 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java @@ -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; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/DebugSetBlockQueue.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/DebugSetBlockQueue.java new file mode 100644 index 000000000..63bb91970 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/bukkit/DebugSetBlockQueue.java @@ -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 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> i = blocks.entrySet().iterator(); + while (System.currentTimeMillis() < start && i.hasNext()) { + Entry 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; + } +}