This commit is contained in:
boy0001 2015-03-27 18:36:28 +11:00
parent b1aa8fdd5e
commit 89f4cc7dec
6 changed files with 65 additions and 71 deletions

View File

@ -36,6 +36,7 @@ import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotLoc; import com.intellectualcrafters.plot.object.PlotLoc;
import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPopulator;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RegionWrapper;
@ -197,10 +198,10 @@ public class HybridGen extends PlotGenerator {
/** /**
* Return the block populator * Return the block populator
*/ */
public List<BlockPopulator> getPopulators(final String world) { public List<PlotPopulator> getPopulators(final String world) {
// You can have as many populators as you would like, e.g. tree // You can have as many populators as you would like, e.g. tree
// populator, ore populator // 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 * generator
*/ */
@Override @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) { if (this.doState) {
final int prime = 13; final int prime = 13;
int h = 1; 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 X = cx << 4;
final int Z = cz << 4; final int Z = cz << 4;
int sx = ((X) % this.size); int sx = ((X) % this.size);
@ -250,7 +251,7 @@ public class HybridGen extends PlotGenerator {
if (biomes != null) { if (biomes != null) {
biomes.setBiome(x, z, this.biome); 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++) { for (short y = 1; y < this.plotheight; y++) {
setBlock(this.result, x, y, z, this.filling); 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()); 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<Short, Short> blocks = ChunkManager.GENERATE_BLOCKS.get(loc);
if (blocks != null) {
for (final Entry<Short, Short> entry : blocks.entrySet()) {
setBlock(this.result, x, entry.getKey(), z, entry.getValue());
}
}
} }
} }
} }
@ -339,8 +332,4 @@ public class HybridGen extends PlotGenerator {
} }
return this.result; 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));
}
} }

View File

@ -11,7 +11,9 @@ import org.bukkit.generator.BlockPopulator;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.object.PlotLoc; import com.intellectualcrafters.plot.object.PlotLoc;
import com.intellectualcrafters.plot.object.PlotPopulator;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.schematic.PlotItem; import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
@ -20,7 +22,7 @@ import com.intellectualcrafters.plot.util.ChunkManager;
/** /**
* @author Citymonstret * @author Citymonstret
*/ */
public class HybridPop extends BlockPopulator { public class HybridPop extends PlotPopulator {
/* /*
* Sorry, this isn't well documented at the moment. * Sorry, this isn't well documented at the moment.
* We advise you to take a look at a world generation tutorial for * We advise you to take a look at a world generation tutorial for
@ -108,20 +110,11 @@ public class HybridPop extends BlockPopulator {
} }
@Override @Override
public void populate(final World w, final Random r, final Chunk c) { public void populate(World world, RegionWrapper requiredRegion, PseudoRandom random, int cx, int cz) {
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;
}
this.X = cx << 4; this.X = cx << 4;
this.Z = cz << 4; this.Z = cz << 4;
PlotSquared.getPlotManager(w.getName()); PlotSquared.getPlotManager(world.getName());
final RegionWrapper plot = ChunkManager.CURRENT_PLOT_CLEAR; if (requiredRegion != null) {
if (plot != null) {
short sx = (short) ((this.X) % this.size); short sx = (short) ((this.X) % this.size);
short sz = (short) ((this.Z) % this.size); short sz = (short) ((this.Z) % this.size);
if (sx < 0) { if (sx < 0) {
@ -132,21 +125,21 @@ public class HybridPop extends BlockPopulator {
} }
for (short x = 0; x < 16; x++) { for (short x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) { 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) { if (this.doFilling) {
for (short y = 1; y < this.plotheight; y++) { for (short y = 1; y < this.plotheight; y++) {
setBlock(w, x, y, z, this.filling); setBlock(x, y, z, this.filling);
} }
} }
if (this.doFloor) { 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) { if (this.plotworld.PLOT_SCHEMATIC) {
final PlotLoc loc = new PlotLoc((short) (this.X + x), (short) (this.Z + z)); final PlotLoc loc = new PlotLoc((short) (this.X + x), (short) (this.Z + z));
final HashMap<Short, Byte> blocks = this.plotworld.G_SCH_DATA.get(loc); final HashMap<Short, Byte> blocks = this.plotworld.G_SCH_DATA.get(loc);
if (blocks != null) { if (blocks != null) {
for (final short y : blocks.keySet()) { 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) { 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<Short, Byte> 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 (gx && gz && lx && lz) {
if (this.doFilling) { if (this.doFilling) {
for (short y = 1; y < this.plotheight; y++) { for (short y = 1; y < this.plotheight; y++) {
setBlock(w, x, y, z, this.filling); setBlock(x, y, z, this.filling);
} }
} }
if (this.doFloor) { 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) { if (this.plotworld.PLOT_SCHEMATIC) {
final PlotLoc loc = new PlotLoc(absX, absZ); final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Byte> blocks = this.plotworld.G_SCH_DATA.get(loc); final HashMap<Short, Byte> blocks = this.plotworld.G_SCH_DATA.get(loc);
if (blocks != null) { if (blocks != null) {
for (final short y : blocks.keySet()) { 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) { 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 (((absX >= this.pathWidthLower) && (absX <= this.pathWidthUpper) && (absZ >= this.pathWidthLower) && (absZ <= this.pathWidthUpper))) {
if (this.wallfilling != 0) { if (this.wallfilling != 0) {
for (short y = 1; y <= this.wallheight; y++) { 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) { 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 // road
else { else {
if (this.roadblock != 0) { if (this.roadblock != 0) {
for (short y = 1; y <= this.roadheight; y++) { 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<Short, Byte> blocks = this.plotworld.G_SCH_DATA.get(loc); final HashMap<Short, Byte> blocks = this.plotworld.G_SCH_DATA.get(loc);
if (blocks != null) { if (blocks != null) {
for (final short y : blocks.keySet()) { 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) { if (blkids.length == 1) {
setBlock(w, x, y, z, blkids[0]); setBlock(x, y, z, blkids[0]);
} else { } else {
final int i = random(blkids.length); 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));
}
} }

View File

@ -40,10 +40,10 @@ public abstract class PlotGenerator extends ChunkGenerator {
private int Z; private int Z;
private PseudoRandom random = new PseudoRandom(); private PseudoRandom random = new PseudoRandom();
@SuppressWarnings("unchecked")
@Override @Override
public List<BlockPopulator> getDefaultPopulators(World world) { public List<BlockPopulator> getDefaultPopulators(World world) {
PlotSquared.loadWorld(world.getName(), this); PlotSquared.loadWorld(world.getName(), this);
// world = Bukkit.getWorld(PlotSquared.GEN_WORLD);
PlotWorld plotworld = PlotSquared.getPlotWorld(world.getName()); PlotWorld plotworld = PlotSquared.getPlotWorld(world.getName());
if (!plotworld.MOB_SPAWNING) { if (!plotworld.MOB_SPAWNING) {
if (!plotworld.SPAWN_EGGS) { if (!plotworld.SPAWN_EGGS) {
@ -61,7 +61,7 @@ public abstract class PlotGenerator extends ChunkGenerator {
world.setMonsterSpawnLimit(-1); world.setMonsterSpawnLimit(-1);
world.setWaterAnimalSpawnLimit(-1); world.setWaterAnimalSpawnLimit(-1);
} }
return getPopulators(world.getName()); return (List<BlockPopulator>)(List<?>) getPopulators(world.getName());
} }
@Override @Override
@ -111,6 +111,13 @@ public abstract class PlotGenerator extends ChunkGenerator {
result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blkid; 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) { public boolean contains(final RegionWrapper plot, final int x, final int z) {
int xx = X + x; int xx = X + x;
int zz = Z + z; 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 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<BlockPopulator> getPopulators(String world); public abstract List<PlotPopulator> getPopulators(String world);
public abstract void init(PlotWorld plotworld); public abstract void init(PlotWorld plotworld);

View File

@ -1,6 +1,7 @@
package com.intellectualcrafters.plot.object; package com.intellectualcrafters.plot.object;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Random; import java.util.Random;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -8,10 +9,15 @@ import org.bukkit.Chunk;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.generator.BlockPopulator; 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.ChunkManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; 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 X;
private int Z; private int Z;
@ -22,7 +28,6 @@ public abstract class PlotPopulator extends BlockPopulator{
this.world = world; this.world = world;
this.X = chunk.getX() << 4; this.X = chunk.getX() << 4;
this.Z = chunk.getZ() << 4; this.Z = chunk.getZ() << 4;
if (ChunkManager.FORCE_PASTE) { if (ChunkManager.FORCE_PASTE) {
for (short x = 0; x < 16; x++) { for (short x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) { for (short z = 0; z < 16; z++) {
@ -35,13 +40,22 @@ public abstract class PlotPopulator extends BlockPopulator{
} }
return; return;
} }
populate(world, ChunkManager.CURRENT_PLOT_CLEAR, random, X, Z);
if (ChunkManager.CURRENT_PLOT_CLEAR != null) {
PlotLoc loc;
for (Entry<PlotLoc, HashMap<Short, Byte>> entry : ChunkManager.GENERATE_DATA.entrySet()) {
for (Entry<Short, Byte> 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); 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 x
* @param y * @param y
* @param z * @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 x
* @param y * @param y
* @param z * @param z
@ -63,6 +77,13 @@ public abstract class PlotPopulator extends BlockPopulator{
world.getBlockAt(X + x, y, Z + z).setTypeId(data); 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) { public boolean contains(final RegionWrapper plot, final int x, final int z) {
int xx = X + x; int xx = X + x;
int zz = Z + z; int zz = Z + z;

View File

@ -43,7 +43,7 @@ public abstract class BlockManager {
final byte[] data = new byte[blocks.length]; final byte[] data = new byte[blocks.length];
for (int i = 0; i < blocks.length; i++) { for (int i = 0; i < blocks.length; i++) {
final PlotBlock[] current = blocks[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; id[i] = current[n].id;
data[i] = current[n].data; data[i] = current[n].data;
} }

View File

@ -54,6 +54,7 @@ public class MainUtil {
static long state = 1; static long state = 1;
public static HashMap<String, PlotId> lastPlot = new HashMap<>(); public static HashMap<String, PlotId> lastPlot = new HashMap<>();
public static HashMap<String, Integer> worldBorder = new HashMap<>(); public static HashMap<String, Integer> worldBorder = new HashMap<>();
static PseudoRandom random = new PseudoRandom();
public static ArrayList<PlotId> getMaxPlotSelectionIds(final String world, PlotId pos1, PlotId pos2) { public static ArrayList<PlotId> 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 y = pos1.getY(); y < pos2.getY(); y++) {
for (int x = pos1.getX(); x < pos2.getX(); x++) { for (int x = pos1.getX(); x < pos2.getX(); x++) {
for (int z = pos1.getZ(); z < pos2.getZ(); z++) { 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; xl[index] = x;
yl[index] = y; yl[index] = y;
zl[index] = z; zl[index] = z;