From 2e7220e40d3997f7ac81d8bbf1e6d496a7470787 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 27 Mar 2015 19:20:19 +1100 Subject: [PATCH] Fix debugclear --- .../plot/generator/HybridGen.java | 107 ++++-------------- .../plot/object/PlotGenerator.java | 33 ++++-- .../plot/object/PlotPopulator.java | 4 +- 3 files changed, 48 insertions(+), 96 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java index a2285f6cb..944792816 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java @@ -30,8 +30,6 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Biome; -import org.bukkit.generator.BlockPopulator; -import org.bukkit.generator.ChunkGenerator.BiomeGrid; import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.object.PlotLoc; @@ -40,7 +38,6 @@ import com.intellectualcrafters.plot.object.PlotPopulator; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.object.RegionWrapper; -import com.intellectualcrafters.plot.util.ChunkManager; /** * The default generator is very messy, as we have decided to try externalize all calculations from within the loop. - @@ -78,14 +75,6 @@ public class HybridGen extends PlotGenerator { short pathWidthUpper; boolean doState = false; int maxY = 0; - /** - * result object is returned for each generated chunk, do stuff to it - */ - short[][] result; - /** - * Faster sudo-random number generator than java.util.random - */ - private long state = 13; /** * Initialize variables, and create plotworld object used in calculations @@ -131,7 +120,6 @@ public class HybridGen extends PlotGenerator { * Return the plot manager for this type of generator, or create one For square plots you may as well use the * default plot manager which comes with PlotSquared */ - @Override public PlotManager getPlotManager() { if (HybridGen.manager == null) { HybridGen.manager = new HybridPlotManager(); @@ -139,18 +127,9 @@ public class HybridGen extends PlotGenerator { return HybridGen.manager; } - /** - * Allow spawning everywhere - */ - @Override - public boolean canSpawn(final World world, final int x, final int z) { - return true; - } - /** * Get a new plotworld class For square plots you can use the DefaultPlotWorld class which comes with PlotSquared */ - @Override public PlotWorld getNewPlotWorld(final String world) { if (this.plotworld == null) { this.plotworld = new HybridPlotWorld(world); @@ -158,43 +137,6 @@ public class HybridGen extends PlotGenerator { return this.plotworld; } - public final long nextLong() { - final long a = this.state; - this.state = xorShift64(a); - return a; - } - - public final long xorShift64(long a) { - a ^= (a << 21); - a ^= (a >>> 35); - a ^= (a << 4); - return a; - } - - public final int random(final int n) { - final long r = ((nextLong() >>> 32) * n) >> 32; - return (int) r; - } - - private void setBlock(final short[][] result, final int x, final int y, final int z, final short[] blkids) { - if (blkids.length == 1) { - setBlock(result, x, y, z, blkids[0]); - } else { - final int i = random(blkids.length); - setBlock(result, x, y, z, blkids[i]); - } - } - - /** - * Standard setblock method for world generation - */ - private void setBlock(final short[][] result, final int x, final int y, final int z, final short blkid) { - if (result[y >> 4] == null) { - result[y >> 4] = new short[4096]; - } - result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blkid; - } - /** * Return the block populator */ @@ -207,31 +149,22 @@ public class HybridGen extends PlotGenerator { /** * Return the default spawn location for this world */ - @Override - public Location getFixedSpawnLocation(final World world, final Random random) { - if (this.plotworld == null) { - return new Location(world, 0, 128, 0); - } - return new Location(world, 0, this.plotworld.ROAD_HEIGHT + 2, 0); - } +// public Location getFixedSpawnLocation(final World world, final Random random) { +// if (this.plotworld == null) { +// return new Location(world, 0, 128, 0); +// } +// return new Location(world, 0, this.plotworld.ROAD_HEIGHT + 2, 0); +// } /** * This part is a fucking mess. - Refer to a proper tutorial if you would like to learn how to make a world * generator */ - @Override - public short[][] generateChunk(final World world, RegionWrapper region, final PseudoRandom random, final int cx, final int cz, final BiomeGrid biomes, final short[][] result) { - if (this.doState) { - final int prime = 13; - int h = 1; - h = (prime * h) + cx; - h = (prime * h) + cz; - this.state = h; - } + public void generateChunk(final World world, RegionWrapper region, final PseudoRandom random, final int cx, final int cz, final BiomeGrid biomes) { if (this.plotworld.PLOT_BEDROCK) { for (short x = 0; x < 16; x++) { for (short z = 0; z < 16; z++) { - setBlock(this.result, x, 0, z, (short) 7); + setBlock(x, 0, z, (short) 7); } } } @@ -253,20 +186,20 @@ public class HybridGen extends PlotGenerator { } if (contains(region, x, z)) { for (short y = 1; y < this.plotheight; y++) { - setBlock(this.result, x, y, z, this.filling); + setBlock(x, y, z, this.filling); } - setBlock(this.result, x, this.plotheight, z, this.plotfloors); + setBlock(x, this.plotheight, z, this.plotfloors); final PlotLoc loc = new PlotLoc((short) (X + x), (short) (Z + z)); final HashMap blocks = plotworld.G_SCH.get(loc); if (blocks != null) { for (final Entry entry : blocks.entrySet()) { - setBlock(this.result, x, this.plotheight + entry.getKey(), z, entry.getValue()); + setBlock(x, this.plotheight + entry.getKey(), z, entry.getValue()); } } } } } - return this.result; + return; } int sx = ((cx << 4) % this.size); int sz = ((cz << 4) % this.size); @@ -290,15 +223,15 @@ public class HybridGen extends PlotGenerator { // inside plot if (gx && gz && lx && lz) { for (short y = 1; y < this.plotheight; y++) { - setBlock(this.result, x, y, z, this.filling); + setBlock(x, y, z, this.filling); } - setBlock(this.result, x, this.plotheight, z, this.plotfloors); + setBlock(x, this.plotheight, z, this.plotfloors); if (this.plotworld.PLOT_SCHEMATIC) { final PlotLoc loc = new PlotLoc((short) absX, (short) absZ); final HashMap blocks = this.plotworld.G_SCH.get(loc); if (blocks != null) { for (final Entry entry : blocks.entrySet()) { - setBlock(this.result, x, this.plotheight + entry.getKey(), z, entry.getValue()); + setBlock(x, this.plotheight + entry.getKey(), z, entry.getValue()); } } } @@ -306,16 +239,16 @@ public class HybridGen extends PlotGenerator { // wall if (((absX >= this.pathWidthLower) && (absX <= this.pathWidthUpper) && (absZ >= this.pathWidthLower) && (absZ <= this.pathWidthUpper))) { for (short y = 1; y <= this.wallheight; y++) { - setBlock(this.result, x, y, z, this.wallfilling); + setBlock(x, y, z, this.wallfilling); } if (!this.plotworld.ROAD_SCHEMATIC_ENABLED) { - setBlock(this.result, x, this.wallheight + 1, z, this.wall); + setBlock(x, this.wallheight + 1, z, this.wall); } } // road else { for (short y = 1; y <= this.roadheight; y++) { - setBlock(this.result, x, y, z, this.roadblock); + setBlock(x, y, z, this.roadblock); } } if (this.plotworld.ROAD_SCHEMATIC_ENABLED) { @@ -323,13 +256,13 @@ public class HybridGen extends PlotGenerator { final HashMap blocks = this.plotworld.G_SCH.get(loc); if (blocks != null) { for (final Entry entry : blocks.entrySet()) { - setBlock(this.result, x, this.roadheight + entry.getKey(), z, entry.getValue()); + setBlock(x, this.roadheight + entry.getKey(), z, entry.getValue()); } } } } } } - return this.result; + return; } } 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 31c71d9b0..92f77c1ea 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java @@ -65,7 +65,7 @@ public abstract class PlotGenerator extends ChunkGenerator { } @Override - public short[][] generateExtBlockSections(final World world, final Random r, final int cx, final int cz, final BiomeGrid biomes) { + public short[][] generateExtBlockSections(World world, Random r, int cx, int cz, BiomeGrid biomes) { final int prime = 13; int h = 1; h = (prime * h) + cx; @@ -74,9 +74,9 @@ public abstract class PlotGenerator extends ChunkGenerator { this.result = new short[256 / 16][]; PlotWorld plotworld = PlotSquared.getPlotWorld(world.getName()); Biome biome = Biome.valueOf(plotworld.PLOT_BIOME); + this.X = cx << 4; + this.Z = cz << 4; if (ChunkManager.FORCE_PASTE) { - X = cx << 4; - Z = cz << 4; for (short x = 0; x < 16; x++) { for (short z = 0; z < 16; z++) { if (biomes != null) { @@ -91,26 +91,37 @@ public abstract class PlotGenerator extends ChunkGenerator { } return this.result; } - this.result = generateChunk(world, ChunkManager.CURRENT_PLOT_CLEAR, random, cx, cz, biomes, result); + generateChunk(world, ChunkManager.CURRENT_PLOT_CLEAR, random, cx, cz, biomes); if (ChunkManager.CURRENT_PLOT_CLEAR != null) { PlotLoc loc; for (Entry> entry : ChunkManager.GENERATE_BLOCKS.entrySet()) { for (Entry entry2 : entry.getValue().entrySet()) { loc = entry.getKey(); - setBlock(loc.x, entry2.getKey(), loc.z, entry2.getValue()); + setBlock(loc.x - X, entry2.getKey(), loc.z- Z, entry2.getValue()); } } } return result; } - private void setBlock(final int x, final int y, final int z, final short blkid) { + public void setBlock(final int x, final int y, final int z, final short blkid) { if (result[y >> 4] == null) { result[y >> 4] = new short[4096]; } result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blkid; } + public void setBlock(final int x, final int y, final int z, final short[] blkid) { + if (blkid.length == 1) { + setBlock(x, y, z, blkid[0]); + } + short id = blkid[random.random(blkid.length)]; + if (result[y >> 4] == null) { + result[y >> 4] = new short[4096]; + } + result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = id; + } + /** * check if a region contains a location. (x, z) must be between [0,15], [0,15] * @param plot @@ -124,6 +135,14 @@ public abstract class PlotGenerator extends ChunkGenerator { return ((xx >= plot.minX) && (xx <= plot.maxX) && (zz >= plot.minZ) && (zz <= plot.maxZ)); } + /** + * Allow spawning everywhere + */ + @Override + public boolean canSpawn(final World world, final int x, final int z) { + return true; + } + /** * random is a optimized random number generator.
* - Change the state to have the same chunk random each time it generates
@@ -143,7 +162,7 @@ public abstract class PlotGenerator extends ChunkGenerator { * @param result * @return */ - public abstract short[][] generateChunk(final World world, RegionWrapper requiredRegion, final PseudoRandom random, final int cx, final int cz, final BiomeGrid biomes, final short[][] result); + public abstract void generateChunk(final World world, RegionWrapper requiredRegion, final PseudoRandom random, final int cx, final int cz, final BiomeGrid biomes); public abstract List getPopulators(String world); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPopulator.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPopulator.java index e50fcced3..87e05f043 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPopulator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPopulator.java @@ -46,7 +46,7 @@ public abstract class PlotPopulator extends BlockPopulator { for (Entry> entry : ChunkManager.GENERATE_DATA.entrySet()) { for (Entry entry2 : entry.getValue().entrySet()) { loc = entry.getKey(); - setBlock(loc.x, entry2.getKey(), loc.z, entry2.getValue()); + setBlock(loc.x - X, entry2.getKey(), loc.z - Z, entry2.getValue()); } } } @@ -74,7 +74,7 @@ public abstract class PlotPopulator extends BlockPopulator { * @param data */ public void setBlock(int x, int y, int z, byte data) { - world.getBlockAt(X + x, y, Z + z).setTypeId(data); + world.getBlockAt(X + x, y, Z + z).setData(data); } /**