This commit is contained in:
boy0001
2015-09-11 20:09:22 +10:00
parent 37a8861fa0
commit c386f33df8
380 changed files with 43490 additions and 33913 deletions

View File

@ -25,7 +25,8 @@ import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.bukkit.util.BukkitChunkManager;
import com.plotsquared.bukkit.util.BukkitSetBlockManager;
public class AugmentedPopulator extends BlockPopulator {
public class AugmentedPopulator extends BlockPopulator
{
public final PlotWorld plotworld;
public final PlotManager manager;
public final BukkitPlotGenerator generator;
@ -39,64 +40,80 @@ public class AugmentedPopulator extends BlockPopulator {
private final int tx;
private final int tz;
public AugmentedPopulator(final String world, final BukkitPlotGenerator generator, final PlotCluster cluster, final boolean p, final boolean b) {
public AugmentedPopulator(final String world, final BukkitPlotGenerator generator, final PlotCluster cluster, final boolean p, final boolean b)
{
MainUtil.initCache();
PS.log("== NEW AUGMENTED POPULATOR FOR: " + world);
this.cluster = cluster;
this.generator = generator;
this.plotworld = PS.get().getPlotWorld(world);
this.manager = generator.getPlotManager();
plotworld = PS.get().getPlotWorld(world);
manager = generator.getPlotManager();
this.p = p;
this.b = b;
this.o = (this.plotworld.TERRAIN == 1) || (this.plotworld.TERRAIN == 2);
o = (plotworld.TERRAIN == 1) || (plotworld.TERRAIN == 2);
final World bukkitWorld = Bukkit.getWorld(world);
if (cluster != null) {
final Location bl = this.manager.getPlotBottomLocAbs(this.plotworld, cluster.getP1());
final Location tl = this.manager.getPlotTopLocAbs(this.plotworld, cluster.getP2()).add(1, 0, 1);
this.bx = bl.getX();
this.bz = bl.getZ();
this.tx = tl.getX();
this.tz = tl.getZ();
} else {
this.bx = Integer.MIN_VALUE;
this.bz = Integer.MIN_VALUE;
this.tx = Integer.MAX_VALUE;
this.tz = Integer.MAX_VALUE;
if (cluster != null)
{
final Location bl = manager.getPlotBottomLocAbs(plotworld, cluster.getP1());
final Location tl = manager.getPlotTopLocAbs(plotworld, cluster.getP2()).add(1, 0, 1);
bx = bl.getX();
bz = bl.getZ();
tx = tl.getX();
tz = tl.getZ();
}
else
{
bx = Integer.MIN_VALUE;
bz = Integer.MIN_VALUE;
tx = Integer.MAX_VALUE;
tz = Integer.MAX_VALUE;
}
// Add the populator
if (this.o) {
if (o)
{
bukkitWorld.getPopulators().add(0, this);
} else {
}
else
{
bukkitWorld.getPopulators().add(this);
}
}
public static void removePopulator(final String worldname, final PlotCluster cluster) {
public static void removePopulator(final String worldname, final PlotCluster cluster)
{
final World world = Bukkit.getWorld(worldname);
for (final Iterator<BlockPopulator> iterator = world.getPopulators().iterator(); iterator.hasNext();) {
for (final Iterator<BlockPopulator> iterator = world.getPopulators().iterator(); iterator.hasNext();)
{
final BlockPopulator populator = iterator.next();
if (populator instanceof AugmentedPopulator) {
if (((AugmentedPopulator) populator).cluster.equals(cluster)) {
if (populator instanceof AugmentedPopulator)
{
if (((AugmentedPopulator) populator).cluster.equals(cluster))
{
iterator.remove();
}
}
}
}
public BlockWrapper get(final int x, final int z, final int i, final int j, final short[][] r, final boolean c) {
public BlockWrapper get(final int x, final int z, final int i, final int j, final short[][] r, final boolean c)
{
final int y = (i << 4) + (j >> 8);
final int a = (j - ((y & 0xF) << 8));
final int z1 = (a >> 4);
final int x1 = a - (z1 << 4);
if (r[i] == null) {
return (c && (((z + z1) < this.bz) || ((z + z1) > this.tz) || ((x + x1) < this.bx) || ((x + x1) > this.tx))) ? null : new BlockWrapper(x1, y, z1, (short) 0, (byte) 0);
} else {
return (c && (((z + z1) < this.bz) || ((z + z1) > this.tz) || ((x + x1) < this.bx) || ((x + x1) > this.tx))) ? null : new BlockWrapper(x1, y, z1, r[i][j], (byte) 0);
if (r[i] == null)
{
return (c && (((z + z1) < bz) || ((z + z1) > tz) || ((x + x1) < bx) || ((x + x1) > tx))) ? null : new BlockWrapper(x1, y, z1, (short) 0, (byte) 0);
}
else
{
return (c && (((z + z1) < bz) || ((z + z1) > tz) || ((x + x1) < bx) || ((x + x1) > tx))) ? null : new BlockWrapper(x1, y, z1, r[i][j], (byte) 0);
}
}
@Override
public void populate(final World world, final Random rand, final Chunk chunk) {
public void populate(final World world, final Random rand, final Chunk chunk)
{
final int cx = chunk.getX();
final int cz = chunk.getZ();
final int bx = cx << 4;
@ -109,25 +126,30 @@ public class AugmentedPopulator extends BlockPopulator {
final boolean inZ2 = ((tz >= this.bz) && (tz <= this.tz));
final boolean inX = inX1 || inX2;
final boolean inZ = inZ1 || inZ2;
if (!inX || !inZ) {
return;
}
if (this.plotworld.TERRAIN == 3) {
int X = chunk.getX() << 4;
int Z = chunk.getZ() << 4;
if (ChunkManager.FORCE_PASTE) {
for (short x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) {
if (!inX || !inZ) { return; }
if (plotworld.TERRAIN == 3)
{
final int X = chunk.getX() << 4;
final int Z = chunk.getZ() << 4;
if (ChunkManager.FORCE_PASTE)
{
for (short x = 0; x < 16; x++)
{
for (short z = 0; z < 16; z++)
{
final PlotLoc loc = new PlotLoc((short) (X + x), (short) (Z + z));
final HashMap<Short, Short> blocks = ChunkManager.GENERATE_BLOCKS.get(loc);
HashMap<Short, Byte> datas = ChunkManager.GENERATE_DATA.get(loc);
for (final Entry<Short, Short> entry : blocks.entrySet()) {
int y = entry.getKey();
final HashMap<Short, Byte> datas = ChunkManager.GENERATE_DATA.get(loc);
for (final Entry<Short, Short> entry : blocks.entrySet())
{
final int y = entry.getKey();
byte data;
if (datas != null) {
if (datas != null)
{
data = datas.get(y);
}
else {
else
{
data = 0;
}
BukkitSetBlockManager.setBlockManager.set(world, x, y, z, blocks.get(y), data);
@ -136,24 +158,31 @@ public class AugmentedPopulator extends BlockPopulator {
}
return;
}
if (ChunkManager.CURRENT_PLOT_CLEAR != null) {
if (ChunkManager.CURRENT_PLOT_CLEAR != null)
{
PlotLoc loc;
for (Entry<PlotLoc, HashMap<Short, Byte>> entry : ChunkManager.GENERATE_DATA.entrySet()) {
HashMap<Short, Byte> datas = ChunkManager.GENERATE_DATA.get(entry.getKey());
for (Entry<Short, Byte> entry2 : entry.getValue().entrySet()) {
Short y = entry2.getKey();
for (final Entry<PlotLoc, HashMap<Short, Byte>> entry : ChunkManager.GENERATE_DATA.entrySet())
{
final HashMap<Short, Byte> datas = ChunkManager.GENERATE_DATA.get(entry.getKey());
for (final Entry<Short, Byte> entry2 : entry.getValue().entrySet())
{
final Short y = entry2.getKey();
byte data;
if (datas != null) {
if (datas != null)
{
data = datas.get(y);
}
else {
else
{
data = 0;
}
loc = entry.getKey();
int xx = loc.x - X;
int zz = loc.z - Z;
if (xx >= 0 && xx < 16) {
if (zz >= 0 && zz < 16) {
final int xx = loc.x - X;
final int zz = loc.z - Z;
if ((xx >= 0) && (xx < 16))
{
if ((zz >= 0) && (zz < 16))
{
BukkitSetBlockManager.setBlockManager.set(world, xx, y, zz, entry2.getValue(), data);
}
}
@ -164,25 +193,31 @@ public class AugmentedPopulator extends BlockPopulator {
}
final boolean check;
check = !inX1 || !inX2 || !inZ1 || !inZ2;
if (this.plotworld.TERRAIN > 1) {
final PlotId plot1 = this.manager.getPlotIdAbs(this.plotworld, bx, 0, bz);
final PlotId plot2 = this.manager.getPlotIdAbs(this.plotworld, tx, 0, tz);
if ((plot1 != null) && (plot2 != null) && plot1.equals(plot2)) {
return;
}
if (plotworld.TERRAIN > 1)
{
final PlotId plot1 = manager.getPlotIdAbs(plotworld, bx, 0, bz);
final PlotId plot2 = manager.getPlotIdAbs(plotworld, tx, 0, tz);
if ((plot1 != null) && (plot2 != null) && plot1.equals(plot2)) { return; }
}
if (this.o) {
if (o)
{
populateBlocks(world, rand, cx, cz, bx, bz, check);
} else {
TaskManager.runTaskLater(new Runnable() {
}
else
{
TaskManager.runTaskLater(new Runnable()
{
@Override
public void run() {
public void run()
{
populateBiome(world, bx, bz);
}
}, 20 + rand.nextInt(10));
TaskManager.runTaskLater(new Runnable() {
TaskManager.runTaskLater(new Runnable()
{
@Override
public void run() {
public void run()
{
chunk.load(true);
populateBlocks(world, rand, cx, cz, bx, bz, check);
}
@ -190,61 +225,86 @@ public class AugmentedPopulator extends BlockPopulator {
}
}
private void populateBiome(final World world, final int x, final int z) {
final Biome biome = Biome.valueOf(this.plotworld.PLOT_BIOME);
if (this.b) {
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
private void populateBiome(final World world, final int x, final int z)
{
final Biome biome = Biome.valueOf(plotworld.PLOT_BIOME);
if (b)
{
for (int i = 0; i < 16; i++)
{
for (int j = 0; j < 16; j++)
{
world.setBiome(x + i, z + j, biome);
}
}
}
}
private void populateBlocks(final World world, final Random rand, final int X, final int Z, final int x, final int z, final boolean check) {
final short[][] result = this.generator.generateExtBlockSections(world, rand, X, Z, null);
for (int i = 0; i < result.length; i++) {
if (result[i] != null) {
for (int j = 0; j < 4096; j++) {
int x1 = MainUtil.x_loc[i][j];
int y = MainUtil.y_loc[i][j];
int z1 = MainUtil.z_loc[i][j];
short id = result[i][j];
private void populateBlocks(final World world, final Random rand, final int X, final int Z, final int x, final int z, final boolean check)
{
final short[][] result = generator.generateExtBlockSections(world, rand, X, Z, null);
for (int i = 0; i < result.length; i++)
{
if (result[i] != null)
{
for (int j = 0; j < 4096; j++)
{
final int x1 = MainUtil.x_loc[i][j];
final int y = MainUtil.y_loc[i][j];
final int z1 = MainUtil.z_loc[i][j];
final short id = result[i][j];
final int xx = x + x1;
final int zz = z + z1;
if (check && (((zz) < this.bz) || ((zz) > this.tz) || ((xx) < this.bx) || ((xx) > this.tx))) {
if (check && (((zz) < bz) || ((zz) > tz) || ((xx) < bx) || ((xx) > tx)))
{
continue;
}
if (this.p) {
if (ChunkManager.CURRENT_PLOT_CLEAR != null) {
if (BukkitChunkManager.isIn(ChunkManager.CURRENT_PLOT_CLEAR, xx, zz)) {
if (p)
{
if (ChunkManager.CURRENT_PLOT_CLEAR != null)
{
if (BukkitChunkManager.isIn(ChunkManager.CURRENT_PLOT_CLEAR, xx, zz))
{
continue;
}
} else if (this.manager.getPlotIdAbs(this.plotworld, xx, 0, zz) != null) {
}
else if (manager.getPlotIdAbs(plotworld, xx, 0, zz) != null)
{
continue;
}
}
BukkitSetBlockManager.setBlockManager.set(world, xx, y, zz, id, (byte) 0);
}
}
else {
short y_min = MainUtil.y_loc[i][0];
if (y_min < 128) {
for (int x1 = x; x1 < x + 16; x1++) {
for (int z1 = z; z1 < z + 16; z1++) {
if (check && (((z1) < this.bz) || ((z1) > this.tz) || ((x1) < this.bx) || ((x1) > this.tx))) {
else
{
final short y_min = MainUtil.y_loc[i][0];
if (y_min < 128)
{
for (int x1 = x; x1 < (x + 16); x1++)
{
for (int z1 = z; z1 < (z + 16); z1++)
{
if (check && (((z1) < bz) || ((z1) > tz) || ((x1) < bx) || ((x1) > tx)))
{
continue;
}
if (this.p) {
if (ChunkManager.CURRENT_PLOT_CLEAR != null) {
if (BukkitChunkManager.isIn(ChunkManager.CURRENT_PLOT_CLEAR, x1, z1)) {
if (p)
{
if (ChunkManager.CURRENT_PLOT_CLEAR != null)
{
if (BukkitChunkManager.isIn(ChunkManager.CURRENT_PLOT_CLEAR, x1, z1))
{
continue;
}
} else if (this.manager.getPlotIdAbs(this.plotworld, x1, 0, z1) != null) {
}
else if (manager.getPlotIdAbs(plotworld, x1, 0, z1) != null)
{
continue;
}
}
for (int y = y_min; y < y_min + 16; y++) {
for (int y = y_min; y < (y_min + 16); y++)
{
BukkitSetBlockManager.setBlockManager.set(world, x1, y, z1, 0, (byte) 0);
}
}
@ -252,9 +312,10 @@ public class AugmentedPopulator extends BlockPopulator {
}
}
}
for (final BlockPopulator populator : this.generator.getPopulators(world.getName())) {
Chunk chunk = world.getChunkAt(X, Z);
populator.populate(world, this.r, chunk);
for (final BlockPopulator populator : generator.getPopulators(world.getName()))
{
final Chunk chunk = world.getChunkAt(X, Z);
populator.populate(world, r, chunk);
}
}
}

View File

@ -9,81 +9,94 @@ import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.SetupObject;
public class BukkitGeneratorWrapper extends PlotGenerator<ChunkGenerator> {
public class BukkitGeneratorWrapper extends PlotGenerator<ChunkGenerator>
{
public final boolean full;
public BukkitGeneratorWrapper(String world, ChunkGenerator generator) {
public BukkitGeneratorWrapper(final String world, final ChunkGenerator generator)
{
super(world, generator);
full = (generator instanceof BukkitPlotGenerator);
}
@Override
public void initialize(PlotWorld plotworld) {
if (generator instanceof BukkitPlotGenerator) {
public void initialize(final PlotWorld plotworld)
{
if (generator instanceof BukkitPlotGenerator)
{
((BukkitPlotGenerator) generator).init(plotworld);
}
}
@Override
public void augment(PlotCluster cluster, PlotWorld plotworld) {
if (generator instanceof BukkitPlotGenerator) {
BukkitPlotGenerator plotgen = (BukkitPlotGenerator) generator;
if (cluster != null) {
public void augment(final PlotCluster cluster, final PlotWorld plotworld)
{
if (generator instanceof BukkitPlotGenerator)
{
final BukkitPlotGenerator plotgen = (BukkitPlotGenerator) generator;
if (cluster != null)
{
new AugmentedPopulator(world, plotgen, cluster, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
}
else {
else
{
new AugmentedPopulator(world, plotgen, null, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
}
}
}
@Override
public void setGenerator(String gen_string) {
if (gen_string == null) {
public void setGenerator(final String gen_string)
{
if (gen_string == null)
{
generator = new HybridGen(world);
} else {
PlotGenerator<ChunkGenerator> gen_wrapper = (PlotGenerator<ChunkGenerator>) PS.get().IMP.getGenerator(world, gen_string);
if (gen_wrapper != null) {
}
else
{
final PlotGenerator<ChunkGenerator> gen_wrapper = (PlotGenerator<ChunkGenerator>) PS.get().IMP.getGenerator(world, gen_string);
if (gen_wrapper != null)
{
generator = gen_wrapper.generator;
}
}
}
@Override
public PlotWorld getNewPlotWorld(String world) {
if (!(generator instanceof BukkitPlotGenerator)) {
return null;
}
public PlotWorld getNewPlotWorld(final String world)
{
if (!(generator instanceof BukkitPlotGenerator)) { return null; }
return ((BukkitPlotGenerator) generator).getNewPlotWorld(world);
}
@Override
public PlotManager getPlotManager() {
if (!(generator instanceof BukkitPlotGenerator)) {
return null;
}
public PlotManager getPlotManager()
{
if (!(generator instanceof BukkitPlotGenerator)) { return null; }
return ((BukkitPlotGenerator) generator).getPlotManager();
}
@Override
public boolean isFull() {
public boolean isFull()
{
return full;
}
@Override
public String getName() {
if (generator == null) {
return "Null";
}
public String getName()
{
if (generator == null) { return "Null"; }
return generator.getClass().getName();
}
@Override
public void processSetup(SetupObject object) {
if (generator instanceof BukkitPlotGenerator) {
public void processSetup(final SetupObject object)
{
if (generator instanceof BukkitPlotGenerator)
{
((BukkitPlotGenerator) generator).processSetup(object);
}
}
}

View File

@ -41,7 +41,8 @@ import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.plotsquared.bukkit.listeners.WorldEvents;
public abstract class BukkitPlotGenerator extends ChunkGenerator {
public abstract class BukkitPlotGenerator extends ChunkGenerator
{
public static short[][][] CACHE_I = null;
public static short[][][] CACHE_J = null;
@ -49,22 +50,28 @@ public abstract class BukkitPlotGenerator extends ChunkGenerator {
public int Z;
private boolean loaded = false;
private short[][] result;
private PseudoRandom random = new PseudoRandom();
public BukkitPlotGenerator(String world) {
private final PseudoRandom random = new PseudoRandom();
public BukkitPlotGenerator(final String world)
{
WorldEvents.lastWorld = world;
initCache();
}
public void initCache() {
if (CACHE_I == null) {
public void initCache()
{
if (CACHE_I == null)
{
CACHE_I = new short[256][16][16];
CACHE_J = new short[256][16][16];
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
for (int y = 0; y < 256; y++) {
short i = (short) (y >> 4);
short j = (short) (((y & 0xF) << 8) | (z << 4) | x);
for (int x = 0; x < 16; x++)
{
for (int z = 0; z < 16; z++)
{
for (int y = 0; y < 256; y++)
{
final short i = (short) (y >> 4);
final short j = (short) (((y & 0xF) << 8) | (z << 4) | x);
CACHE_I[y][x][z] = i;
CACHE_J[y][x][z] = j;
}
@ -75,14 +82,19 @@ public abstract class BukkitPlotGenerator extends ChunkGenerator {
@SuppressWarnings("unchecked")
@Override
public List<BlockPopulator> getDefaultPopulators(World world) {
try {
if (!loaded) {
String name = WorldEvents.getName(world);
public List<BlockPopulator> getDefaultPopulators(final World world)
{
try
{
if (!loaded)
{
final String name = WorldEvents.getName(world);
PS.get().loadWorld(name, new BukkitGeneratorWrapper(name, this));
PlotWorld plotworld = PS.get().getPlotWorld(WorldEvents.getName(world));
if (!plotworld.MOB_SPAWNING) {
if (!plotworld.SPAWN_EGGS) {
final PlotWorld plotworld = PS.get().getPlotWorld(WorldEvents.getName(world));
if (!plotworld.MOB_SPAWNING)
{
if (!plotworld.SPAWN_EGGS)
{
world.setSpawnFlags(false, false);
}
world.setAmbientSpawnLimit(0);
@ -90,7 +102,8 @@ public abstract class BukkitPlotGenerator extends ChunkGenerator {
world.setMonsterSpawnLimit(0);
world.setWaterAnimalSpawnLimit(0);
}
else {
else
{
world.setSpawnFlags(true, true);
world.setAmbientSpawnLimit(-1);
world.setAnimalSpawnLimit(-1);
@ -98,28 +111,33 @@ public abstract class BukkitPlotGenerator extends ChunkGenerator {
world.setWaterAnimalSpawnLimit(-1);
}
loaded = true;
return (List<BlockPopulator>)(List<?>) getPopulators(WorldEvents.getName(world));
return (List<BlockPopulator>) (List<?>) getPopulators(WorldEvents.getName(world));
}
}
catch (Exception e) {
catch (final Exception e)
{
e.printStackTrace();
}
return new ArrayList<BlockPopulator>();
}
/**
* Set the result;
* @param result
*/
public void setResult(short[][] result) {
public void setResult(final short[][] result)
{
this.result = result;
}
@Override
public short[][] generateExtBlockSections(World world, Random r, int cx, int cz, BiomeGrid biomes) {
try {
if (!loaded) {
String name = WorldEvents.getName(world);
public short[][] generateExtBlockSections(final World world, final Random r, final int cx, final int cz, final BiomeGrid biomes)
{
try
{
if (!loaded)
{
final String name = WorldEvents.getName(world);
PS.get().loadWorld(name, new BukkitGeneratorWrapper(name, this));
loaded = true;
}
@ -127,37 +145,47 @@ public abstract class BukkitPlotGenerator extends ChunkGenerator {
int h = 1;
h = (prime * h) + cx;
h = (prime * h) + cz;
this.random.state = h;
this.result = new short[16][];
this.X = cx << 4;
this.Z = cz << 4;
if (ChunkManager.FORCE_PASTE) {
PlotWorld plotworld = PS.get().getPlotWorld(world.getName());
Biome biome = Biome.valueOf(plotworld.PLOT_BIOME);
for (short x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) {
if (biomes != null) {
random.state = h;
result = new short[16][];
X = cx << 4;
Z = cz << 4;
if (ChunkManager.FORCE_PASTE)
{
final PlotWorld plotworld = PS.get().getPlotWorld(world.getName());
final Biome biome = Biome.valueOf(plotworld.PLOT_BIOME);
for (short x = 0; x < 16; x++)
{
for (short z = 0; z < 16; z++)
{
if (biomes != null)
{
biomes.setBiome(x, z, biome);
}
final PlotLoc loc = new PlotLoc((X + x), (Z + z));
final HashMap<Short, Short> blocks = ChunkManager.GENERATE_BLOCKS.get(loc);
for (final Entry<Short, Short> entry : blocks.entrySet()) {
for (final Entry<Short, Short> entry : blocks.entrySet())
{
setBlock(x, entry.getKey(), z, entry.getValue());
}
}
}
return this.result;
return result;
}
generateChunk(world, ChunkManager.CURRENT_PLOT_CLEAR, random, cx, cz, biomes);
if (ChunkManager.CURRENT_PLOT_CLEAR != null) {
if (ChunkManager.CURRENT_PLOT_CLEAR != null)
{
PlotLoc loc;
for (Entry<PlotLoc, HashMap<Short, Short>> entry : ChunkManager.GENERATE_BLOCKS.entrySet()) {
for (Entry<Short, Short> entry2 : entry.getValue().entrySet()) {
for (final Entry<PlotLoc, HashMap<Short, Short>> entry : ChunkManager.GENERATE_BLOCKS.entrySet())
{
for (final Entry<Short, Short> entry2 : entry.getValue().entrySet())
{
loc = entry.getKey();
int xx = loc.x - X;
int zz = loc.z - Z;
if (xx >= 0 && xx < 16) {
if (zz >= 0 && zz < 16) {
final int xx = loc.x - X;
final int zz = loc.z - Z;
if ((xx >= 0) && (xx < 16))
{
if ((zz >= 0) && (zz < 16))
{
setBlock(xx, entry2.getKey(), zz, entry2.getValue());
}
}
@ -165,30 +193,36 @@ public abstract class BukkitPlotGenerator extends ChunkGenerator {
}
}
}
catch (Exception e) {
catch (final Exception e)
{
e.printStackTrace();
}
return result;
}
public void setBlock(final int x, final int y, final int z, final short blkid) {
if (result[CACHE_I[y][x][z]] == null) {
public void setBlock(final int x, final int y, final int z, final short blkid)
{
if (result[CACHE_I[y][x][z]] == null)
{
result[CACHE_I[y][x][z]] = new short[4096];
}
result[CACHE_I[y][x][z]][CACHE_J[y][x][z]] = blkid;
}
public void setBlock(final int x, final int y, final int z, final short[] blkid) {
if (blkid.length == 1) {
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[CACHE_I[y][x][z]] == null) {
final short id = blkid[random.random(blkid.length)];
if (result[CACHE_I[y][x][z]] == null)
{
result[CACHE_I[y][x][z]] = new short[4096];
}
result[CACHE_I[y][x][z]][CACHE_J[y][x][z]] = id;
}
/**
* check if a region contains a location. (x, z) must be between [0,15], [0,15]
* @param plot
@ -196,22 +230,24 @@ public abstract class BukkitPlotGenerator extends ChunkGenerator {
* @param z
* @return
*/
public boolean contains(final RegionWrapper plot, final int x, final int z) {
int xx = X + x;
int zz = Z + z;
public boolean contains(final RegionWrapper plot, final int x, final int z)
{
final int xx = X + x;
final int zz = Z + z;
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) {
public boolean canSpawn(final World world, final int x, final int z)
{
return true;
}
/**
* <b>random</b> is an optimized random number generator.<br>
* <b>random</b> is an optimized random number generator.<br>
* - Change the state to have the same chunk random each time it generates<br>
* <b>requiredRegion</b> If a plot is being regenerated, you are only required to generate content in this area<br>
* - use the contains(RegionWrapper, x, z) method to check if the region contains a location<br>
@ -219,7 +255,7 @@ public abstract class BukkitPlotGenerator extends ChunkGenerator {
* - will be null if no restrictions are set<br>
* <b>result</b> is the standard 2D block data array used for generation<br>
* <b>biomes</b> is the standard BiomeGrid used for generation
*
*
* @param world
* @param random
* @param cx
@ -229,19 +265,19 @@ public abstract class BukkitPlotGenerator extends ChunkGenerator {
* @param result
* @return
*/
public abstract void generateChunk(final World world, RegionWrapper requiredRegion, final PseudoRandom random, final int cx, final int cz, final BiomeGrid biomes);
public abstract List<BukkitPlotPopulator> getPopulators(String world);
public abstract void generateChunk(final World world, final RegionWrapper requiredRegion, final PseudoRandom random, final int cx, final int cz, final BiomeGrid biomes);
public abstract List<BukkitPlotPopulator> getPopulators(final String world);
/**
* This is called when the generator is initialized.
* This is called when the generator is initialized.
* You don't need to do anything with it necessarily.
* @param plotworld
*/
public abstract void init(PlotWorld plotworld);
public abstract void init(final PlotWorld plotworld);
/**
* Return a new instance of the PlotWorld for a world
* Return a new instance of the PlotWorld for a world
* @param world
* @return
*/
@ -252,13 +288,13 @@ public abstract class BukkitPlotGenerator extends ChunkGenerator {
* @return
*/
public abstract PlotManager getPlotManager();
/**
* If you need to do anything fancy for /plot setup<br>
* - Otherwise it will just use the PlotWorld configuration<br>
* Feel free to extend BukkitSetupUtils and customize world creation
* @param object
*/
public void processSetup(SetupObject object) {
}
public void processSetup(final SetupObject object)
{}
}

View File

@ -15,28 +15,33 @@ import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.SetBlockQueue;
public abstract class BukkitPlotPopulator extends BlockPopulator {
private PseudoRandom random = new PseudoRandom();
public abstract class BukkitPlotPopulator extends BlockPopulator
{
private final PseudoRandom random = new PseudoRandom();
public int X;
public int Z;
public String worldname;
private World world;
@Override
public void populate(World world, Random rand, Chunk chunk) {
public void populate(final World world, final Random rand, final Chunk chunk)
{
this.world = world;
this.worldname = world.getName();
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++) {
worldname = world.getName();
X = chunk.getX() << 4;
Z = chunk.getZ() << 4;
if (ChunkManager.FORCE_PASTE)
{
for (short x = 0; x < 16; x++)
{
for (short z = 0; z < 16; z++)
{
final PlotLoc loc = new PlotLoc((short) (X + x), (short) (Z + z));
final HashMap<Short, Byte> blocks = ChunkManager.GENERATE_DATA.get(loc);
for (final Entry<Short, Byte> entry : blocks.entrySet()) {
for (final Entry<Short, Byte> entry : blocks.entrySet())
{
setBlock(x, entry.getKey(), z, entry.getValue());
}
}
@ -44,25 +49,30 @@ public abstract class BukkitPlotPopulator extends BlockPopulator {
return;
}
populate(world, ChunkManager.CURRENT_PLOT_CLEAR, random, X, Z);
if (ChunkManager.CURRENT_PLOT_CLEAR != null) {
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()) {
for (final Entry<PlotLoc, HashMap<Short, Byte>> entry : ChunkManager.GENERATE_DATA.entrySet())
{
for (final Entry<Short, Byte> entry2 : entry.getValue().entrySet())
{
loc = entry.getKey();
int xx = loc.x - X;
int zz = loc.z - Z;
if (xx >= 0 && xx < 16) {
if (zz >= 0 && zz < 16) {
setBlock(xx, entry2.getKey(), zz, entry2.getValue());
}
final int xx = loc.x - X;
final int zz = loc.z - Z;
if ((xx >= 0) && (xx < 16))
{
if ((zz >= 0) && (zz < 16))
{
setBlock(xx, entry2.getKey(), zz, entry2.getValue());
}
}
}
}
}
}
public abstract void populate(World world, RegionWrapper requiredRegion, PseudoRandom random, int cx, int cz);
public abstract void populate(final World world, final RegionWrapper requiredRegion, final PseudoRandom random, final int cx, final int cz);
/**
* Set the id and data at a location. (x, y, z) must be between [0,15], [0,255], [0,15]
* @param x
@ -71,15 +81,18 @@ public abstract class BukkitPlotPopulator extends BlockPopulator {
* @param id
* @param data
*/
public void setBlock(int x, int y, int z, short id, byte data) {
if (data == 0) {
public void setBlock(final int x, final int y, final int z, final short id, final byte data)
{
if (data == 0)
{
SetBlockQueue.setBlock(worldname, x, y, z, id);
}
else {
else
{
SetBlockQueue.setBlock(worldname, x, y, z, new PlotBlock(id, data));
}
}
/**
* Set the data at a location. (x, y, z) must be between [0,15], [0,255], [0,15]
* @param x
@ -87,12 +100,14 @@ public abstract class BukkitPlotPopulator extends BlockPopulator {
* @param z
* @param data
*/
public void setBlock(int x, int y, int z, byte data) {
if (data != 0) {
public void setBlock(final int x, final int y, final int z, final byte data)
{
if (data != 0)
{
world.getBlockAt(X + x, y, Z + z).setData(data);
}
}
/**
* Like setblock, but lacks the data != 0 check
* @param x
@ -100,10 +115,11 @@ public abstract class BukkitPlotPopulator extends BlockPopulator {
* @param z
* @param data
*/
public void setBlockAbs(int x, int y, int z, byte data) {
public void setBlockAbs(final int x, final int y, final int z, final byte data)
{
world.getBlockAt(X + x, y, Z + z).setData(data);
}
/**
* check if a region contains a location. (x, z) must be between [0,15], [0,15]
* @param plot
@ -111,10 +127,11 @@ public abstract class BukkitPlotPopulator extends BlockPopulator {
* @param z
* @return
*/
public boolean contains(final RegionWrapper plot, final int x, final int z) {
int xx = X + x;
int zz = Z + z;
public boolean contains(final RegionWrapper plot, final int x, final int z)
{
final int xx = X + x;
final int zz = Z + z;
return ((xx >= plot.minX) && (xx <= plot.maxX) && (zz >= plot.minZ) && (zz <= plot.maxZ));
}
}

View File

@ -1,294 +1,358 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.plotsquared.bukkit.generator;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.block.Biome;
import com.intellectualcrafters.plot.generator.HybridPlotManager;
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
import com.intellectualcrafters.plot.object.PlotLoc;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.object.RegionWrapper;
/**
* The default generator is very messy, as we have decided to try externalize all calculations from within the loop. -
* You will see a lot of slower implementations have a single for loop. - This is perfectly fine to do, it will just
* mean world generation may take somewhat longer
*
* @author Citymonstret
* @author Empire92
*/
public class HybridGen extends BukkitPlotGenerator {
public HybridGen(String world) {
super(world);
}
/**
* Set to static to re-use the same managet for all Default World Generators
*/
private static PlotManager manager = null;
/**
* plotworld object
*/
public HybridPlotWorld plotworld = null;
/**
* Some generator specific variables (implementation dependent)
*/
int plotsize;
int pathsize;
short wall;
short wallfilling;
short roadblock;
int size;
Biome biome;
int roadheight;
int wallheight;
int plotheight;
short[] plotfloors;
short[] filling;
short pathWidthLower;
short pathWidthUpper;
boolean doState = false;
int maxY = 0;
short[][] cached;
/**
* Initialize variables, and create plotworld object used in calculations
*/
public void init(PlotWorld plotworld) {
if (plotworld != null) {
this.plotworld = (HybridPlotWorld) plotworld;
}
this.plotsize = this.plotworld.PLOT_WIDTH;
this.pathsize = this.plotworld.ROAD_WIDTH;
this.roadblock = this.plotworld.ROAD_BLOCK.id;
this.wallfilling = this.plotworld.WALL_FILLING.id;
this.size = this.pathsize + this.plotsize;
this.wall = this.plotworld.WALL_BLOCK.id;
this.plotfloors = new short[this.plotworld.TOP_BLOCK.length];
for (int i = 0; i < this.plotworld.TOP_BLOCK.length; i++) {
this.plotfloors[i] = this.plotworld.TOP_BLOCK[i].id;
}
this.filling = new short[this.plotworld.MAIN_BLOCK.length];
for (int i = 0; i < this.plotworld.MAIN_BLOCK.length; i++) {
this.filling[i] = this.plotworld.MAIN_BLOCK[i].id;
}
if ((this.filling.length > 1) || (this.plotfloors.length > 1)) {
this.doState = true;
}
this.wallheight = this.plotworld.WALL_HEIGHT;
this.roadheight = this.plotworld.ROAD_HEIGHT;
this.plotheight = this.plotworld.PLOT_HEIGHT;
if (this.pathsize == 0) {
this.pathWidthLower = (short) -1;
this.pathWidthUpper = (short) (this.plotsize + 1);
}
else {
if ((this.pathsize % 2) == 0) {
this.pathWidthLower = (short) (Math.floor(this.pathsize / 2) - 1);
} else {
this.pathWidthLower = (short) (Math.floor(this.pathsize / 2));
}
this.pathWidthUpper = (short) (this.pathWidthLower + this.plotsize + 1);
}
this.biome = Biome.valueOf(this.plotworld.PLOT_BIOME);
try {
this.maxY = Bukkit.getWorld(plotworld.worldname).getMaxHeight();
} catch (final NullPointerException e) {}
if (this.maxY == 0) {
this.maxY = 256;
}
// create cached chunk (for optimized chunk generation)
if (!this.plotworld.PLOT_SCHEMATIC) {
this.cached = new short[(plotheight + 16) / 16][];
for (int i = 0; i < cached.length; i++) {
cached[i] = new short[4096];
}
PseudoRandom random = new PseudoRandom();
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
cached[CACHE_I[plotheight][x][z]][CACHE_J[plotheight][x][z]] = plotfloors[random.random(plotfloors.length)];
if (this.plotworld.PLOT_BEDROCK) {
cached[CACHE_I[0][x][z]][CACHE_J[0][x][z]] = 7;
}
for (int y = 1; y < plotheight; y++) {
cached[CACHE_I[y][x][z]][CACHE_J[y][x][z]] = filling[random.random(filling.length)];
}
}
}
}
}
/**
* 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
*/
public PlotManager getPlotManager() {
if (HybridGen.manager == null) {
HybridGen.manager = new HybridPlotManager();
}
return HybridGen.manager;
}
/**
* Get a new plotworld class For square plots you can use the DefaultPlotWorld class which comes with PlotSquared
*/
public PlotWorld getNewPlotWorld(final String world) {
if (this.plotworld == null) {
this.plotworld = new HybridPlotWorld(world);
}
return this.plotworld;
}
/**
* Return the block populator
*/
public List<BukkitPlotPopulator> getPopulators(final String world) {
// You can have as many populators as you would like, e.g. tree
// populator, ore populator
return Arrays.asList((BukkitPlotPopulator) new HybridPop(this.plotworld));
}
/**
* This part is a fucking mess. - Refer to a proper tutorial if you would like to learn how to make a world
* generator
*/
public void generateChunk(final World world, RegionWrapper region, final PseudoRandom random, final int cx, final int cz, final BiomeGrid biomes) {
int sx = (short) ((this.X - this.plotworld.ROAD_OFFSET_X) % this.size);
int sz = (short) ((this.Z - this.plotworld.ROAD_OFFSET_Z) % this.size);
if (sx < 0) {
sx += this.size;
}
if (sz < 0) {
sz += this.size;
}
if (biomes != null) {
for (short x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) {
biomes.setBiome(x, z, this.biome);
}
}
}
if (cached != null) {
if (sx > pathWidthLower && sz > pathWidthLower && sx + 15 < pathWidthUpper&& sz + 15 < pathWidthUpper) {
setResult(cached);
return;
}
}
if (this.plotworld.PLOT_BEDROCK) {
for (short x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) {
setBlock(x, 0, z, (short) 7);
}
}
}
if (region != null) {
for (short x = 0; x < 16; x++) {
final int absX = ((sx + x) % this.size);
for (short z = 0; z < 16; z++) {
if (contains(region, x, z)) {
for (short y = 1; y < this.plotheight; y++) {
setBlock(x, y, z, this.filling);
}
setBlock(x, this.plotheight, z, this.plotfloors);
final int absZ = ((sz + z) % this.size);
final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Short> blocks = plotworld.G_SCH.get(loc);
if (blocks != null) {
for (final Entry<Short, Short> entry : blocks.entrySet()) {
setBlock(x, this.plotheight + entry.getKey(), z, entry.getValue());
}
}
}
}
}
return;
}
for (short x = 0; x < 16; x++) {
final int absX = ((sx + x) % this.size);
final boolean gx = absX > this.pathWidthLower;
final boolean lx = absX < this.pathWidthUpper;
for (short z = 0; z < 16; z++) {
final int absZ = ((sz + z) % this.size);
final boolean gz = absZ > this.pathWidthLower;
final boolean lz = absZ < this.pathWidthUpper;
// inside plot
if (gx && gz && lx && lz) {
for (short y = 1; y < this.plotheight; y++) {
setBlock(x, y, z, this.filling);
}
setBlock(x, this.plotheight, z, this.plotfloors);
if (this.plotworld.PLOT_SCHEMATIC) {
final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Short> blocks = this.plotworld.G_SCH.get(loc);
if (blocks != null) {
for (final Entry<Short, Short> entry : blocks.entrySet()) {
setBlock(x, this.plotheight + entry.getKey(), z, entry.getValue());
}
}
}
} else if (pathsize != 0) {
// wall
if (((absX >= this.pathWidthLower) && (absX <= this.pathWidthUpper) && (absZ >= this.pathWidthLower) && (absZ <= this.pathWidthUpper))) {
for (short y = 1; y <= this.wallheight; y++) {
setBlock(x, y, z, this.wallfilling);
}
if (!this.plotworld.ROAD_SCHEMATIC_ENABLED) {
setBlock(x, this.wallheight + 1, z, this.wall);
}
}
// road
else {
for (short y = 1; y <= this.roadheight; y++) {
setBlock(x, y, z, this.roadblock);
}
}
if (this.plotworld.ROAD_SCHEMATIC_ENABLED) {
final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Short> blocks = this.plotworld.G_SCH.get(loc);
if (blocks != null) {
for (final Entry<Short, Short> entry : blocks.entrySet()) {
setBlock(x, this.roadheight + entry.getKey(), z, entry.getValue());
}
}
}
}
}
}
return;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.plotsquared.bukkit.generator;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.block.Biome;
import com.intellectualcrafters.plot.generator.HybridPlotManager;
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
import com.intellectualcrafters.plot.object.PlotLoc;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.object.RegionWrapper;
/**
* The default generator is very messy, as we have decided to try externalize all calculations from within the loop. -
* You will see a lot of slower implementations have a single for loop. - This is perfectly fine to do, it will just
* mean world generation may take somewhat longer
*
*/
public class HybridGen extends BukkitPlotGenerator
{
public HybridGen(final String world)
{
super(world);
}
/**
* Set to static to re-use the same managet for all Default World Generators
*/
private static PlotManager manager = null;
/**
* plotworld object
*/
public HybridPlotWorld plotworld = null;
/**
* Some generator specific variables (implementation dependent)
*/
int plotsize;
int pathsize;
short wall;
short wallfilling;
short roadblock;
int size;
Biome biome;
int roadheight;
int wallheight;
int plotheight;
short[] plotfloors;
short[] filling;
short pathWidthLower;
short pathWidthUpper;
boolean doState = false;
int maxY = 0;
short[][] cached;
/**
* Initialize variables, and create plotworld object used in calculations
*/
@Override
public void init(final PlotWorld plotworld)
{
if (plotworld != null)
{
this.plotworld = (HybridPlotWorld) plotworld;
}
plotsize = this.plotworld.PLOT_WIDTH;
pathsize = this.plotworld.ROAD_WIDTH;
roadblock = this.plotworld.ROAD_BLOCK.id;
wallfilling = this.plotworld.WALL_FILLING.id;
size = pathsize + plotsize;
wall = this.plotworld.WALL_BLOCK.id;
plotfloors = new short[this.plotworld.TOP_BLOCK.length];
for (int i = 0; i < this.plotworld.TOP_BLOCK.length; i++)
{
plotfloors[i] = this.plotworld.TOP_BLOCK[i].id;
}
filling = new short[this.plotworld.MAIN_BLOCK.length];
for (int i = 0; i < this.plotworld.MAIN_BLOCK.length; i++)
{
filling[i] = this.plotworld.MAIN_BLOCK[i].id;
}
if ((filling.length > 1) || (plotfloors.length > 1))
{
doState = true;
}
wallheight = this.plotworld.WALL_HEIGHT;
roadheight = this.plotworld.ROAD_HEIGHT;
plotheight = this.plotworld.PLOT_HEIGHT;
if (pathsize == 0)
{
pathWidthLower = (short) -1;
pathWidthUpper = (short) (plotsize + 1);
}
else
{
if ((pathsize % 2) == 0)
{
pathWidthLower = (short) (Math.floor(pathsize / 2) - 1);
}
else
{
pathWidthLower = (short) (Math.floor(pathsize / 2));
}
pathWidthUpper = (short) (pathWidthLower + plotsize + 1);
}
biome = Biome.valueOf(this.plotworld.PLOT_BIOME);
try
{
maxY = Bukkit.getWorld(plotworld.worldname).getMaxHeight();
}
catch (final NullPointerException e)
{}
if (maxY == 0)
{
maxY = 256;
}
// create cached chunk (for optimized chunk generation)
if (!this.plotworld.PLOT_SCHEMATIC)
{
cached = new short[(plotheight + 16) / 16][];
for (int i = 0; i < cached.length; i++)
{
cached[i] = new short[4096];
}
final PseudoRandom random = new PseudoRandom();
for (int x = 0; x < 16; x++)
{
for (int z = 0; z < 16; z++)
{
cached[CACHE_I[plotheight][x][z]][CACHE_J[plotheight][x][z]] = plotfloors[random.random(plotfloors.length)];
if (this.plotworld.PLOT_BEDROCK)
{
cached[CACHE_I[0][x][z]][CACHE_J[0][x][z]] = 7;
}
for (int y = 1; y < plotheight; y++)
{
cached[CACHE_I[y][x][z]][CACHE_J[y][x][z]] = filling[random.random(filling.length)];
}
}
}
}
}
/**
* 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();
}
return HybridGen.manager;
}
/**
* 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 (plotworld == null)
{
plotworld = new HybridPlotWorld(world);
}
return plotworld;
}
/**
* Return the block populator
*/
@Override
public List<BukkitPlotPopulator> getPopulators(final String world)
{
// You can have as many populators as you would like, e.g. tree
// populator, ore populator
return Arrays.asList((BukkitPlotPopulator) new HybridPop(plotworld));
}
/**
* 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 void generateChunk(final World world, final RegionWrapper region, final PseudoRandom random, final int cx, final int cz, final BiomeGrid biomes)
{
int sx = (short) ((X - plotworld.ROAD_OFFSET_X) % size);
int sz = (short) ((Z - plotworld.ROAD_OFFSET_Z) % size);
if (sx < 0)
{
sx += size;
}
if (sz < 0)
{
sz += size;
}
if (biomes != null)
{
for (short x = 0; x < 16; x++)
{
for (short z = 0; z < 16; z++)
{
biomes.setBiome(x, z, biome);
}
}
}
if (cached != null)
{
if ((sx > pathWidthLower) && (sz > pathWidthLower) && ((sx + 15) < pathWidthUpper) && ((sz + 15) < pathWidthUpper))
{
setResult(cached);
return;
}
}
if (plotworld.PLOT_BEDROCK)
{
for (short x = 0; x < 16; x++)
{
for (short z = 0; z < 16; z++)
{
setBlock(x, 0, z, (short) 7);
}
}
}
if (region != null)
{
for (short x = 0; x < 16; x++)
{
final int absX = ((sx + x) % size);
for (short z = 0; z < 16; z++)
{
if (contains(region, x, z))
{
for (short y = 1; y < plotheight; y++)
{
setBlock(x, y, z, filling);
}
setBlock(x, plotheight, z, plotfloors);
final int absZ = ((sz + z) % size);
final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Short> blocks = plotworld.G_SCH.get(loc);
if (blocks != null)
{
for (final Entry<Short, Short> entry : blocks.entrySet())
{
setBlock(x, plotheight + entry.getKey(), z, entry.getValue());
}
}
}
}
}
return;
}
for (short x = 0; x < 16; x++)
{
final int absX = ((sx + x) % size);
final boolean gx = absX > pathWidthLower;
final boolean lx = absX < pathWidthUpper;
for (short z = 0; z < 16; z++)
{
final int absZ = ((sz + z) % size);
final boolean gz = absZ > pathWidthLower;
final boolean lz = absZ < pathWidthUpper;
// inside plot
if (gx && gz && lx && lz)
{
for (short y = 1; y < plotheight; y++)
{
setBlock(x, y, z, filling);
}
setBlock(x, plotheight, z, plotfloors);
if (plotworld.PLOT_SCHEMATIC)
{
final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Short> blocks = plotworld.G_SCH.get(loc);
if (blocks != null)
{
for (final Entry<Short, Short> entry : blocks.entrySet())
{
setBlock(x, plotheight + entry.getKey(), z, entry.getValue());
}
}
}
}
else if (pathsize != 0)
{
// wall
if (((absX >= pathWidthLower) && (absX <= pathWidthUpper) && (absZ >= pathWidthLower) && (absZ <= pathWidthUpper)))
{
for (short y = 1; y <= wallheight; y++)
{
setBlock(x, y, z, wallfilling);
}
if (!plotworld.ROAD_SCHEMATIC_ENABLED)
{
setBlock(x, wallheight + 1, z, wall);
}
}
// road
else
{
for (short y = 1; y <= roadheight; y++)
{
setBlock(x, y, z, roadblock);
}
}
if (plotworld.ROAD_SCHEMATIC_ENABLED)
{
final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Short> blocks = plotworld.G_SCH.get(loc);
if (blocks != null)
{
for (final Entry<Short, Short> entry : blocks.entrySet())
{
setBlock(x, roadheight + entry.getKey(), z, entry.getValue());
}
}
}
}
}
}
return;

View File

@ -1,233 +1,284 @@
package com.plotsquared.bukkit.generator;
import java.util.HashMap;
import java.util.HashSet;
import org.bukkit.World;
import org.bukkit.block.Biome;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
import com.intellectualcrafters.plot.object.PlotLoc;
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;
/**
* @author Citymonstret
*/
public class HybridPop extends BukkitPlotPopulator {
/*
* Sorry, this isn't well documented at the moment.
* We advise you to take a look at a world generation tutorial for
* information about how a BlockPopulator works.
*/
final short plotsize;
final short pathsize;
final byte wall;
final byte wallfilling;
final byte roadblock;
final int size;
final int roadheight;
final int wallheight;
final int plotheight;
final byte[] plotfloors;
final byte[] filling;
final short pathWidthLower;
final short pathWidthUpper;
private final HybridPlotWorld plotworld;
Biome biome;
private long state;
private boolean doFilling = false;
private boolean doFloor = false;
private boolean doState = false;
public HybridPop(final PlotWorld pw) {
this.plotworld = (HybridPlotWorld) pw;
// save configuration
this.plotsize = (short) this.plotworld.PLOT_WIDTH;
this.pathsize = (short) this.plotworld.ROAD_WIDTH;
this.roadblock = this.plotworld.ROAD_BLOCK.data;
this.wallfilling = this.plotworld.WALL_FILLING.data;
this.size = this.pathsize + this.plotsize;
this.wall = this.plotworld.WALL_BLOCK.data;
int count1 = 0;
int count2 = 0;
this.plotfloors = new byte[this.plotworld.TOP_BLOCK.length];
for (int i = 0; i < this.plotworld.TOP_BLOCK.length; i++) {
count1++;
this.plotfloors[i] = this.plotworld.TOP_BLOCK[i].data;
if (this.plotworld.TOP_BLOCK[i].data != 0) {
this.doFloor = true;
}
}
this.filling = new byte[this.plotworld.MAIN_BLOCK.length];
for (int i = 0; i < this.plotworld.MAIN_BLOCK.length; i++) {
count2++;
this.filling[i] = this.plotworld.MAIN_BLOCK[i].data;
if (this.plotworld.MAIN_BLOCK[i].data != 0) {
this.doFilling = true;
}
}
if (((count1 > 0) && this.doFloor) || ((count2 > 0) && this.doFilling)) {
this.doState = true;
}
this.wallheight = this.plotworld.WALL_HEIGHT;
this.roadheight = this.plotworld.ROAD_HEIGHT;
this.plotheight = this.plotworld.PLOT_HEIGHT;
if (this.pathsize == 0) {
this.pathWidthLower = (short) -1;
this.pathWidthUpper = (short) (this.plotsize + 1);
}
else {
if ((this.pathsize % 2) == 0) {
this.pathWidthLower = (short) (Math.floor(this.pathsize / 2) - 1);
} else {
this.pathWidthLower = (short) (Math.floor(this.pathsize / 2));
}
this.pathWidthUpper = (short) (this.pathWidthLower + this.plotsize + 1);
}
}
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 result = ((nextLong() >>> 32) * n) >> 32;
return (int) result;
}
@Override
public void populate(World world, RegionWrapper requiredRegion, PseudoRandom random, int cx, int cz) {
PS.get().getPlotManager(world.getName());
int sx = (short) ((this.X - this.plotworld.ROAD_OFFSET_X) % this.size);
int sz = (short) ((this.Z - this.plotworld.ROAD_OFFSET_Z) % this.size);
if (sx < 0) {
sx += this.size;
}
if (sz < 0) {
sz += this.size;
}
if (requiredRegion != null) {
for (short x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) {
if (contains(requiredRegion, x, z)) {
if (this.doFilling) {
for (short y = 1; y < this.plotheight; y++) {
setBlock(x, y, z, this.filling);
}
}
if (this.doFloor) {
setBlock(x, (short) this.plotheight, z, this.plotfloors);
}
if (this.plotworld.PLOT_SCHEMATIC) {
final int absX = ((sx + x) % this.size);
final int absZ = ((sz + z) % this.size);
final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Byte> blocks = this.plotworld.G_SCH_DATA.get(loc);
if (blocks != null) {
for (final short y : blocks.keySet()) {
setBlockAbs(x, (short) (this.plotheight + y), z, blocks.get(y));
}
}
if (this.plotworld.G_SCH_STATE != null) {
HashSet<PlotItem> states = this.plotworld.G_SCH_STATE.get(loc);
if (states != null) {
for (PlotItem items : states) {
BlockManager.manager.addItems(this.plotworld.worldname, items);
}
}
}
}
}
}
}
return;
}
for (short x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) {
final int absX = ((sx + x) % this.size);
final int absZ = ((sz + z) % this.size);
final boolean gx = absX > this.pathWidthLower;
final boolean gz = absZ > this.pathWidthLower;
final boolean lx = absX < this.pathWidthUpper;
final boolean lz = absZ < this.pathWidthUpper;
// inside plot
if (gx && gz && lx && lz) {
for (short y = 1; y < this.plotheight; y++) {
setBlock(x, y, z, this.filling);
}
setBlock(x, (short) this.plotheight, z, this.plotfloors);
if (this.plotworld.PLOT_SCHEMATIC) {
final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Byte> blocks = this.plotworld.G_SCH_DATA.get(loc);
if (blocks != null) {
for (final short y : blocks.keySet()) {
setBlockAbs(x, (short) (this.plotheight + y), z, blocks.get(y));
}
}
if (this.plotworld.G_SCH_STATE != null) {
HashSet<PlotItem> states = this.plotworld.G_SCH_STATE.get(loc);
if (states != null) {
for (PlotItem items : states) {
items.x = this.X + x;
items.z = this.Z + z;
BlockManager.manager.addItems(this.plotworld.worldname, items);
}
}
}
}
} else if (pathsize != 0) {
// wall
if (((absX >= this.pathWidthLower) && (absX <= this.pathWidthUpper) && (absZ >= this.pathWidthLower) && (absZ <= this.pathWidthUpper))) {
for (short y = 1; y <= this.wallheight; y++) {
setBlock(x, y, z, this.wallfilling);
}
if (!this.plotworld.ROAD_SCHEMATIC_ENABLED) {
setBlock(x, this.wallheight + 1, z, this.wall);
}
}
// road
else {
for (short y = 1; y <= this.roadheight; y++) {
setBlock(x, y, z, this.roadblock);
}
}
if (this.plotworld.ROAD_SCHEMATIC_ENABLED) {
final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Byte> blocks = this.plotworld.G_SCH_DATA.get(loc);
if (blocks != null) {
for (final short y : blocks.keySet()) {
setBlockAbs(x, (short) (this.roadheight + y), z, blocks.get(y));
}
}
}
}
}
}
}
private void setBlock(final short x, final short y, final short z, final byte[] blkids) {
if (blkids.length == 1) {
setBlock(x, y, z, blkids[0]);
} else {
final int i = random(blkids.length);
setBlock(x, y, z, blkids[i]);
}
}
}
package com.plotsquared.bukkit.generator;
import java.util.HashMap;
import java.util.HashSet;
import org.bukkit.World;
import org.bukkit.block.Biome;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
import com.intellectualcrafters.plot.object.PlotLoc;
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;
/**
*/
public class HybridPop extends BukkitPlotPopulator
{
/*
* Sorry, this isn't well documented at the moment.
* We advise you to take a look at a world generation tutorial for
* information about how a BlockPopulator works.
*/
final short plotsize;
final short pathsize;
final byte wall;
final byte wallfilling;
final byte roadblock;
final int size;
final int roadheight;
final int wallheight;
final int plotheight;
final byte[] plotfloors;
final byte[] filling;
final short pathWidthLower;
final short pathWidthUpper;
private final HybridPlotWorld plotworld;
Biome biome;
private long state;
private boolean doFilling = false;
private boolean doFloor = false;
public HybridPop(final PlotWorld pw)
{
plotworld = (HybridPlotWorld) pw;
// save configuration
plotsize = (short) plotworld.PLOT_WIDTH;
pathsize = (short) plotworld.ROAD_WIDTH;
roadblock = plotworld.ROAD_BLOCK.data;
wallfilling = plotworld.WALL_FILLING.data;
size = pathsize + plotsize;
wall = plotworld.WALL_BLOCK.data;
int count1 = 0;
int count2 = 0;
plotfloors = new byte[plotworld.TOP_BLOCK.length];
for (int i = 0; i < plotworld.TOP_BLOCK.length; i++)
{
count1++;
plotfloors[i] = plotworld.TOP_BLOCK[i].data;
if (plotworld.TOP_BLOCK[i].data != 0)
{
doFloor = true;
}
}
filling = new byte[plotworld.MAIN_BLOCK.length];
for (int i = 0; i < plotworld.MAIN_BLOCK.length; i++)
{
count2++;
filling[i] = plotworld.MAIN_BLOCK[i].data;
if (plotworld.MAIN_BLOCK[i].data != 0)
{
doFilling = true;
}
}
if (((count1 > 0) && doFloor) || ((count2 > 0) && doFilling))
{}
wallheight = plotworld.WALL_HEIGHT;
roadheight = plotworld.ROAD_HEIGHT;
plotheight = plotworld.PLOT_HEIGHT;
if (pathsize == 0)
{
pathWidthLower = (short) -1;
pathWidthUpper = (short) (plotsize + 1);
}
else
{
if ((pathsize % 2) == 0)
{
pathWidthLower = (short) (Math.floor(pathsize / 2) - 1);
}
else
{
pathWidthLower = (short) (Math.floor(pathsize / 2));
}
pathWidthUpper = (short) (pathWidthLower + plotsize + 1);
}
}
public final long nextLong()
{
final long a = state;
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 result = ((nextLong() >>> 32) * n) >> 32;
return (int) result;
}
@Override
public void populate(final World world, final RegionWrapper requiredRegion, final PseudoRandom random, final int cx, final int cz)
{
PS.get().getPlotManager(world.getName());
int sx = (short) ((X - plotworld.ROAD_OFFSET_X) % size);
int sz = (short) ((Z - plotworld.ROAD_OFFSET_Z) % size);
if (sx < 0)
{
sx += size;
}
if (sz < 0)
{
sz += size;
}
if (requiredRegion != null)
{
for (short x = 0; x < 16; x++)
{
for (short z = 0; z < 16; z++)
{
if (contains(requiredRegion, x, z))
{
if (doFilling)
{
for (short y = 1; y < plotheight; y++)
{
setBlock(x, y, z, filling);
}
}
if (doFloor)
{
setBlock(x, (short) plotheight, z, plotfloors);
}
if (plotworld.PLOT_SCHEMATIC)
{
final int absX = ((sx + x) % size);
final int absZ = ((sz + z) % size);
final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Byte> blocks = plotworld.G_SCH_DATA.get(loc);
if (blocks != null)
{
for (final short y : blocks.keySet())
{
setBlockAbs(x, (short) (plotheight + y), z, blocks.get(y));
}
}
if (plotworld.G_SCH_STATE != null)
{
final HashSet<PlotItem> states = plotworld.G_SCH_STATE.get(loc);
if (states != null)
{
for (final PlotItem items : states)
{
BlockManager.manager.addItems(plotworld.worldname, items);
}
}
}
}
}
}
}
return;
}
for (short x = 0; x < 16; x++)
{
for (short z = 0; z < 16; z++)
{
final int absX = ((sx + x) % size);
final int absZ = ((sz + z) % size);
final boolean gx = absX > pathWidthLower;
final boolean gz = absZ > pathWidthLower;
final boolean lx = absX < pathWidthUpper;
final boolean lz = absZ < pathWidthUpper;
// inside plot
if (gx && gz && lx && lz)
{
for (short y = 1; y < plotheight; y++)
{
setBlock(x, y, z, filling);
}
setBlock(x, (short) plotheight, z, plotfloors);
if (plotworld.PLOT_SCHEMATIC)
{
final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Byte> blocks = plotworld.G_SCH_DATA.get(loc);
if (blocks != null)
{
for (final short y : blocks.keySet())
{
setBlockAbs(x, (short) (plotheight + y), z, blocks.get(y));
}
}
if (plotworld.G_SCH_STATE != null)
{
final HashSet<PlotItem> states = plotworld.G_SCH_STATE.get(loc);
if (states != null)
{
for (final PlotItem items : states)
{
items.x = X + x;
items.z = Z + z;
BlockManager.manager.addItems(plotworld.worldname, items);
}
}
}
}
}
else if (pathsize != 0)
{
// wall
if (((absX >= pathWidthLower) && (absX <= pathWidthUpper) && (absZ >= pathWidthLower) && (absZ <= pathWidthUpper)))
{
for (short y = 1; y <= wallheight; y++)
{
setBlock(x, y, z, wallfilling);
}
if (!plotworld.ROAD_SCHEMATIC_ENABLED)
{
setBlock(x, wallheight + 1, z, wall);
}
}
// road
else
{
for (short y = 1; y <= roadheight; y++)
{
setBlock(x, y, z, roadblock);
}
}
if (plotworld.ROAD_SCHEMATIC_ENABLED)
{
final PlotLoc loc = new PlotLoc(absX, absZ);
final HashMap<Short, Byte> blocks = plotworld.G_SCH_DATA.get(loc);
if (blocks != null)
{
for (final short y : blocks.keySet())
{
setBlockAbs(x, (short) (roadheight + y), z, blocks.get(y));
}
}
}
}
}
}
}
private void setBlock(final short x, final short y, final short z, final byte[] blkids)
{
if (blkids.length == 1)
{
setBlock(x, y, z, blkids[0]);
}
else
{
final int i = random(blkids.length);
setBlock(x, y, z, blkids[i]);
}
}