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 3b7d1ed2a..a2285f6cb 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java @@ -36,6 +36,7 @@ import org.bukkit.generator.ChunkGenerator.BiomeGrid; import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.object.PlotLoc; import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.object.PlotPopulator; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.object.RegionWrapper; @@ -197,10 +198,10 @@ public class HybridGen extends PlotGenerator { /** * Return the block populator */ - public List getPopulators(final String world) { + public List getPopulators(final String world) { // You can have as many populators as you would like, e.g. tree // populator, ore populator - return Arrays.asList((BlockPopulator) new HybridPop(this.plotworld)); + return Arrays.asList((PlotPopulator) new HybridPop(this.plotworld)); } /** @@ -219,7 +220,7 @@ public class HybridGen extends PlotGenerator { * generator */ @Override - public short[][] generateChunk(final World world, RegionWrapper plot, final PseudoRandom random, final int cx, final int cz, final BiomeGrid biomes, final short[][] result) { + 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; @@ -234,7 +235,7 @@ public class HybridGen extends PlotGenerator { } } } - if (plot != null) { + if (region != null) { final int X = cx << 4; final int Z = cz << 4; int sx = ((X) % this.size); @@ -250,7 +251,7 @@ public class HybridGen extends PlotGenerator { if (biomes != null) { biomes.setBiome(x, z, this.biome); } - if (isIn(plot, X + x, Z + z)) { + if (contains(region, x, z)) { for (short y = 1; y < this.plotheight; y++) { setBlock(this.result, x, y, z, this.filling); } @@ -262,14 +263,6 @@ public class HybridGen extends PlotGenerator { setBlock(this.result, x, this.plotheight + entry.getKey(), z, entry.getValue()); } } - } else { - final PlotLoc loc = new PlotLoc((short) (X + x), (short) (Z + z)); - final HashMap blocks = ChunkManager.GENERATE_BLOCKS.get(loc); - if (blocks != null) { - for (final Entry entry : blocks.entrySet()) { - setBlock(this.result, x, entry.getKey(), z, entry.getValue()); - } - } } } } @@ -339,8 +332,4 @@ public class HybridGen extends PlotGenerator { } return this.result; } - - public boolean isIn(final RegionWrapper plot, final int x, final int z) { - return ((x >= plot.minX) && (x <= plot.maxX) && (z >= plot.minZ) && (z <= plot.maxZ)); - } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java index 5ff5d73f8..9f8292b0d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridPop.java @@ -11,7 +11,9 @@ import org.bukkit.generator.BlockPopulator; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.object.PlotLoc; +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.object.schematic.PlotItem; import com.intellectualcrafters.plot.util.BlockManager; @@ -20,7 +22,7 @@ import com.intellectualcrafters.plot.util.ChunkManager; /** * @author Citymonstret */ -public class HybridPop extends BlockPopulator { +public class HybridPop extends PlotPopulator { /* * Sorry, this isn't well documented at the moment. * We advise you to take a look at a world generation tutorial for @@ -108,20 +110,11 @@ public class HybridPop extends BlockPopulator { } @Override - public void populate(final World w, final Random r, final Chunk c) { - final int cx = c.getX(), cz = c.getZ(); - if (this.doState) { - final int prime = 13; - int h = 1; - h = (prime * h) + cx; - h = (prime * h) + cz; - this.state = h; - } + public void populate(World world, RegionWrapper requiredRegion, PseudoRandom random, int cx, int cz) { this.X = cx << 4; this.Z = cz << 4; - PlotSquared.getPlotManager(w.getName()); - final RegionWrapper plot = ChunkManager.CURRENT_PLOT_CLEAR; - if (plot != null) { + PlotSquared.getPlotManager(world.getName()); + if (requiredRegion != null) { short sx = (short) ((this.X) % this.size); short sz = (short) ((this.Z) % this.size); if (sx < 0) { @@ -132,21 +125,21 @@ public class HybridPop extends BlockPopulator { } for (short x = 0; x < 16; x++) { for (short z = 0; z < 16; z++) { - if (isIn(plot, this.X + x, this.Z + z)) { + if (contains(requiredRegion, this.X + x, this.Z + z)) { if (this.doFilling) { for (short y = 1; y < this.plotheight; y++) { - setBlock(w, x, y, z, this.filling); + setBlock(x, y, z, this.filling); } } if (this.doFloor) { - setBlock(w, x, (short) this.plotheight, z, this.plotfloors); + setBlock(x, (short) this.plotheight, z, this.plotfloors); } if (this.plotworld.PLOT_SCHEMATIC) { final PlotLoc loc = new PlotLoc((short) (this.X + x), (short) (this.Z + z)); final HashMap blocks = this.plotworld.G_SCH_DATA.get(loc); if (blocks != null) { for (final short y : blocks.keySet()) { - setBlock(w, x, (short) (this.plotheight + y), z, blocks.get(y)); + setBlock(x, (short) (this.plotheight + y), z, blocks.get(y)); } } if (this.plotworld.G_SCH_STATE != null) { @@ -158,14 +151,6 @@ public class HybridPop extends BlockPopulator { } } } - } else { - final PlotLoc loc = new PlotLoc((short) (this.X + x), (short) (this.Z + z)); - final HashMap data = ChunkManager.GENERATE_DATA.get(loc); - if (data != null) { - for (final short y : data.keySet()) { - setBlock(w, x, y, z, data.get(y).byteValue()); - } - } } } } @@ -192,18 +177,18 @@ public class HybridPop extends BlockPopulator { if (gx && gz && lx && lz) { if (this.doFilling) { for (short y = 1; y < this.plotheight; y++) { - setBlock(w, x, y, z, this.filling); + setBlock(x, y, z, this.filling); } } if (this.doFloor) { - setBlock(w, x, (short) this.plotheight, z, this.plotfloors); + setBlock(x, (short) this.plotheight, z, this.plotfloors); } if (this.plotworld.PLOT_SCHEMATIC) { final PlotLoc loc = new PlotLoc(absX, absZ); final HashMap blocks = this.plotworld.G_SCH_DATA.get(loc); if (blocks != null) { for (final short y : blocks.keySet()) { - setBlock(w, x, (short) (this.plotheight + y), z, blocks.get(y)); + setBlock(x, (short) (this.plotheight + y), z, blocks.get(y)); } } if (this.plotworld.G_SCH_STATE != null) { @@ -222,18 +207,18 @@ public class HybridPop extends BlockPopulator { if (((absX >= this.pathWidthLower) && (absX <= this.pathWidthUpper) && (absZ >= this.pathWidthLower) && (absZ <= this.pathWidthUpper))) { if (this.wallfilling != 0) { for (short y = 1; y <= this.wallheight; y++) { - setBlock(w, x, y, z, this.wallfilling); + setBlock(x, y, z, this.wallfilling); } } if ((this.wall != 0) && !this.plotworld.ROAD_SCHEMATIC_ENABLED) { - setBlock(w, x, (short) (this.wallheight + 1), z, this.wall); + setBlock(x, (short) (this.wallheight + 1), z, this.wall); } } // road else { if (this.roadblock != 0) { for (short y = 1; y <= this.roadheight; y++) { - setBlock(w, x, y, z, this.roadblock); + setBlock(x, y, z, this.roadblock); } } } @@ -242,7 +227,7 @@ public class HybridPop extends BlockPopulator { final HashMap blocks = this.plotworld.G_SCH_DATA.get(loc); if (blocks != null) { for (final short y : blocks.keySet()) { - setBlock(w, x, (short) (this.roadheight + y), z, blocks.get(y)); + setBlock(x, (short) (this.roadheight + y), z, blocks.get(y)); } } } @@ -251,21 +236,12 @@ public class HybridPop extends BlockPopulator { } } - private void setBlock(final World w, final short x, final short y, final short z, final byte[] blkids) { + private void setBlock(final short x, final short y, final short z, final byte[] blkids) { if (blkids.length == 1) { - setBlock(w, x, y, z, blkids[0]); + setBlock(x, y, z, blkids[0]); } else { final int i = random(blkids.length); - setBlock(w, x, y, z, blkids[i]); + setBlock(x, y, z, blkids[i]); } } - - @SuppressWarnings("deprecation") - private void setBlock(final World w, final short x, final short y, final short z, final byte val) { - w.getBlockAt(this.X + x, y, this.Z + z).setData(val, false); - } - - public boolean isIn(final RegionWrapper plot, final int x, final int z) { - return ((x >= plot.minX) && (x <= plot.maxX) && (z >= plot.minZ) && (z <= plot.maxZ)); - } } 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 0f1a447c3..31c71d9b0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java @@ -40,10 +40,10 @@ public abstract class PlotGenerator extends ChunkGenerator { private int Z; private PseudoRandom random = new PseudoRandom(); + @SuppressWarnings("unchecked") @Override public List getDefaultPopulators(World world) { PlotSquared.loadWorld(world.getName(), this); -// world = Bukkit.getWorld(PlotSquared.GEN_WORLD); PlotWorld plotworld = PlotSquared.getPlotWorld(world.getName()); if (!plotworld.MOB_SPAWNING) { if (!plotworld.SPAWN_EGGS) { @@ -61,7 +61,7 @@ public abstract class PlotGenerator extends ChunkGenerator { world.setMonsterSpawnLimit(-1); world.setWaterAnimalSpawnLimit(-1); } - return getPopulators(world.getName()); + return (List)(List) getPopulators(world.getName()); } @Override @@ -111,6 +111,13 @@ public abstract class PlotGenerator extends ChunkGenerator { result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blkid; } + /** + * check if a region contains a location. (x, z) must be between [0,15], [0,15] + * @param plot + * @param x + * @param z + * @return + */ public boolean contains(final RegionWrapper plot, final int x, final int z) { int xx = X + x; int zz = Z + z; @@ -138,7 +145,7 @@ public abstract class PlotGenerator extends ChunkGenerator { */ 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 List getPopulators(String world); + public abstract List getPopulators(String world); public abstract void init(PlotWorld plotworld); 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 03374a4af..e50fcced3 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPopulator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotPopulator.java @@ -1,6 +1,7 @@ package com.intellectualcrafters.plot.object; import java.util.HashMap; +import java.util.HashSet; import java.util.Random; import java.util.Map.Entry; @@ -8,10 +9,15 @@ import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.generator.BlockPopulator; +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.object.schematic.PlotItem; +import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; -public abstract class PlotPopulator extends BlockPopulator{ +public abstract class PlotPopulator extends BlockPopulator { + + private PseudoRandom random = new PseudoRandom(); private int X; private int Z; @@ -22,7 +28,6 @@ public abstract class PlotPopulator extends BlockPopulator{ this.world = world; this.X = chunk.getX() << 4; this.Z = chunk.getZ() << 4; - if (ChunkManager.FORCE_PASTE) { for (short x = 0; x < 16; x++) { for (short z = 0; z < 16; z++) { @@ -35,13 +40,22 @@ public abstract class PlotPopulator extends BlockPopulator{ } return; } - + populate(world, ChunkManager.CURRENT_PLOT_CLEAR, random, X, Z); + if (ChunkManager.CURRENT_PLOT_CLEAR != null) { + PlotLoc loc; + 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()); + } + } + } } public abstract void populate(World world, RegionWrapper requiredRegion, PseudoRandom random, int cx, int cz); /** - * Set the id and data at a location (x, y, z) must be between [0,15], [0,255], [0,15] + * Set the id and data at a location. (x, y, z) must be between [0,15], [0,255], [0,15] * @param x * @param y * @param z @@ -53,7 +67,7 @@ public abstract class PlotPopulator extends BlockPopulator{ } /** - * Set the data at a location (x, y, z) must be between [0,15], [0,255], [0,15] + * Set the data at a location. (x, y, z) must be between [0,15], [0,255], [0,15] * @param x * @param y * @param z @@ -63,6 +77,13 @@ public abstract class PlotPopulator extends BlockPopulator{ world.getBlockAt(X + x, y, Z + z).setTypeId(data); } + /** + * check if a region contains a location. (x, z) must be between [0,15], [0,15] + * @param plot + * @param x + * @param z + * @return + */ public boolean contains(final RegionWrapper plot, final int x, final int z) { int xx = X + x; int zz = Z + z; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java index ee8252014..e72b90695 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/BlockManager.java @@ -43,7 +43,7 @@ public abstract class BlockManager { final byte[] data = new byte[blocks.length]; for (int i = 0; i < blocks.length; i++) { final PlotBlock[] current = blocks[i]; - final int n = PseudoRandom.random(current.length); + final int n = MainUtil.random.random(current.length); id[i] = current[n].id; data[i] = current[n].data; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index a8f8fef2a..7dc920c1c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -54,6 +54,7 @@ public class MainUtil { static long state = 1; public static HashMap lastPlot = new HashMap<>(); public static HashMap worldBorder = new HashMap<>(); + static PseudoRandom random = new PseudoRandom(); public static ArrayList getMaxPlotSelectionIds(final String world, PlotId pos1, PlotId pos2) { @@ -567,7 +568,7 @@ public class MainUtil { for (int y = pos1.getY(); y < pos2.getY(); y++) { for (int x = pos1.getX(); x < pos2.getX(); x++) { for (int z = pos1.getZ(); z < pos2.getZ(); z++) { - final int i = PseudoRandom.random(blocks.length); + final int i = random.random(blocks.length); xl[index] = x; yl[index] = y; zl[index] = z;