mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Sudo-random plot content with data values
This commit is contained in:
parent
c07634acc6
commit
d919dc0dbd
@ -86,7 +86,7 @@ public class PlotWorld {
|
|||||||
/**
|
/**
|
||||||
* Default main block: 1
|
* Default main block: 1
|
||||||
*/
|
*/
|
||||||
public static String[] MAIN_BLOCK_DEFAULT = new String[] {"1"};
|
public static String[] MAIN_BLOCK_DEFAULT = new String[] {"1:0"};
|
||||||
/**
|
/**
|
||||||
* Top blocks
|
* Top blocks
|
||||||
*/
|
*/
|
||||||
@ -94,7 +94,7 @@ public class PlotWorld {
|
|||||||
/**
|
/**
|
||||||
* Default top blocks: {"2"}
|
* Default top blocks: {"2"}
|
||||||
*/
|
*/
|
||||||
public static String[] TOP_BLOCK_DEFAULT = new String[] {"2"};
|
public static String[] TOP_BLOCK_DEFAULT = new String[] {"2:0"};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wall block
|
* Wall block
|
||||||
|
@ -22,12 +22,12 @@ public class SetBlockFast {
|
|||||||
|
|
||||||
public static boolean set(org.bukkit.World world, int x, int y, int z, int blockId, byte data) {
|
public static boolean set(org.bukkit.World world, int x, int y, int z, int blockId, byte data) {
|
||||||
Object w = methodGetHandle.of(world).call();
|
Object w = methodGetHandle.of(world).call();
|
||||||
|
|
||||||
Object chunk = methodGetChunkAt.of(w).call(x >> 4, z >> 4);
|
Object chunk = methodGetChunkAt.of(w).call(x >> 4, z >> 4);
|
||||||
Object block = methodGetById.of(null).call(blockId);
|
Object block = methodGetById.of(null).call(blockId);
|
||||||
methodA.of(chunk).call(x & 0x0f, y, z & 0x0f,block , data);
|
methodA.of(chunk).call(x & 0x0f, y, z & 0x0f,block , data);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void update(Player player) {
|
public static void update(Player player) {
|
||||||
for (int cx = -8; cx < 8; cx++) {
|
for (int cx = -8; cx < 8; cx++) {
|
||||||
for (int cz = -8; cz < 8; cz++) {
|
for (int cz = -8; cz < 8; cz++) {
|
||||||
|
@ -22,6 +22,24 @@ import static com.intellectualcrafters.plot.PlotWorld.*;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class WorldGenerator extends ChunkGenerator {
|
public class WorldGenerator extends ChunkGenerator {
|
||||||
|
private long state = 100;
|
||||||
|
public final long nextLong() {
|
||||||
|
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(int n) {
|
||||||
|
long r = ((nextLong()>>>32)*n)>>32;
|
||||||
|
return (int) r;
|
||||||
|
}
|
||||||
short[][] result;
|
short[][] result;
|
||||||
int plotsize;
|
int plotsize;
|
||||||
int pathsize;
|
int pathsize;
|
||||||
@ -36,22 +54,8 @@ public class WorldGenerator extends ChunkGenerator {
|
|||||||
int wallheight;
|
int wallheight;
|
||||||
int plotheight;
|
int plotheight;
|
||||||
|
|
||||||
Short[] plotfloors;
|
short[] plotfloors;
|
||||||
Short[] filling;
|
short[] filling;
|
||||||
|
|
||||||
public short getFilling(Random random) {
|
|
||||||
if (filling.length==1) {
|
|
||||||
return filling[0];
|
|
||||||
}
|
|
||||||
return filling[random.nextInt(filling.length)];
|
|
||||||
}
|
|
||||||
|
|
||||||
public short getPlotFloor(Random random) {
|
|
||||||
if (plotfloors.length==1) {
|
|
||||||
return plotfloors[0];
|
|
||||||
}
|
|
||||||
return plotfloors[random.nextInt(plotfloors.length)];
|
|
||||||
}
|
|
||||||
|
|
||||||
public Short getBlock(String block) {
|
public Short getBlock(String block) {
|
||||||
if (block.contains(":")) {
|
if (block.contains(":")) {
|
||||||
@ -131,8 +135,8 @@ public class WorldGenerator extends ChunkGenerator {
|
|||||||
size = pathsize + plotsize;
|
size = pathsize + plotsize;
|
||||||
wall = getBlock(plotworld.WALL_BLOCK);
|
wall = getBlock(plotworld.WALL_BLOCK);
|
||||||
|
|
||||||
plotfloors = new Short[plotworld.TOP_BLOCK.length];
|
plotfloors = new short[plotworld.TOP_BLOCK.length];
|
||||||
filling = new Short[plotworld.TOP_BLOCK.length];
|
filling = new short[plotworld.MAIN_BLOCK.length];
|
||||||
|
|
||||||
for (int i = 0; i < plotworld.TOP_BLOCK.length; i++) {
|
for (int i = 0; i < plotworld.TOP_BLOCK.length; i++) {
|
||||||
plotfloors[i] = getBlock(plotworld.TOP_BLOCK[i]);
|
plotfloors[i] = getBlock(plotworld.TOP_BLOCK[i]);
|
||||||
@ -156,7 +160,7 @@ public class WorldGenerator extends ChunkGenerator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BlockPopulator> getDefaultPopulators(World world) {
|
public List<BlockPopulator> getDefaultPopulators(World world) {
|
||||||
return Arrays.asList((BlockPopulator) new XPopulator());
|
return Arrays.asList((BlockPopulator) new XPopulator(PlotMain.getWorldSettings(world)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -168,12 +172,31 @@ public class WorldGenerator extends ChunkGenerator {
|
|||||||
for (int x = x1; x < x2; x++) {
|
for (int x = x1; x < x2; x++) {
|
||||||
for (int z = z1; z < z2; z++) {
|
for (int z = z1; z < z2; z++) {
|
||||||
for (int y = y1; y < y2; y++) {
|
for (int y = y1; y < y2; y++) {
|
||||||
setBlock(result, (int) x, y, (int) z, id);
|
setBlock(result, x, y, z, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void setCuboidRegion(int x1, int x2, int y1, int y2, int z1, int z2, short[] id) {
|
||||||
|
if (id.length==1) {
|
||||||
|
setCuboidRegion(x1,x2,y1,y2,z1,z2,id[0]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (int x = x1; x < x2; x++) {
|
||||||
|
for (int z = z1; z < z2; z++) {
|
||||||
|
for (int y = y1; y < y2; y++) {
|
||||||
|
int i = random(id.length);
|
||||||
|
setBlock(result, x, y, z, id[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public short[][] generateExtBlockSections(World world, Random random,
|
public short[][] generateExtBlockSections(World world, Random random,
|
||||||
@ -184,10 +207,13 @@ public class WorldGenerator extends ChunkGenerator {
|
|||||||
|
|
||||||
double pathWidthLower;
|
double pathWidthLower;
|
||||||
pathWidthLower = Math.floor(pathsize/2);
|
pathWidthLower = Math.floor(pathsize/2);
|
||||||
if (cx<0)
|
final int prime = 31;
|
||||||
cx+=((-cx)*(size));
|
int h = 1;
|
||||||
if (cz<0)
|
h = prime * h + cx;
|
||||||
cz+=((-cz)*(size));
|
h = prime * h + cz;
|
||||||
|
state = h;
|
||||||
|
cx=cx%size+8*size;
|
||||||
|
cz=cz%size+8*size;
|
||||||
int absX = (int) (cx*16+16-pathWidthLower-1+8*size);
|
int absX = (int) (cx*16+16-pathWidthLower-1+8*size);
|
||||||
int absZ = (int) (cz*16+16-pathWidthLower-1+8*size);
|
int absZ = (int) (cz*16+16-pathWidthLower-1+8*size);
|
||||||
int plotMinX = (((absX)%size));
|
int plotMinX = (((absX)%size));
|
||||||
@ -261,8 +287,6 @@ public class WorldGenerator extends ChunkGenerator {
|
|||||||
}
|
}
|
||||||
if (roadStartZ<=16&&roadStartZ>1) {
|
if (roadStartZ<=16&&roadStartZ>1) {
|
||||||
int val = roadStartZ;
|
int val = roadStartZ;
|
||||||
// if (val==0)
|
|
||||||
// val+=16-pathsize+2;
|
|
||||||
int start,end;
|
int start,end;
|
||||||
if (plotMinX+2<=16)
|
if (plotMinX+2<=16)
|
||||||
start = 16-plotMinX-1;
|
start = 16-plotMinX-1;
|
||||||
@ -303,37 +327,37 @@ public class WorldGenerator extends ChunkGenerator {
|
|||||||
if (plotsize>16) {
|
if (plotsize>16) {
|
||||||
if (roadStartX<=16) {
|
if (roadStartX<=16) {
|
||||||
if (roadStartZ<=16) {
|
if (roadStartZ<=16) {
|
||||||
setCuboidRegion(0, 16-roadStartX, 1, plotheight, 0, 16-roadStartZ, getFilling(random));
|
setCuboidRegion(0, 16-roadStartX, 1, plotheight, 0, 16-roadStartZ, filling);
|
||||||
setCuboidRegion(0, 16-roadStartX, plotheight, plotheight+1, 0, 16-roadStartZ, getPlotFloor(random));
|
setCuboidRegion(0, 16-roadStartX, plotheight, plotheight+1, 0, 16-roadStartZ, plotfloors);
|
||||||
}
|
}
|
||||||
if (plotMinZ<=16) {
|
if (plotMinZ<=16) {
|
||||||
setCuboidRegion(0, 16-roadStartX, 1, plotheight, 16-plotMinZ, 16, getFilling(random));
|
setCuboidRegion(0, 16-roadStartX, 1, plotheight, 16-plotMinZ, 16, filling);
|
||||||
setCuboidRegion(0, 16-roadStartX, plotheight, plotheight+1, 16-plotMinZ, 16, getPlotFloor(random));
|
setCuboidRegion(0, 16-roadStartX, plotheight, plotheight+1, 16-plotMinZ, 16, plotfloors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (roadStartZ<=16) {
|
if (roadStartZ<=16) {
|
||||||
if (plotMinX>16) {
|
if (plotMinX>16) {
|
||||||
setCuboidRegion(0, 16, 1, plotheight, 0, 16-roadStartZ, getFilling(random));
|
setCuboidRegion(0, 16, 1, plotheight, 0, 16-roadStartZ, filling);
|
||||||
setCuboidRegion(0, 16, plotheight, plotheight+1, 0, 16-roadStartZ, getPlotFloor(random));
|
setCuboidRegion(0, 16, plotheight, plotheight+1, 0, 16-roadStartZ, plotfloors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (plotMinX<=16) {
|
if (plotMinX<=16) {
|
||||||
if (plotMinZ<=16) {
|
if (plotMinZ<=16) {
|
||||||
setCuboidRegion(16-plotMinX, 16, 1, plotheight, 16-plotMinZ, 16, getFilling(random));
|
setCuboidRegion(16-plotMinX, 16, 1, plotheight, 16-plotMinZ, 16, filling);
|
||||||
setCuboidRegion(16-plotMinX, 16, plotheight, plotheight+1, 16-plotMinZ, 16, getPlotFloor(random));
|
setCuboidRegion(16-plotMinX, 16, plotheight, plotheight+1, 16-plotMinZ, 16, plotfloors);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int z = (int) (16-roadStartZ);
|
int z = (int) (16-roadStartZ);
|
||||||
if (z<0)
|
if (z<0)
|
||||||
z=16;
|
z=16;
|
||||||
setCuboidRegion(16-plotMinX, 16, 1, plotheight, 0, z, getFilling(random));
|
setCuboidRegion(16-plotMinX, 16, 1, plotheight, 0, z, filling);
|
||||||
setCuboidRegion(16-plotMinX, 16, plotheight, plotheight+1, 0, z, getPlotFloor(random));
|
setCuboidRegion(16-plotMinX, 16, plotheight, plotheight+1, 0, z, plotfloors);
|
||||||
}
|
}
|
||||||
if (roadStartZ<=16) {
|
if (roadStartZ<=16) {
|
||||||
setCuboidRegion(16-plotMinX, 16, 1, plotheight, 0, 16-roadStartZ, getFilling(random));
|
setCuboidRegion(16-plotMinX, 16, 1, plotheight, 0, 16-roadStartZ, filling);
|
||||||
setCuboidRegion(16-plotMinX, 16, plotheight, plotheight+1, 0, 16-roadStartZ, getPlotFloor(random));
|
setCuboidRegion(16-plotMinX, 16, plotheight, plotheight+1, 0, 16-roadStartZ, plotfloors);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (roadStartX<=16) {
|
if (roadStartX<=16) {
|
||||||
@ -341,8 +365,8 @@ public class WorldGenerator extends ChunkGenerator {
|
|||||||
int x = (int) (16-roadStartX);
|
int x = (int) (16-roadStartX);
|
||||||
if (x<0)
|
if (x<0)
|
||||||
x=16;
|
x=16;
|
||||||
setCuboidRegion(0, x, 1, plotheight, 0, 16, getFilling(random));
|
setCuboidRegion(0, x, 1, plotheight, 0, 16, filling);
|
||||||
setCuboidRegion(0, x, plotheight,plotheight+1, 0, 16, getPlotFloor(random));
|
setCuboidRegion(0, x, plotheight,plotheight+1, 0, 16, plotfloors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -353,8 +377,8 @@ public class WorldGenerator extends ChunkGenerator {
|
|||||||
int x = (int) (16-roadStartX);
|
int x = (int) (16-roadStartX);
|
||||||
if (x<0)
|
if (x<0)
|
||||||
x=16;
|
x=16;
|
||||||
setCuboidRegion(0, x, 1, plotheight, 16-plotMinZ, 16, getFilling(random));
|
setCuboidRegion(0, x, 1, plotheight, 16-plotMinZ, 16, filling);
|
||||||
setCuboidRegion(0, x, plotheight, plotheight+1, 16-plotMinZ, 16, getPlotFloor(random));
|
setCuboidRegion(0, x, plotheight, plotheight+1, 16-plotMinZ, 16, plotfloors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -366,12 +390,12 @@ public class WorldGenerator extends ChunkGenerator {
|
|||||||
if (z<0)
|
if (z<0)
|
||||||
z=16;
|
z=16;
|
||||||
if (roadStartX>16) {
|
if (roadStartX>16) {
|
||||||
setCuboidRegion(0, x, 1, plotheight, 0, z, getFilling(random));
|
setCuboidRegion(0, x, 1, plotheight, 0, z, filling);
|
||||||
setCuboidRegion(0, x, plotheight, plotheight+1, 0, z, getPlotFloor(random));
|
setCuboidRegion(0, x, plotheight, plotheight+1, 0, z, plotfloors);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setCuboidRegion(0, x, 1, plotheight, 0, z, getFilling(random));
|
setCuboidRegion(0, x, 1, plotheight, 0, z, filling);
|
||||||
setCuboidRegion(0, x, plotheight, plotheight+1, 0, z, getPlotFloor(random));
|
setCuboidRegion(0, x, plotheight, plotheight+1, 0, z, plotfloors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -380,22 +404,22 @@ public class WorldGenerator extends ChunkGenerator {
|
|||||||
else {
|
else {
|
||||||
if (roadStartX<=16) {
|
if (roadStartX<=16) {
|
||||||
if (roadStartZ<=16) {
|
if (roadStartZ<=16) {
|
||||||
setCuboidRegion(0, 16-roadStartX, 1, plotheight, 0, 16-roadStartZ, getFilling(random));
|
setCuboidRegion(0, 16-roadStartX, 1, plotheight, 0, 16-roadStartZ, filling);
|
||||||
setCuboidRegion(0, 16-roadStartX, plotheight, plotheight+1, 0, 16-roadStartZ, getPlotFloor(random));
|
setCuboidRegion(0, 16-roadStartX, plotheight, plotheight+1, 0, 16-roadStartZ, plotfloors);
|
||||||
}
|
}
|
||||||
if (plotMinZ<=16) {
|
if (plotMinZ<=16) {
|
||||||
setCuboidRegion(0, 16-roadStartX, 1, plotheight, 16-plotMinZ, 16, getFilling(random));
|
setCuboidRegion(0, 16-roadStartX, 1, plotheight, 16-plotMinZ, 16, filling);
|
||||||
setCuboidRegion(0, 16-roadStartX, plotheight, plotheight+1, 16-plotMinZ, 16, getPlotFloor(random));
|
setCuboidRegion(0, 16-roadStartX, plotheight, plotheight+1, 16-plotMinZ, 16, plotfloors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (plotMinX<=16) {
|
if (plotMinX<=16) {
|
||||||
if (plotMinZ<=16) {
|
if (plotMinZ<=16) {
|
||||||
setCuboidRegion(16-plotMinX, 16, 1, plotheight, 16-plotMinZ, 16, getFilling(random));
|
setCuboidRegion(16-plotMinX, 16, 1, plotheight, 16-plotMinZ, 16, filling);
|
||||||
setCuboidRegion(16-plotMinX, 16, plotheight, plotheight+1, 16-plotMinZ, 16, getPlotFloor(random));
|
setCuboidRegion(16-plotMinX, 16, plotheight, plotheight+1, 16-plotMinZ, 16, plotfloors);
|
||||||
}
|
}
|
||||||
if (roadStartZ<=16) {
|
if (roadStartZ<=16) {
|
||||||
setCuboidRegion(16-plotMinX, 16, 1, plotheight, 0, 16-roadStartZ, getFilling(random));
|
setCuboidRegion(16-plotMinX, 16, 1, plotheight, 0, 16-roadStartZ, filling);
|
||||||
setCuboidRegion(16-plotMinX, 16, plotheight, plotheight+1, 0, 16-roadStartZ, getPlotFloor(random));
|
setCuboidRegion(16-plotMinX, 16, plotheight, plotheight+1, 0, 16-roadStartZ, plotfloors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -478,10 +502,6 @@ public class WorldGenerator extends ChunkGenerator {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings({ "deprecation", "unused" })
|
@SuppressWarnings({ "deprecation", "unused" })
|
||||||
private void setBlock(short[][] result, int x, int y, int z,
|
private void setBlock(short[][] result, int x, int y, int z,
|
||||||
Material material) {
|
Material material) {
|
||||||
|
@ -14,30 +14,55 @@ import java.util.Random;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class XPopulator extends BlockPopulator {
|
public class XPopulator extends BlockPopulator {
|
||||||
private SetBlockFast setBlockClass = null;
|
private int X;
|
||||||
public XPopulator() {
|
private int Z;
|
||||||
try {
|
private long state;
|
||||||
setBlockClass = new SetBlockFast();
|
public final long nextLong() {
|
||||||
}
|
long a=state;
|
||||||
catch (NoClassDefFoundError e) {
|
state = xorShift64(a);
|
||||||
PlotMain.sendConsoleSenderMessage(C.PREFIX.s() + "&cFast plot clearing is currently not enabled.");
|
return a;
|
||||||
PlotMain.sendConsoleSenderMessage(C.PREFIX.s() + "&c - Please get PlotSquared for "+Bukkit.getVersion()+" for improved performance");
|
}
|
||||||
}
|
|
||||||
|
public final long xorShift64(long a) {
|
||||||
|
a ^= (a << 21);
|
||||||
|
a ^= (a >>> 35);
|
||||||
|
a ^= (a << 4);
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final int random(int n) {
|
||||||
|
long result=((nextLong()>>>32)*n)>>32;
|
||||||
|
return (int) result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCuboidRegion(int x1,int x2, int y1, int y2, int z1, int z2, short id, byte data, World w) {
|
public void setCuboidRegion(int x1,int x2, int y1, int y2, int z1, int z2, short id, byte data, World w) {
|
||||||
if (data!=0) {
|
if (data==0)
|
||||||
for (int x = x1; x < x2; x++) {
|
return;
|
||||||
for (int z = z1; z < z2; z++) {
|
for (int x = x1; x < x2; x++) {
|
||||||
for (int y = y1; y < y2; y++) {
|
for (int z = z1; z < z2; z++) {
|
||||||
if (w.getBlockTypeIdAt(x, y, z)==id)
|
for (int y = y1; y < y2; y++) {
|
||||||
setBlock(w, x, y, z, id, data);
|
setBlock(w, x, y, z, id, data);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void setCuboidRegion(int x1, int x2, int y1, int y2, int z1, int z2, short[] id, short[] v, World w) {
|
||||||
|
if (id.length==1) {
|
||||||
|
setCuboidRegion(x1,x2,y1,y2,z1,z2,id[0],(byte) v[0],w);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (int x = x1; x < x2; x++) {
|
||||||
|
for (int z = z1; z < z2; z++) {
|
||||||
|
for (int y = y1; y < y2; y++) {
|
||||||
|
int i = random(id.length);
|
||||||
|
if (v[i]!=0)
|
||||||
|
setBlock(w, x, y, z, id[i], (byte) v[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
public short[] getBlock(String block) {
|
public short[] getBlock(String block) {
|
||||||
if (block.contains(":")) {
|
if (block.contains(":")) {
|
||||||
String[] split = block.split(":");
|
String[] split = block.split(":");
|
||||||
@ -46,52 +71,75 @@ public class XPopulator extends BlockPopulator {
|
|||||||
return new short[] {Short.parseShort(block),0};
|
return new short[] {Short.parseShort(block),0};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private int plotsize, pathsize, plotheight, wallheight, roadheight, size;
|
||||||
public void populate(World w, Random r, Chunk c) {
|
private byte w_v, f1_v, wf_v, f2_v;
|
||||||
PlotWorld plotworld = PlotMain.getWorldSettings(w);
|
private short w_id, f1_id, wf_id, f2_id;
|
||||||
|
private short[] p_id, p_v, f_id, f_v;
|
||||||
|
private double pathWidthLower;
|
||||||
|
private PlotWorld plotworld;
|
||||||
|
public XPopulator(PlotWorld plotworld) {
|
||||||
|
this.plotworld = plotworld;
|
||||||
|
plotsize = plotworld.PLOT_WIDTH;
|
||||||
|
pathsize = plotworld.ROAD_WIDTH;
|
||||||
|
plotheight = plotworld.PLOT_HEIGHT;
|
||||||
|
wallheight = plotworld.WALL_HEIGHT;
|
||||||
|
roadheight = plotworld.ROAD_HEIGHT;
|
||||||
|
size = pathsize + plotsize;
|
||||||
|
// WALL
|
||||||
|
short[] result_w = getBlock(plotworld.WALL_BLOCK);
|
||||||
|
w_id = result_w[0];
|
||||||
|
w_v = (byte) result_w[1];
|
||||||
|
|
||||||
int plotsize = plotworld.PLOT_WIDTH;
|
// WALL FILLING
|
||||||
int pathsize = plotworld.ROAD_WIDTH;
|
short[] result_wf = getBlock(plotworld.WALL_FILLING);
|
||||||
int wallheight = plotworld.WALL_HEIGHT;
|
wf_id = result_wf[0];
|
||||||
int roadheight = plotworld.ROAD_HEIGHT;
|
|
||||||
// int plotheight = plotworld.PLOT_HEIGHT;
|
|
||||||
int size = pathsize + plotsize;
|
|
||||||
byte w_v, f1_v, wf_v, f2_v;
|
|
||||||
|
|
||||||
short w_id, f1_id, wf_id, f2_id;
|
|
||||||
|
|
||||||
// WALL
|
|
||||||
short[] result_w = getBlock(plotworld.WALL_BLOCK);
|
|
||||||
w_id = result_w[0];
|
|
||||||
w_v = (byte) result_w[1];
|
|
||||||
|
|
||||||
// WALL FILLING
|
|
||||||
short[] result_wf = getBlock(plotworld.WALL_FILLING);
|
|
||||||
wf_id = result_wf[0];
|
|
||||||
wf_v = (byte) result_wf[1];
|
wf_v = (byte) result_wf[1];
|
||||||
|
|
||||||
// ROAD
|
// ROAD
|
||||||
short[] result_f1 = getBlock(plotworld.ROAD_BLOCK);
|
short[] result_f1 = getBlock(plotworld.ROAD_BLOCK);
|
||||||
f1_id = result_f1[0];
|
f1_id = result_f1[0];
|
||||||
f1_v = (byte) result_f1[1];
|
f1_v = (byte) result_f1[1];
|
||||||
//
|
//
|
||||||
|
|
||||||
// Floor 2
|
// Floor 2
|
||||||
short[] result_f2 = getBlock(plotworld.ROAD_STRIPES);
|
short[] result_f2 = getBlock(plotworld.ROAD_STRIPES);
|
||||||
f2_id = result_f2[0];
|
f2_id = result_f2[0];
|
||||||
f2_v = (byte) result_f1[1];
|
f2_v = (byte) result_f1[1];
|
||||||
//
|
//
|
||||||
|
|
||||||
int cx = c.getX(), cz = c.getZ();
|
p_id = new short[plotworld.MAIN_BLOCK.length];
|
||||||
|
p_v = new short[plotworld.MAIN_BLOCK.length];
|
||||||
double pathWidthLower;
|
f_id = new short[plotworld.TOP_BLOCK.length];
|
||||||
|
f_v = new short[plotworld.TOP_BLOCK.length];
|
||||||
|
for (int i = 0; i < plotworld.MAIN_BLOCK.length; i++) {
|
||||||
|
short[] result = getBlock(plotworld.MAIN_BLOCK[i]);
|
||||||
|
p_id[i] = result[0];
|
||||||
|
p_v[i] = result[1];
|
||||||
|
}
|
||||||
|
for (int i = 0; i < plotworld.TOP_BLOCK.length; i++) {
|
||||||
|
short[] result = getBlock(plotworld.TOP_BLOCK[i]);
|
||||||
|
f_id[i] = result[0];
|
||||||
|
f_v[i] = result[1];
|
||||||
|
}
|
||||||
pathWidthLower = Math.floor(pathsize/2);
|
pathWidthLower = Math.floor(pathsize/2);
|
||||||
if (cx<0)
|
}
|
||||||
cx+=((-cx)*(size));
|
|
||||||
if (cz<0)
|
@Override
|
||||||
cz+=((-cz)*(size));
|
public void populate(World w, Random r, Chunk c) {
|
||||||
double absX = (cx*16+16-pathWidthLower-1+8*size);
|
int cx = c.getX(), cz = c.getZ();
|
||||||
double absZ = (cz*16+16-pathWidthLower-1+8*size);
|
|
||||||
|
final int prime = 31;
|
||||||
|
int h = 1;
|
||||||
|
h = prime * h + cx;
|
||||||
|
h = prime * h + cz;
|
||||||
|
state = h;
|
||||||
|
|
||||||
|
|
||||||
|
X = cx << 4;
|
||||||
|
Z = cz << 4;
|
||||||
|
cx=cx%size+8*size;
|
||||||
|
cz=cz%size+8*size;
|
||||||
|
double absX = (cx*16+16-pathWidthLower-1+8*size), absZ = (cz*16+16-pathWidthLower-1+8*size);
|
||||||
int plotMinX = (int) (((absX)%size));
|
int plotMinX = (int) (((absX)%size));
|
||||||
int plotMinZ = (int) (((absZ)%size));
|
int plotMinZ = (int) (((absZ)%size));
|
||||||
int roadStartX = (plotMinX + pathsize);
|
int roadStartX = (plotMinX + pathsize);
|
||||||
@ -118,9 +166,10 @@ public class XPopulator extends BlockPopulator {
|
|||||||
setCuboidRegion(Math.max(start,0), Math.min(16,end), 1, roadheight+1, 0, 16, f1_id, f1_v, w);
|
setCuboidRegion(Math.max(start,0), Math.min(16,end), 1, roadheight+1, 0, 16, f1_id, f1_v, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// STRIPES
|
||||||
if (pathsize>4) {
|
if (pathsize>4) {
|
||||||
if ((plotMinZ+2)%size<=16) {
|
if ((plotMinZ+2)<=16) {
|
||||||
int value = (plotMinZ+2)%size;
|
int value = (plotMinZ+2);
|
||||||
int start,end;
|
int start,end;
|
||||||
if (plotMinX+2<=16)
|
if (plotMinX+2<=16)
|
||||||
start = 16-plotMinX-1;
|
start = 16-plotMinX-1;
|
||||||
@ -133,8 +182,8 @@ public class XPopulator extends BlockPopulator {
|
|||||||
if (!(plotMinX+2<=16||roadStartX-1<=16)) {
|
if (!(plotMinX+2<=16||roadStartX-1<=16)) {
|
||||||
start = 0;
|
start = 0;
|
||||||
}
|
}
|
||||||
setCuboidRegion(0, end, wallheight, wallheight+1, 16-value, 16-value+1, f2_id, f2_v, w); //
|
setCuboidRegion(0, end, roadheight, roadheight+1, 16-value, 16-value+1, f2_id, f2_v, w); //
|
||||||
setCuboidRegion(start, 16, wallheight, wallheight+1, 16-value, 16-value+1, f2_id, f2_v, w); //
|
setCuboidRegion(start, 16, roadheight, roadheight+1, 16-value, 16-value+1, f2_id, f2_v, w); //
|
||||||
}
|
}
|
||||||
if ((plotMinX+2)%size<=16) {
|
if ((plotMinX+2)%size<=16) {
|
||||||
int value = (plotMinX+2)%size;
|
int value = (plotMinX+2)%size;
|
||||||
@ -150,13 +199,11 @@ public class XPopulator extends BlockPopulator {
|
|||||||
if (!(plotMinZ+2<=16||roadStartZ-1<=16)) {
|
if (!(plotMinZ+2<=16||roadStartZ-1<=16)) {
|
||||||
start = 0;
|
start = 0;
|
||||||
}
|
}
|
||||||
setCuboidRegion( 16-value, 16-value+1,wallheight, wallheight+1, 0, end, f2_id, f2_v, w); //
|
setCuboidRegion( 16-value, 16-value+1,roadheight, roadheight+1, 0, end, f2_id, f2_v, w); //
|
||||||
setCuboidRegion( 16-value, 16-value+1, wallheight, wallheight+1,start, 16, f2_id, f2_v, w); //
|
setCuboidRegion( 16-value, 16-value+1, roadheight, roadheight+1,start, 16, f2_id, f2_v, w); //
|
||||||
}
|
}
|
||||||
if (roadStartZ<=16&&roadStartZ>0) {
|
if (roadStartZ<=16&&roadStartZ>1) {
|
||||||
int val = roadStartZ;
|
int val = roadStartZ;
|
||||||
if (val==0)
|
|
||||||
val+=16-pathsize+2;
|
|
||||||
int start,end;
|
int start,end;
|
||||||
if (plotMinX+2<=16)
|
if (plotMinX+2<=16)
|
||||||
start = 16-plotMinX-1;
|
start = 16-plotMinX-1;
|
||||||
@ -169,8 +216,8 @@ public class XPopulator extends BlockPopulator {
|
|||||||
if (!(plotMinX+2<=16||roadStartX-1<=16)) {
|
if (!(plotMinX+2<=16||roadStartX-1<=16)) {
|
||||||
start = 0;
|
start = 0;
|
||||||
}
|
}
|
||||||
setCuboidRegion(0, end, wallheight, wallheight+1, 16-val+1, 16-val+2, f2_id, f2_v, w); //
|
setCuboidRegion(0, end, roadheight, roadheight+1, 16-val+1, 16-val+2, f2_id, f2_v, w);
|
||||||
setCuboidRegion(start, 16, wallheight, wallheight+1, 16-val+1, 16-val+2, f2_id, f2_v, w); //
|
setCuboidRegion(start, 16, roadheight, roadheight+1, 16-val+1, 16-val+2, f2_id, f2_v, w);
|
||||||
}
|
}
|
||||||
if (roadStartX<=16&&roadStartX>0) {
|
if (roadStartX<=16&&roadStartX>0) {
|
||||||
int val = roadStartX;
|
int val = roadStartX;
|
||||||
@ -188,11 +235,10 @@ public class XPopulator extends BlockPopulator {
|
|||||||
if (!(plotMinZ+2<=16||roadStartZ-1<=16)) {
|
if (!(plotMinZ+2<=16||roadStartZ-1<=16)) {
|
||||||
start = 0;
|
start = 0;
|
||||||
}
|
}
|
||||||
setCuboidRegion(16-val+1, 16-val+2, wallheight, wallheight+1, 0, end, f2_id, f2_v, w); //
|
setCuboidRegion(16-val+1, 16-val+2, roadheight, roadheight+1, 0, end, f2_id, f2_v, w); //
|
||||||
setCuboidRegion(16-val+1, 16-val+2, wallheight, wallheight+1, start, 16, f2_id, f2_v, w); //
|
setCuboidRegion(16-val+1, 16-val+2, roadheight, roadheight+1, start, 16, f2_id, f2_v, w); //
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WALLS
|
// WALLS
|
||||||
if (pathsize>0) {
|
if (pathsize>0) {
|
||||||
if (plotMinZ+1<=16) {
|
if (plotMinZ+1<=16) {
|
||||||
@ -269,22 +315,111 @@ public class XPopulator extends BlockPopulator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO PLOT MAIN - How are we going to do the IDs for the actual plot if we have randomized blocks...
|
// PLOT
|
||||||
// - possibly on plot claiming, we could regenerate using the xpopulator
|
|
||||||
|
if (plotsize>16) {
|
||||||
|
if (roadStartX<=16) {
|
||||||
|
if (roadStartZ<=16) {
|
||||||
|
setCuboidRegion(0, 16-roadStartX, 1, plotheight, 0, 16-roadStartZ, p_id, p_v, w);
|
||||||
|
setCuboidRegion(0, 16-roadStartX, plotheight, plotheight+1, 0, 16-roadStartZ, f_id, f_v, w);
|
||||||
|
}
|
||||||
|
if (plotMinZ<=16) {
|
||||||
|
setCuboidRegion(0, 16-roadStartX, 1, plotheight, 16-plotMinZ, 16, p_id, p_v, w);
|
||||||
|
setCuboidRegion(0, 16-roadStartX, plotheight, plotheight+1, 16-plotMinZ, 16, f_id, f_v, w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (roadStartZ<=16) {
|
||||||
|
if (plotMinX>16) {
|
||||||
|
setCuboidRegion(0, 16, 1, plotheight, 0, 16-roadStartZ, p_id, p_v, w);
|
||||||
|
setCuboidRegion(0, 16, plotheight, plotheight+1, 0, 16-roadStartZ, f_id, f_v, w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (plotMinX<=16) {
|
||||||
|
if (plotMinZ<=16) {
|
||||||
|
setCuboidRegion(16-plotMinX, 16, 1, plotheight, 16-plotMinZ, 16, p_id, p_v, w);
|
||||||
|
setCuboidRegion(16-plotMinX, 16, plotheight, plotheight+1, 16-plotMinZ, 16, f_id, f_v, w);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int z = (int) (16-roadStartZ);
|
||||||
|
if (z<0)
|
||||||
|
z=16;
|
||||||
|
setCuboidRegion(16-plotMinX, 16, 1, plotheight, 0, z, p_id, p_v, w);
|
||||||
|
setCuboidRegion(16-plotMinX, 16, plotheight, plotheight+1, 0, z, f_id, f_v, w);
|
||||||
|
}
|
||||||
|
if (roadStartZ<=16) {
|
||||||
|
setCuboidRegion(16-plotMinX, 16, 1, plotheight, 0, 16-roadStartZ, p_id, p_v, w);
|
||||||
|
setCuboidRegion(16-plotMinX, 16, plotheight, plotheight+1, 0, 16-roadStartZ, f_id, f_v, w);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (roadStartX<=16) {
|
||||||
|
if (plotMinZ>16) {
|
||||||
|
int x = (int) (16-roadStartX);
|
||||||
|
if (x<0)
|
||||||
|
x=16;
|
||||||
|
setCuboidRegion(0, x, 1, plotheight, 0, 16, p_id, p_v, w);
|
||||||
|
setCuboidRegion(0, x, plotheight,plotheight+1, 0, 16, f_id, f_v, w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (plotMinZ<=16) {
|
||||||
|
if (roadStartX>16) {
|
||||||
|
int x = (int) (16-roadStartX);
|
||||||
|
if (x<0)
|
||||||
|
x=16;
|
||||||
|
setCuboidRegion(0, x, 1, plotheight, 16-plotMinZ, 16, p_id, p_v, w);
|
||||||
|
setCuboidRegion(0, x, plotheight, plotheight+1, 16-plotMinZ, 16, f_id, f_v, w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (roadStartZ>16) {
|
||||||
|
int x = (int) (16-roadStartX);
|
||||||
|
if (x<0)
|
||||||
|
x=16;
|
||||||
|
int z = (int) (16-roadStartZ);
|
||||||
|
if (z<0)
|
||||||
|
z=16;
|
||||||
|
if (roadStartX>16) {
|
||||||
|
setCuboidRegion(0, x, 1, plotheight, 0, z, p_id, p_v, w);
|
||||||
|
setCuboidRegion(0, x, plotheight, plotheight+1, 0, z, f_id, f_v, w);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setCuboidRegion(0, x, 1, plotheight, 0, z, p_id, p_v, w);
|
||||||
|
setCuboidRegion(0, x, plotheight, plotheight+1, 0, z, f_id, f_v, w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (roadStartX<=16) {
|
||||||
|
if (roadStartZ<=16) {
|
||||||
|
setCuboidRegion(0, 16-roadStartX, 1, plotheight, 0, 16-roadStartZ, p_id, p_v, w);
|
||||||
|
setCuboidRegion(0, 16-roadStartX, plotheight, plotheight+1, 0, 16-roadStartZ, f_id, f_v, w);
|
||||||
|
}
|
||||||
|
if (plotMinZ<=16) {
|
||||||
|
setCuboidRegion(0, 16-roadStartX, 1, plotheight, 16-plotMinZ, 16, p_id, p_v, w);
|
||||||
|
setCuboidRegion(0, 16-roadStartX, plotheight, plotheight+1, 16-plotMinZ, 16, f_id, f_v, w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (plotMinX<=16) {
|
||||||
|
if (plotMinZ<=16) {
|
||||||
|
setCuboidRegion(16-plotMinX, 16, 1, plotheight, 16-plotMinZ, 16, p_id, p_v, w);
|
||||||
|
setCuboidRegion(16-plotMinX, 16, plotheight, plotheight+1, 16-plotMinZ, 16, f_id, f_v, w);
|
||||||
|
}
|
||||||
|
if (roadStartZ<=16) {
|
||||||
|
setCuboidRegion(16-plotMinX, 16, 1, plotheight, 0, 16-roadStartZ, p_id, p_v, w);
|
||||||
|
setCuboidRegion(16-plotMinX, 16, plotheight, plotheight+1, 0, 16-roadStartZ, f_id, f_v, w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
private void setBlock(World w, int x, int y, int z, short id, byte val) {
|
||||||
private void setBlock(World w, int x, int y, int z, short id, byte val) {
|
w.getBlockAt(X+x, y, Z+z).setData(val, false);
|
||||||
if (setBlockClass!=null) {
|
|
||||||
setBlockClass.set(w, x, y, z, id, val);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (val != 0) {
|
|
||||||
w.getBlockAt(x, y, z).setTypeIdAndData(id, val, false);
|
|
||||||
} else {
|
|
||||||
w.getBlockAt(x, y, z).setTypeId(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user