Fix debugclear

This commit is contained in:
boy0001 2015-03-27 19:20:19 +11:00
parent 89f4cc7dec
commit 2e7220e40d
3 changed files with 48 additions and 96 deletions

View File

@ -30,8 +30,6 @@ import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotLoc; import com.intellectualcrafters.plot.object.PlotLoc;
@ -40,7 +38,6 @@ import com.intellectualcrafters.plot.object.PlotPopulator;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.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;
import com.intellectualcrafters.plot.util.ChunkManager;
/** /**
* The default generator is very messy, as we have decided to try externalize all calculations from within the loop. - * The default generator is very messy, as we have decided to try externalize all calculations from within the loop. -
@ -78,14 +75,6 @@ public class HybridGen extends PlotGenerator {
short pathWidthUpper; short pathWidthUpper;
boolean doState = false; boolean doState = false;
int maxY = 0; int maxY = 0;
/**
* result object is returned for each generated chunk, do stuff to it
*/
short[][] result;
/**
* Faster sudo-random number generator than java.util.random
*/
private long state = 13;
/** /**
* Initialize variables, and create plotworld object used in calculations * Initialize variables, and create plotworld object used in calculations
@ -131,7 +120,6 @@ public class HybridGen extends PlotGenerator {
* Return the plot manager for this type of generator, or create one For square plots you may as well use the * 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 * default plot manager which comes with PlotSquared
*/ */
@Override
public PlotManager getPlotManager() { public PlotManager getPlotManager() {
if (HybridGen.manager == null) { if (HybridGen.manager == null) {
HybridGen.manager = new HybridPlotManager(); HybridGen.manager = new HybridPlotManager();
@ -139,18 +127,9 @@ public class HybridGen extends PlotGenerator {
return HybridGen.manager; return HybridGen.manager;
} }
/**
* Allow spawning everywhere
*/
@Override
public boolean canSpawn(final World world, final int x, final int z) {
return true;
}
/** /**
* Get a new plotworld class For square plots you can use the DefaultPlotWorld class which comes with PlotSquared * 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) { public PlotWorld getNewPlotWorld(final String world) {
if (this.plotworld == null) { if (this.plotworld == null) {
this.plotworld = new HybridPlotWorld(world); this.plotworld = new HybridPlotWorld(world);
@ -158,43 +137,6 @@ public class HybridGen extends PlotGenerator {
return this.plotworld; return this.plotworld;
} }
public final long nextLong() {
final long a = this.state;
this.state = xorShift64(a);
return a;
}
public final long xorShift64(long a) {
a ^= (a << 21);
a ^= (a >>> 35);
a ^= (a << 4);
return a;
}
public final int random(final int n) {
final long r = ((nextLong() >>> 32) * n) >> 32;
return (int) r;
}
private void setBlock(final short[][] result, final int x, final int y, final int z, final short[] blkids) {
if (blkids.length == 1) {
setBlock(result, x, y, z, blkids[0]);
} else {
final int i = random(blkids.length);
setBlock(result, x, y, z, blkids[i]);
}
}
/**
* Standard setblock method for world generation
*/
private void setBlock(final short[][] result, final int x, final int y, final int z, final short blkid) {
if (result[y >> 4] == null) {
result[y >> 4] = new short[4096];
}
result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blkid;
}
/** /**
* Return the block populator * Return the block populator
*/ */
@ -207,31 +149,22 @@ public class HybridGen extends PlotGenerator {
/** /**
* Return the default spawn location for this world * Return the default spawn location for this world
*/ */
@Override // public Location getFixedSpawnLocation(final World world, final Random random) {
public Location getFixedSpawnLocation(final World world, final Random random) { // if (this.plotworld == null) {
if (this.plotworld == null) { // return new Location(world, 0, 128, 0);
return new Location(world, 0, 128, 0); // }
} // return new Location(world, 0, this.plotworld.ROAD_HEIGHT + 2, 0);
return new Location(world, 0, this.plotworld.ROAD_HEIGHT + 2, 0); // }
}
/** /**
* This part is a fucking mess. - Refer to a proper tutorial if you would like to learn how to make a world * This part is a fucking mess. - Refer to a proper tutorial if you would like to learn how to make a world
* generator * generator
*/ */
@Override public void generateChunk(final World world, RegionWrapper region, final PseudoRandom random, final int cx, final int cz, final BiomeGrid biomes) {
public short[][] generateChunk(final World world, RegionWrapper region, final PseudoRandom random, final int cx, final int cz, final BiomeGrid biomes, final short[][] result) {
if (this.doState) {
final int prime = 13;
int h = 1;
h = (prime * h) + cx;
h = (prime * h) + cz;
this.state = h;
}
if (this.plotworld.PLOT_BEDROCK) { if (this.plotworld.PLOT_BEDROCK) {
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++) {
setBlock(this.result, x, 0, z, (short) 7); setBlock(x, 0, z, (short) 7);
} }
} }
} }
@ -253,20 +186,20 @@ public class HybridGen extends PlotGenerator {
} }
if (contains(region, x, z)) { 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(x, y, z, this.filling);
} }
setBlock(this.result, x, this.plotheight, z, this.plotfloors); setBlock(x, this.plotheight, z, this.plotfloors);
final PlotLoc loc = new PlotLoc((short) (X + x), (short) (Z + z)); final PlotLoc loc = new PlotLoc((short) (X + x), (short) (Z + z));
final HashMap<Short, Short> blocks = plotworld.G_SCH.get(loc); final HashMap<Short, Short> blocks = plotworld.G_SCH.get(loc);
if (blocks != null) { if (blocks != null) {
for (final Entry<Short, Short> entry : blocks.entrySet()) { for (final Entry<Short, Short> entry : blocks.entrySet()) {
setBlock(this.result, x, this.plotheight + entry.getKey(), z, entry.getValue()); setBlock(x, this.plotheight + entry.getKey(), z, entry.getValue());
} }
} }
} }
} }
} }
return this.result; return;
} }
int sx = ((cx << 4) % this.size); int sx = ((cx << 4) % this.size);
int sz = ((cz << 4) % this.size); int sz = ((cz << 4) % this.size);
@ -290,15 +223,15 @@ public class HybridGen extends PlotGenerator {
// inside plot // inside plot
if (gx && gz && lx && lz) { if (gx && gz && lx && lz) {
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(x, y, z, this.filling);
} }
setBlock(this.result, x, this.plotheight, z, this.plotfloors); setBlock(x, this.plotheight, z, this.plotfloors);
if (this.plotworld.PLOT_SCHEMATIC) { if (this.plotworld.PLOT_SCHEMATIC) {
final PlotLoc loc = new PlotLoc((short) absX, (short) absZ); final PlotLoc loc = new PlotLoc((short) absX, (short) absZ);
final HashMap<Short, Short> blocks = this.plotworld.G_SCH.get(loc); final HashMap<Short, Short> blocks = this.plotworld.G_SCH.get(loc);
if (blocks != null) { if (blocks != null) {
for (final Entry<Short, Short> entry : blocks.entrySet()) { for (final Entry<Short, Short> entry : blocks.entrySet()) {
setBlock(this.result, x, this.plotheight + entry.getKey(), z, entry.getValue()); setBlock(x, this.plotheight + entry.getKey(), z, entry.getValue());
} }
} }
} }
@ -306,16 +239,16 @@ public class HybridGen extends PlotGenerator {
// wall // wall
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))) {
for (short y = 1; y <= this.wallheight; y++) { for (short y = 1; y <= this.wallheight; y++) {
setBlock(this.result, x, y, z, this.wallfilling); setBlock(x, y, z, this.wallfilling);
} }
if (!this.plotworld.ROAD_SCHEMATIC_ENABLED) { if (!this.plotworld.ROAD_SCHEMATIC_ENABLED) {
setBlock(this.result, x, this.wallheight + 1, z, this.wall); setBlock(x, this.wallheight + 1, z, this.wall);
} }
} }
// road // road
else { else {
for (short y = 1; y <= this.roadheight; y++) { for (short y = 1; y <= this.roadheight; y++) {
setBlock(this.result, x, y, z, this.roadblock); setBlock(x, y, z, this.roadblock);
} }
} }
if (this.plotworld.ROAD_SCHEMATIC_ENABLED) { if (this.plotworld.ROAD_SCHEMATIC_ENABLED) {
@ -323,13 +256,13 @@ public class HybridGen extends PlotGenerator {
final HashMap<Short, Short> blocks = this.plotworld.G_SCH.get(loc); final HashMap<Short, Short> blocks = this.plotworld.G_SCH.get(loc);
if (blocks != null) { if (blocks != null) {
for (final Entry<Short, Short> entry : blocks.entrySet()) { for (final Entry<Short, Short> entry : blocks.entrySet()) {
setBlock(this.result, x, this.roadheight + entry.getKey(), z, entry.getValue()); setBlock(x, this.roadheight + entry.getKey(), z, entry.getValue());
} }
} }
} }
} }
} }
} }
return this.result; return;
} }
} }

View File

@ -65,7 +65,7 @@ public abstract class PlotGenerator extends ChunkGenerator {
} }
@Override @Override
public short[][] generateExtBlockSections(final World world, final Random r, final int cx, final int cz, final BiomeGrid biomes) { public short[][] generateExtBlockSections(World world, Random r, int cx, int cz, BiomeGrid biomes) {
final int prime = 13; final int prime = 13;
int h = 1; int h = 1;
h = (prime * h) + cx; h = (prime * h) + cx;
@ -74,9 +74,9 @@ public abstract class PlotGenerator extends ChunkGenerator {
this.result = new short[256 / 16][]; this.result = new short[256 / 16][];
PlotWorld plotworld = PlotSquared.getPlotWorld(world.getName()); PlotWorld plotworld = PlotSquared.getPlotWorld(world.getName());
Biome biome = Biome.valueOf(plotworld.PLOT_BIOME); Biome biome = Biome.valueOf(plotworld.PLOT_BIOME);
this.X = cx << 4;
this.Z = cz << 4;
if (ChunkManager.FORCE_PASTE) { if (ChunkManager.FORCE_PASTE) {
X = cx << 4;
Z = cz << 4;
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 (biomes != null) { if (biomes != null) {
@ -91,26 +91,37 @@ public abstract class PlotGenerator extends ChunkGenerator {
} }
return this.result; return this.result;
} }
this.result = generateChunk(world, ChunkManager.CURRENT_PLOT_CLEAR, random, cx, cz, biomes, result); generateChunk(world, ChunkManager.CURRENT_PLOT_CLEAR, random, cx, cz, biomes);
if (ChunkManager.CURRENT_PLOT_CLEAR != null) { if (ChunkManager.CURRENT_PLOT_CLEAR != null) {
PlotLoc loc; PlotLoc loc;
for (Entry<PlotLoc, HashMap<Short, Short>> entry : ChunkManager.GENERATE_BLOCKS.entrySet()) { for (Entry<PlotLoc, HashMap<Short, Short>> entry : ChunkManager.GENERATE_BLOCKS.entrySet()) {
for (Entry<Short, Short> entry2 : entry.getValue().entrySet()) { for (Entry<Short, Short> entry2 : entry.getValue().entrySet()) {
loc = entry.getKey(); loc = entry.getKey();
setBlock(loc.x, entry2.getKey(), loc.z, entry2.getValue()); setBlock(loc.x - X, entry2.getKey(), loc.z- Z, entry2.getValue());
} }
} }
} }
return result; return result;
} }
private void setBlock(final int x, final int y, final int z, final short blkid) { public void setBlock(final int x, final int y, final int z, final short blkid) {
if (result[y >> 4] == null) { if (result[y >> 4] == null) {
result[y >> 4] = new short[4096]; result[y >> 4] = new short[4096];
} }
result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blkid; result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blkid;
} }
public void setBlock(final int x, final int y, final int z, final short[] blkid) {
if (blkid.length == 1) {
setBlock(x, y, z, blkid[0]);
}
short id = blkid[random.random(blkid.length)];
if (result[y >> 4] == null) {
result[y >> 4] = new short[4096];
}
result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = id;
}
/** /**
* check if a region contains a location. (x, z) must be between [0,15], [0,15] * check if a region contains a location. (x, z) must be between [0,15], [0,15]
* @param plot * @param plot
@ -124,6 +135,14 @@ public abstract class PlotGenerator extends ChunkGenerator {
return ((xx >= plot.minX) && (xx <= plot.maxX) && (zz >= plot.minZ) && (zz <= plot.maxZ)); return ((xx >= plot.minX) && (xx <= plot.maxX) && (zz >= plot.minZ) && (zz <= plot.maxZ));
} }
/**
* Allow spawning everywhere
*/
@Override
public boolean canSpawn(final World world, final int x, final int z) {
return true;
}
/** /**
* <b>random</b> is a optimized random number generator.<br> * <b>random</b> is a optimized random number generator.<br>
* - Change the state to have the same chunk random each time it generates<br> * - Change the state to have the same chunk random each time it generates<br>
@ -143,7 +162,7 @@ public abstract class PlotGenerator extends ChunkGenerator {
* @param result * @param result
* @return * @return
*/ */
public abstract short[][] generateChunk(final World world, RegionWrapper requiredRegion, final PseudoRandom random, final int cx, final int cz, final BiomeGrid biomes, final short[][] result); public abstract void generateChunk(final World world, RegionWrapper requiredRegion, final PseudoRandom random, final int cx, final int cz, final BiomeGrid biomes);
public abstract List<PlotPopulator> getPopulators(String world); public abstract List<PlotPopulator> getPopulators(String world);

View File

@ -46,7 +46,7 @@ public abstract class PlotPopulator extends BlockPopulator {
for (Entry<PlotLoc, HashMap<Short, Byte>> entry : ChunkManager.GENERATE_DATA.entrySet()) { for (Entry<PlotLoc, HashMap<Short, Byte>> entry : ChunkManager.GENERATE_DATA.entrySet()) {
for (Entry<Short, Byte> entry2 : entry.getValue().entrySet()) { for (Entry<Short, Byte> entry2 : entry.getValue().entrySet()) {
loc = entry.getKey(); loc = entry.getKey();
setBlock(loc.x, entry2.getKey(), loc.z, entry2.getValue()); setBlock(loc.x - X, entry2.getKey(), loc.z - Z, entry2.getValue());
} }
} }
} }
@ -74,7 +74,7 @@ public abstract class PlotPopulator extends BlockPopulator {
* @param data * @param data
*/ */
public void setBlock(int x, int y, int z, byte data) { public void setBlock(int x, int y, int z, byte data) {
world.getBlockAt(X + x, y, Z + z).setTypeId(data); world.getBlockAt(X + x, y, Z + z).setData(data);
} }
/** /**