From 0d55e1a2dc09583a26606688b7eed4c8bdd85b6c Mon Sep 17 00:00:00 2001 From: boy0001 Date: Wed, 8 Oct 2014 16:53:09 +1100 Subject: [PATCH] Continued externalization of generators. - Please ignore all the errors, I am not commiting all the classes I have changed. --- .../plot/Configuration.java | 176 +++++++ .../plot/ConfigurationNode.java | 4 +- .../intellectualcrafters/plot/PlotBlock.java | 4 +- .../plot/PlotGenerator.java | 16 + .../plot/commands/plugin.java | 2 +- .../plot/generator/DefaultPlotGenerator.java | 13 +- .../plot/generator/DefaultPlotManager.java | 2 +- .../plot/generator/DefaultPlotWorld.java | 73 ++- .../plot/generator/WorldGenerator.java | 468 ++++++++++++++++++ .../plot/generator/XPopulator.java | 467 +++++++++++++++++ 10 files changed, 1194 insertions(+), 31 deletions(-) create mode 100644 PlotSquared/src/com/intellectualcrafters/plot/Configuration.java create mode 100644 PlotSquared/src/com/intellectualcrafters/plot/PlotGenerator.java create mode 100644 PlotSquared/src/com/intellectualcrafters/plot/generator/WorldGenerator.java create mode 100644 PlotSquared/src/com/intellectualcrafters/plot/generator/XPopulator.java diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Configuration.java b/PlotSquared/src/com/intellectualcrafters/plot/Configuration.java new file mode 100644 index 000000000..9dd54c72d --- /dev/null +++ b/PlotSquared/src/com/intellectualcrafters/plot/Configuration.java @@ -0,0 +1,176 @@ +package com.intellectualcrafters.plot; + +import org.bukkit.block.Biome; + +public class Configuration { + public static final SettingValue STRING = new SettingValue("STRING") { + @Override + public boolean validateValue(String string) { + return true; + } + + @Override + public Object parseString(String string) { + return string; + } + }; + + public static final SettingValue STRINGLIST = new SettingValue("STRINGLIST") { + @Override + public boolean validateValue(String string) { + return true; + } + + @Override + public Object parseString(String string) { + return string.split(","); + } + }; + + public static final SettingValue INTEGER = new SettingValue("INTEGER") { + @Override + public boolean validateValue(String string) { + try { + Integer.parseInt(string); + return true; + } catch (Exception e) { + return false; + } + } + + @Override + public Object parseString(String string) { + return Integer.parseInt(string); + } + }; + + public static final SettingValue BOOLEAN = new SettingValue("BOOLEAN") { + @Override + public boolean validateValue(String string) { + try { + Boolean.parseBoolean(string); + return true; + } catch (Exception e) { + return false; + } + } + + @Override + public Object parseString(String string) { + return Boolean.parseBoolean(string); + } + }; + + public static final SettingValue DOUBLE = new SettingValue("DOUBLE") { + @Override + public boolean validateValue(String string) { + try { + Double.parseDouble(string); + return true; + } catch (Exception e) { + return false; + } + } + + @Override + public Object parseString(String string) { + return Double.parseDouble(string); + } + }; + + public static final SettingValue BIOME = new SettingValue("BIOME") { + @Override + public boolean validateValue(String string) { + try { + Biome.valueOf(string.toUpperCase()); + return true; + } catch (Exception e) { + return false; + } + } + + @Override + public Object parseString(String string) { + return Biome.valueOf(string.toUpperCase()); + } + }; + + public static final SettingValue BLOCK = new SettingValue("BLOCK") { + @Override + public boolean validateValue(String string) { + try { + if (string.contains(":")) { + String[] split = string.split(":"); + Short.parseShort(split[0]); + Short.parseShort(split[1]); + } else { + Short.parseShort(string); + } + return true; + } catch (Exception e) { + return false; + } + } + + @Override + public Object parseString(String string) { + if (string.contains(":")) { + String[] split = string.split(":"); + return new PlotBlock(Short.parseShort(split[0]), Byte.parseByte(split[1])); + } else { + return new PlotBlock(Short.parseShort(string), (byte) 0); + } + } + }; + + public static final SettingValue BLOCKLIST = new SettingValue("BLOCKLIST") { + @Override + public boolean validateValue(String string) { + try { + for (String block : string.split(",")) { + if (block.contains(":")) { + String[] split = block.split(":"); + Short.parseShort(split[0]); + Short.parseShort(split[1]); + } else { + Short.parseShort(block); + } + } + return true; + } catch (Exception e) { + return false; + } + } + + @Override + public Object parseString(String string) { + String[] blocks = string.split(","); + PlotBlock[] values = new PlotBlock[blocks.length]; + for (int i = 0; i>> 35); + a ^= (a << 4); + return a; + } + + public final int random(int n) { + long r = ((nextLong() >>> 32) * n) >> 32; + return (int) r; + } + + DefaultPlotWorld plotworld; + short[][] result; + int plotsize; + int pathsize; + PlotBlock wall; + PlotBlock wallfilling; + PlotBlock floor1; + PlotBlock floor2; + int size; + Biome biome; + int roadheight; + int wallheight; + int plotheight; + + PlotBlock[] plotfloors; + PlotBlock[] filling; + + public Short getBlock(String block) { + if (block.contains(":")) { + String[] split = block.split(":"); + return Short.parseShort(split[0]); + } + return Short.parseShort(block); + } + + public WorldGenerator(PlotWorld pw, String world) { + + // + this.plotworld = (DefaultPlotWorld) pw; + + // save configuration + + plotsize = plotworld.PLOT_WIDTH; + pathsize = plotworld.ROAD_WIDTH; + + floor1 = plotworld.ROAD_BLOCK; + floor2 = plotworld.ROAD_STRIPES; + + wallfilling = plotworld.WALL_FILLING; + size = pathsize + plotsize; + wall = plotworld.WALL_BLOCK; + + plotfloors = plotworld.TOP_BLOCK; + filling = plotworld.MAIN_BLOCK; + wallheight = plotworld.WALL_HEIGHT; + roadheight = plotworld.ROAD_HEIGHT; + plotheight = plotworld.PLOT_HEIGHT; + + biome = plotworld.PLOT_BIOME; + } + + @Override + public List getDefaultPopulators(World world) { + world.setSpawnFlags(false, false); + return Arrays.asList((BlockPopulator) new XPopulator(plotworld)); + } + + @Override + public Location getFixedSpawnLocation(World world, Random random) { + return new Location(world, 0, plotworld.ROAD_HEIGHT + 2, 0); + } + + public void setCuboidRegion(int x1, int x2, int y1, int y2, int z1, int z2, PlotBlock block) { + for (int x = x1; x < x2; x++) { + for (int z = z1; z < z2; z++) { + for (int y = y1; y < y2; y++) { + setBlock(this.result, x, y, z, block.data); + } + } + } + } + + private void setCuboidRegion(int x1, int x2, int y1, int y2, int z1, int z2, PlotBlock[] blocks) { + if (blocks.length == 1) { + setCuboidRegion(x1, x2, y1, y2, z1, z2, blocks[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(blocks.length); + setBlock(this.result, x, y, z, blocks[i].id); + } + } + } + } + + } + + @Override + public short[][] generateExtBlockSections(World world, Random random, int cx, int cz, BiomeGrid biomes) { + + final int prime = 31; + int h = 1; + h = (prime * h) + cx; + h = (prime * h) + cz; + this.state = h; + + int maxY = world.getMaxHeight(); + + this.result = new short[maxY / 16][]; + double pathWidthLower; + if ((this.pathsize % 2) == 0) { + pathWidthLower = Math.floor(this.pathsize / 2) - 1; + } else { + pathWidthLower = Math.floor(this.pathsize / 2); + } + + cx = (cx % this.size) + (8 * this.size); + cz = (cz % this.size) + (8 * this.size); + int absX = (int) ((((cx * 16) + 16) - pathWidthLower - 1) + (8 * this.size)); + int absZ = (int) ((((cz * 16) + 16) - pathWidthLower - 1) + (8 * this.size)); + int plotMinX = (((absX) % this.size)); + int plotMinZ = (((absZ) % this.size)); + int roadStartX = (plotMinX + this.pathsize); + int roadStartZ = (plotMinZ + this.pathsize); + if (roadStartX >= this.size) { + roadStartX -= this.size; + } + if (roadStartZ >= this.size) { + roadStartZ -= this.size; + } + + // BOTTOM (1/1 cuboids) + for (int x = 0; x < 16; x++) { + for (int z = 0; z < 16; z++) { + setBlock(this.result, x, 0, z, (short) 7); + biomes.setBiome(x, z, this.biome); + } + } + // ROAD (0/24) The following is an inefficient placeholder as it is too + // much work to finish it + + if ((this.pathsize > 16) && ((plotMinX > roadStartX) || (plotMinZ > roadStartZ)) && !((roadStartX < 16) && (roadStartZ < 16)) && (((roadStartX > 16) && (roadStartZ > 16)) || ((plotMinX > roadStartX) && (plotMinZ > roadStartZ)))) { + setCuboidRegion(0, 16, 1, this.roadheight + 1, 0, 16, this.floor1); + return this.result; + } + + if (((plotMinZ + 1) <= 16) || ((roadStartZ <= 16) && (roadStartZ > 0))) { + int start = Math.max((16 - plotMinZ - this.pathsize) + 1, (16 - roadStartZ) + 1); + int end = Math.min(16 - plotMinZ - 1, (16 - roadStartZ) + this.pathsize); + if ((start >= 0) && (start <= 16) && (end < 0)) { + end = 16; + } + setCuboidRegion(0, 16, 1, this.roadheight + 1, Math.max(start, 0), Math.min(16, end), this.floor1); + } + if (((plotMinX + 1) <= 16) || ((roadStartX <= 16) && (roadStartX > 0))) { + int start = Math.max((16 - plotMinX - this.pathsize) + 1, (16 - roadStartX) + 1); + int end = Math.min(16 - plotMinX - 1, (16 - roadStartX) + this.pathsize); + if ((start >= 0) && (start <= 16) && (end < 0)) { + end = 16; + } + setCuboidRegion(Math.max(start, 0), Math.min(16, end), 1, this.roadheight + 1, 0, 16, this.floor1); + } + + // ROAD STRIPES + if ((this.pathsize > 4) && this.plotworld.ROAD_STRIPES_ENABLED) { + if ((plotMinZ + 2) <= 16) { + int value = (plotMinZ + 2); + int start, end; + if ((plotMinX + 2) <= 16) { + start = 16 - plotMinX - 1; + } else { + start = 16; + } + if ((roadStartX - 1) <= 16) { + end = (16 - roadStartX) + 1; + } else { + end = 0; + } + if (!(((plotMinX + 2) <= 16) || ((roadStartX - 1) <= 16))) { + start = 0; + } + setCuboidRegion(0, end, this.wallheight, this.wallheight + 1, 16 - value, (16 - value) + 1, this.floor2); // + setCuboidRegion(start, 16, this.wallheight, this.wallheight + 1, 16 - value, (16 - value) + 1, this.floor2); // + } + if ((plotMinX + 2) <= 16) { + int value = (plotMinX + 2); + int start, end; + if ((plotMinZ + 2) <= 16) { + start = 16 - plotMinZ - 1; + } else { + start = 16; + } + if ((roadStartZ - 1) <= 16) { + end = (16 - roadStartZ) + 1; + } else { + end = 0; + } + if (!(((plotMinZ + 2) <= 16) || ((roadStartZ - 1) <= 16))) { + start = 0; + } + setCuboidRegion(16 - value, (16 - value) + 1, this.wallheight, this.wallheight + 1, 0, end, this.floor2); // + setCuboidRegion(16 - value, (16 - value) + 1, this.wallheight, this.wallheight + 1, start, 16, this.floor2); // + } + if ((roadStartZ <= 16) && (roadStartZ > 1)) { + int val = roadStartZ; + int start, end; + if ((plotMinX + 2) <= 16) { + start = 16 - plotMinX - 1; + } else { + start = 16; + } + if ((roadStartX - 1) <= 16) { + end = (16 - roadStartX) + 1; + } else { + end = 0; + } + if (!(((plotMinX + 2) <= 16) || ((roadStartX - 1) <= 16))) { + start = 0; + } + setCuboidRegion(0, end, this.wallheight, this.wallheight + 1, (16 - val) + 1, (16 - val) + 2, this.floor2); + setCuboidRegion(start, 16, this.wallheight, this.wallheight + 1, (16 - val) + 1, (16 - val) + 2, this.floor2); + } + if ((roadStartX <= 16) && (roadStartX > 1)) { + int val = roadStartX; + int start, end; + if ((plotMinZ + 2) <= 16) { + start = 16 - plotMinZ - 1; + } else { + start = 16; + } + if ((roadStartZ - 1) <= 16) { + end = (16 - roadStartZ) + 1; + } else { + end = 0; + } + if (!(((plotMinZ + 2) <= 16) || ((roadStartZ - 1) <= 16))) { + start = 0; + } + setCuboidRegion((16 - val) + 1, (16 - val) + 2, this.wallheight, this.wallheight + 1, 0, end, this.floor2); // + setCuboidRegion((16 - val) + 1, (16 - val) + 2, this.wallheight, this.wallheight + 1, start, 16, this.floor2); // + } + } + + // Plot filling (28/28 cuboids) (10x2 + 4x2) + if (this.plotsize > 16) { + if (roadStartX <= 16) { + if (roadStartZ <= 16) { + setCuboidRegion(0, 16 - roadStartX, 1, this.plotheight, 0, 16 - roadStartZ, this.filling); + setCuboidRegion(0, 16 - roadStartX, this.plotheight, this.plotheight + 1, 0, 16 - roadStartZ, this.plotfloors); + } + if (plotMinZ <= 16) { + setCuboidRegion(0, 16 - roadStartX, 1, this.plotheight, 16 - plotMinZ, 16, this.filling); + setCuboidRegion(0, 16 - roadStartX, this.plotheight, this.plotheight + 1, 16 - plotMinZ, 16, this.plotfloors); + } + } else { + if (roadStartZ <= 16) { + if (plotMinX > 16) { + setCuboidRegion(0, 16, 1, this.plotheight, 0, 16 - roadStartZ, this.filling); + setCuboidRegion(0, 16, this.plotheight, this.plotheight + 1, 0, 16 - roadStartZ, this.plotfloors); + } + } + } + if (plotMinX <= 16) { + if (plotMinZ <= 16) { + setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 16 - plotMinZ, 16, this.filling); + setCuboidRegion(16 - plotMinX, 16, this.plotheight, this.plotheight + 1, 16 - plotMinZ, 16, this.plotfloors); + } else { + int z = 16 - roadStartZ; + if (z < 0) { + z = 16; + } + setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 0, z, this.filling); + setCuboidRegion(16 - plotMinX, 16, this.plotheight, this.plotheight + 1, 0, z, this.plotfloors); + } + if (roadStartZ <= 16) { + setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 0, 16 - roadStartZ, this.filling); + setCuboidRegion(16 - plotMinX, 16, this.plotheight, this.plotheight + 1, 0, 16 - roadStartZ, this.plotfloors); + } else { + if (roadStartX <= 16) { + if (plotMinZ > 16) { + int x = 16 - roadStartX; + if (x < 0) { + x = 16; + } + setCuboidRegion(0, x, 1, this.plotheight, 0, 16, this.filling); + setCuboidRegion(0, x, this.plotheight, this.plotheight + 1, 0, 16, this.plotfloors); + } + } + } + } else { + if (plotMinZ <= 16) { + if (roadStartX > 16) { + int x = 16 - roadStartX; + if (x < 0) { + x = 16; + } + setCuboidRegion(0, x, 1, this.plotheight, 16 - plotMinZ, 16, this.filling); + setCuboidRegion(0, x, this.plotheight, this.plotheight + 1, 16 - plotMinZ, 16, this.plotfloors); + } + } else { + if (roadStartZ > 16) { + int x = 16 - roadStartX; + if (x < 0) { + x = 16; + } + int z = 16 - roadStartZ; + if (z < 0) { + z = 16; + } + if (roadStartX > 16) { + setCuboidRegion(0, x, 1, this.plotheight, 0, z, this.filling); + setCuboidRegion(0, x, this.plotheight, this.plotheight + 1, 0, z, this.plotfloors); + } else { + setCuboidRegion(0, x, 1, this.plotheight, 0, z, this.filling); + setCuboidRegion(0, x, this.plotheight, this.plotheight + 1, 0, z, this.plotfloors); + } + } + } + } + } else { + if (roadStartX <= 16) { + if (roadStartZ <= 16) { + setCuboidRegion(0, 16 - roadStartX, 1, this.plotheight, 0, 16 - roadStartZ, this.filling); + setCuboidRegion(0, 16 - roadStartX, this.plotheight, this.plotheight + 1, 0, 16 - roadStartZ, this.plotfloors); + } + if (plotMinZ <= 16) { + setCuboidRegion(0, 16 - roadStartX, 1, this.plotheight, 16 - plotMinZ, 16, this.filling); + setCuboidRegion(0, 16 - roadStartX, this.plotheight, this.plotheight + 1, 16 - plotMinZ, 16, this.plotfloors); + } + } + if (plotMinX <= 16) { + if (plotMinZ <= 16) { + setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 16 - plotMinZ, 16, this.filling); + setCuboidRegion(16 - plotMinX, 16, this.plotheight, this.plotheight + 1, 16 - plotMinZ, 16, this.plotfloors); + } + if (roadStartZ <= 16) { + setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 0, 16 - roadStartZ, this.filling); + setCuboidRegion(16 - plotMinX, 16, this.plotheight, this.plotheight + 1, 0, 16 - roadStartZ, this.plotfloors); + } + } + } + + // WALLS (16/16 cuboids) + if (this.pathsize > 0) { + if ((plotMinZ + 1) <= 16) { + int start, end; + if ((plotMinX + 2) <= 16) { + start = 16 - plotMinX - 1; + } else { + start = 16; + } + if ((roadStartX - 1) <= 16) { + end = (16 - roadStartX) + 1; + } else { + end = 0; + } + if (!(((plotMinX + 2) <= 16) || ((roadStartX - 1) <= 16))) { + start = 0; + } + setCuboidRegion(0, end, 1, this.wallheight + 1, 16 - plotMinZ - 1, 16 - plotMinZ, this.wallfilling); + setCuboidRegion(0, end, this.wallheight + 1, this.wallheight + 2, 16 - plotMinZ - 1, 16 - plotMinZ, this.wall); + setCuboidRegion(start, 16, 1, this.wallheight + 1, 16 - plotMinZ - 1, 16 - plotMinZ, this.wallfilling); + setCuboidRegion(start, 16, this.wallheight + 1, this.wallheight + 2, 16 - plotMinZ - 1, 16 - plotMinZ, this.wall); + } + if ((plotMinX + 1) <= 16) { + int start, end; + if ((plotMinZ + 2) <= 16) { + start = 16 - plotMinZ - 1; + } else { + start = 16; + } + if ((roadStartZ - 1) <= 16) { + end = (16 - roadStartZ) + 1; + } else { + end = 0; + } + if (!(((plotMinZ + 2) <= 16) || ((roadStartZ - 1) <= 16))) { + start = 0; + } + setCuboidRegion(16 - plotMinX - 1, 16 - plotMinX, 1, this.wallheight + 1, 0, end, this.wallfilling); + setCuboidRegion(16 - plotMinX - 1, 16 - plotMinX, this.wallheight + 1, this.wallheight + 2, 0, end, this.wall); + setCuboidRegion(16 - plotMinX - 1, 16 - plotMinX, 1, this.wallheight + 1, start, 16, this.wallfilling); + setCuboidRegion(16 - plotMinX - 1, 16 - plotMinX, this.wallheight + 1, this.wallheight + 2, start, 16, this.wall); + } + if ((roadStartZ <= 16) && (roadStartZ > 0)) { + int start, end; + if ((plotMinX + 1) <= 16) { + start = 16 - plotMinX; + } else { + start = 16; + } + if ((roadStartX + 1) <= 16) { + end = (16 - roadStartX) + 1; + } else { + end = 0; + } + if (!(((plotMinX + 1) <= 16) || (roadStartX <= 16))) { + start = 0; + } + setCuboidRegion(0, end, 1, this.wallheight + 1, 16 - roadStartZ, (16 - roadStartZ) + 1, this.wallfilling); + setCuboidRegion(0, end, this.wallheight + 1, this.wallheight + 2, 16 - roadStartZ, (16 - roadStartZ) + 1, this.wall); + setCuboidRegion(start, 16, 1, this.wallheight + 1, 16 - roadStartZ, (16 - roadStartZ) + 1, this.wallfilling); + setCuboidRegion(start, 16, this.wallheight + 1, this.wallheight + 2, 16 - roadStartZ, (16 - roadStartZ) + 1, this.wall); + } + if ((roadStartX <= 16) && (roadStartX > 0)) { + int start, end; + if ((plotMinZ + 1) <= 16) { + start = 16 - plotMinZ; + } else { + start = 16; + } + if ((roadStartZ + 1) <= 16) { + end = (16 - roadStartZ) + 1; + } else { + end = 0; + } + if (!(((plotMinZ + 1) <= 16) || ((roadStartZ + 1) <= 16))) { + start = 0; + } + setCuboidRegion(16 - roadStartX, (16 - roadStartX) + 1, 1, this.wallheight + 1, 0, end, this.wallfilling); + setCuboidRegion(16 - roadStartX, (16 - roadStartX) + 1, this.wallheight + 1, this.roadheight + 2, 0, end, this.wall); + setCuboidRegion(16 - roadStartX, (16 - roadStartX) + 1, 1, this.wallheight + 1, start, 16, this.wallfilling); + setCuboidRegion(16 - roadStartX, (16 - roadStartX) + 1, this.wallheight + 1, this.wallheight + 2, start, 16, this.wall); + } + } + return this.result; + } + + private void setBlock(short[][] result, int x, int y, int z, short blkid) { + if (result[y >> 4] == null) { + result[y >> 4] = new short[4096]; + } + result[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = blkid; + } +} diff --git a/PlotSquared/src/com/intellectualcrafters/plot/generator/XPopulator.java b/PlotSquared/src/com/intellectualcrafters/plot/generator/XPopulator.java new file mode 100644 index 000000000..a70ac9551 --- /dev/null +++ b/PlotSquared/src/com/intellectualcrafters/plot/generator/XPopulator.java @@ -0,0 +1,467 @@ +package com.intellectualcrafters.plot.generator; + +import java.util.Random; + +import org.bukkit.Chunk; +import org.bukkit.World; +import org.bukkit.generator.BlockPopulator; + +import com.intellectualcrafters.plot.PlotWorld; + +/** + * + * @author Citymonstret + * + */ +public class XPopulator extends BlockPopulator { + private int X; + private int Z; + private long state; + + public final long nextLong() { + 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(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) { + if (data == 0) { + return; + } + for (int x = x1; x < x2; x++) { + for (int z = z1; z < z2; z++) { + for (int y = y1; y < y2; y++) { + 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) { + if (block.contains(":")) { + String[] split = block.split(":"); + return new short[] { Short.parseShort(split[0]), Short.parseShort(split[1]) }; + } + return new short[] { Short.parseShort(block), 0 }; + } + + private int plotsize, pathsize, plotheight, wallheight, roadheight, size; + private byte w_v, f1_v, wf_v, f2_v; + private short w_id, f1_id, wf_id, f2_id; + private short[] p_id, p_v, f_id, f_v; + private double pathWidthLower; + private DefaultPlotWorld plotworld; + + public XPopulator(PlotWorld pw) { + this.plotworld = (DefaultPlotWorld) pw; + + // save configuration + + plotsize = plotworld.PLOT_WIDTH; + pathsize = plotworld.ROAD_WIDTH; + + floor1 = plotworld.ROAD_BLOCK; + floor2 = plotworld.ROAD_STRIPES; + + wallfilling = plotworld.WALL_FILLING; + size = pathsize + plotsize; + wall = plotworld.WALL_BLOCK; + + plotfloors = plotworld.TOP_BLOCK; + filling = plotworld.MAIN_BLOCK; + wallheight = plotworld.WALL_HEIGHT; + roadheight = plotworld.ROAD_HEIGHT; + plotheight = plotworld.PLOT_HEIGHT; + + // WALL + short[] result_w = getBlock(plotworld.WALL_BLOCK); + this.w_id = result_w[0]; + this.w_v = (byte) result_w[1]; + + // WALL FILLING + short[] result_wf = getBlock(plotworld.WALL_FILLING); + this.wf_id = result_wf[0]; + this.wf_v = (byte) result_wf[1]; + + // ROAD + short[] result_f1 = getBlock(plotworld.ROAD_BLOCK); + this.f1_id = result_f1[0]; + this.f1_v = (byte) result_f1[1]; + // + + // Floor 2 + short[] result_f2 = getBlock(plotworld.ROAD_STRIPES); + this.f2_id = result_f2[0]; + this.f2_v = (byte) result_f2[1]; + // + + this.p_id = new short[plotworld.MAIN_BLOCK.length]; + this.p_v = new short[plotworld.MAIN_BLOCK.length]; + this.f_id = new short[plotworld.TOP_BLOCK.length]; + this.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]); + this.p_id[i] = result[0]; + this.p_v[i] = result[1]; + } + for (int i = 0; i < plotworld.TOP_BLOCK.length; i++) { + short[] result = getBlock(plotworld.TOP_BLOCK[i]); + this.f_id[i] = result[0]; + this.f_v[i] = result[1]; + } + if ((this.pathsize % 2) == 0) { + this.pathWidthLower = Math.floor(this.pathsize / 2) - 1; + } else { + this.pathWidthLower = Math.floor(this.pathsize / 2); + } + } + + @Override + public void populate(World w, Random r, Chunk c) { + int cx = c.getX(), cz = c.getZ(); + + final int prime = 31; + int h = 1; + h = (prime * h) + cx; + h = (prime * h) + cz; + this.state = h; + + this.X = cx << 4; + this.Z = cz << 4; + cx = (cx % this.size) + (8 * this.size); + cz = (cz % this.size) + (8 * this.size); + double absX = ((((cx * 16) + 16) - this.pathWidthLower - 1) + (8 * this.size)), absZ = ((((cz * 16) + 16) - this.pathWidthLower - 1) + (8 * this.size)); + int plotMinX = (int) (((absX) % this.size)); + int plotMinZ = (int) (((absZ) % this.size)); + int roadStartX = (plotMinX + this.pathsize); + int roadStartZ = (plotMinZ + this.pathsize); + if (roadStartX >= this.size) { + roadStartX -= this.size; + } + if (roadStartZ >= this.size) { + roadStartZ -= this.size; + } + + // ROADS + + if ((this.pathsize > 16) && ((plotMinX > roadStartX) || (plotMinZ > roadStartZ)) && !((roadStartX < 16) && (roadStartZ < 16)) && (((roadStartX > 16) && (roadStartZ > 16)) || ((plotMinX > roadStartX) && (plotMinZ > roadStartZ)))) { + setCuboidRegion(0, 16, 1, this.roadheight + 1, 0, 16, this.f1_id, this.f1_v, w); + return; + } + + if (((plotMinZ + 1) <= 16) || ((roadStartZ <= 16) && (roadStartZ > 0))) { + int start = Math.max((16 - plotMinZ - this.pathsize) + 1, (16 - roadStartZ) + 1); + int end = Math.min(16 - plotMinZ - 1, (16 - roadStartZ) + this.pathsize); + if ((start >= 0) && (start <= 16) && (end < 0)) { + end = 16; + } + setCuboidRegion(0, 16, 1, this.roadheight + 1, Math.max(start, 0), Math.min(16, end), this.f1_id, this.f1_v, w); + } + if (((plotMinX + 1) <= 16) || ((roadStartX <= 16) && (roadStartX > 0))) { + int start = Math.max((16 - plotMinX - this.pathsize) + 1, (16 - roadStartX) + 1); + int end = Math.min(16 - plotMinX - 1, (16 - roadStartX) + this.pathsize); + if ((start >= 0) && (start <= 16) && (end < 0)) { + end = 16; + } + setCuboidRegion(Math.max(start, 0), Math.min(16, end), 1, this.roadheight + 1, 0, 16, this.f1_id, this.f1_v, w); + } + + // STRIPES + if ((this.pathsize > 4) && this.plotworld.ROAD_STRIPES_ENABLED) { + if ((plotMinZ + 2) <= 16) { + int value = (plotMinZ + 2); + int start, end; + if ((plotMinX + 2) <= 16) { + start = 16 - plotMinX - 1; + } else { + start = 16; + } + if ((roadStartX - 1) <= 16) { + end = (16 - roadStartX) + 1; + } else { + end = 0; + } + if (!(((plotMinX + 2) <= 16) || ((roadStartX - 1) <= 16))) { + start = 0; + } + setCuboidRegion(0, end, this.roadheight, this.roadheight + 1, 16 - value, (16 - value) + 1, this.f2_id, this.f2_v, w); // + setCuboidRegion(start, 16, this.roadheight, this.roadheight + 1, 16 - value, (16 - value) + 1, this.f2_id, this.f2_v, w); // + } + if ((plotMinX + 2) <= 16) { + int value = (plotMinX + 2); + int start, end; + if ((plotMinZ + 2) <= 16) { + start = 16 - plotMinZ - 1; + } else { + start = 16; + } + if ((roadStartZ - 1) <= 16) { + end = (16 - roadStartZ) + 1; + } else { + end = 0; + } + if (!(((plotMinZ + 2) <= 16) || ((roadStartZ - 1) <= 16))) { + start = 0; + } + setCuboidRegion(16 - value, (16 - value) + 1, this.roadheight, this.roadheight + 1, 0, end, this.f2_id, this.f2_v, w); // + setCuboidRegion(16 - value, (16 - value) + 1, this.roadheight, this.roadheight + 1, start, 16, this.f2_id, this.f2_v, w); // + } + if ((roadStartZ <= 16) && (roadStartZ > 1)) { + int val = roadStartZ; + int start, end; + if ((plotMinX + 2) <= 16) { + start = 16 - plotMinX - 1; + } else { + start = 16; + } + if ((roadStartX - 1) <= 16) { + end = (16 - roadStartX) + 1; + } else { + end = 0; + } + if (!(((plotMinX + 2) <= 16) || ((roadStartX - 1) <= 16))) { + start = 0; + } + setCuboidRegion(0, end, this.roadheight, this.roadheight + 1, (16 - val) + 1, (16 - val) + 2, this.f2_id, this.f2_v, w); + setCuboidRegion(start, 16, this.roadheight, this.roadheight + 1, (16 - val) + 1, (16 - val) + 2, this.f2_id, this.f2_v, w); + } + if ((roadStartX <= 16) && (roadStartX > 1)) { + int val = roadStartX; + int start, end; + if ((plotMinZ + 2) <= 16) { + start = 16 - plotMinZ - 1; + } else { + start = 16; + } + if ((roadStartZ - 1) <= 16) { + end = (16 - roadStartZ) + 1; + } else { + end = 0; + } + if (!(((plotMinZ + 2) <= 16) || ((roadStartZ - 1) <= 16))) { + start = 0; + } + setCuboidRegion((16 - val) + 1, (16 - val) + 2, this.roadheight, this.roadheight + 1, 0, end, this.f2_id, this.f2_v, w); // + setCuboidRegion((16 - val) + 1, (16 - val) + 2, this.roadheight, this.roadheight + 1, start, 16, this.f2_id, this.f2_v, w); // + } + } + // WALLS + if (this.pathsize > 0) { + if ((plotMinZ + 1) <= 16) { + int start, end; + if ((plotMinX + 2) <= 16) { + start = 16 - plotMinX - 1; + } else { + start = 16; + } + if ((roadStartX - 1) <= 16) { + end = (16 - roadStartX) + 1; + } else { + end = 0; + } + if (!(((plotMinX + 2) <= 16) || ((roadStartX - 1) <= 16))) { + start = 0; + } + setCuboidRegion(0, end, 1, this.wallheight + 1, 16 - plotMinZ - 1, 16 - plotMinZ, this.wf_id, this.wf_v, w); + setCuboidRegion(0, end, this.wallheight + 1, this.wallheight + 2, 16 - plotMinZ - 1, 16 - plotMinZ, this.w_id, this.w_v, w); + setCuboidRegion(start, 16, 1, this.wallheight + 1, 16 - plotMinZ - 1, 16 - plotMinZ, this.wf_id, this.wf_v, w); + setCuboidRegion(start, 16, this.wallheight + 1, this.wallheight + 2, 16 - plotMinZ - 1, 16 - plotMinZ, this.w_id, this.w_v, w); + } + if ((plotMinX + 1) <= 16) { + int start, end; + if ((plotMinZ + 2) <= 16) { + start = 16 - plotMinZ - 1; + } else { + start = 16; + } + if ((roadStartZ - 1) <= 16) { + end = (16 - roadStartZ) + 1; + } else { + end = 0; + } + if (!(((plotMinZ + 2) <= 16) || ((roadStartZ - 1) <= 16))) { + start = 0; + } + setCuboidRegion(16 - plotMinX - 1, 16 - plotMinX, 1, this.wallheight + 1, 0, end, this.wf_id, this.wf_v, w); + setCuboidRegion(16 - plotMinX - 1, 16 - plotMinX, this.wallheight + 1, this.wallheight + 2, 0, end, this.w_id, this.w_v, w); + setCuboidRegion(16 - plotMinX - 1, 16 - plotMinX, 1, this.wallheight + 1, start, 16, this.wf_id, this.wf_v, w); + setCuboidRegion(16 - plotMinX - 1, 16 - plotMinX, this.wallheight + 1, this.wallheight + 2, start, 16, this.w_id, this.w_v, w); + } + if ((roadStartZ <= 16) && (roadStartZ > 0)) { + int start, end; + if ((plotMinX + 1) <= 16) { + start = 16 - plotMinX; + } else { + start = 16; + } + if ((roadStartX + 1) <= 16) { + end = (16 - roadStartX) + 1; + } else { + end = 0; + } + if (!(((plotMinX + 1) <= 16) || (roadStartX <= 16))) { + start = 0; + } + setCuboidRegion(0, end, 1, this.wallheight + 1, 16 - roadStartZ, (16 - roadStartZ) + 1, this.wf_id, this.wf_v, w); + setCuboidRegion(0, end, this.wallheight + 1, this.wallheight + 2, 16 - roadStartZ, (16 - roadStartZ) + 1, this.w_id, this.w_v, w); + setCuboidRegion(start, 16, 1, this.wallheight + 1, 16 - roadStartZ, (16 - roadStartZ) + 1, this.wf_id, this.wf_v, w); + setCuboidRegion(start, 16, this.wallheight + 1, this.wallheight + 2, 16 - roadStartZ, (16 - roadStartZ) + 1, this.w_id, this.w_v, w); + } + if ((roadStartX <= 16) && (roadStartX > 0)) { + int start, end; + if ((plotMinZ + 1) <= 16) { + start = 16 - plotMinZ; + } else { + start = 16; + } + if ((roadStartZ + 1) <= 16) { + end = (16 - roadStartZ) + 1; + } else { + end = 0; + } + if (!(((plotMinZ + 1) <= 16) || ((roadStartZ + 1) <= 16))) { + start = 0; + } + setCuboidRegion(16 - roadStartX, (16 - roadStartX) + 1, 1, this.wallheight + 1, 0, end, this.wf_id, this.wf_v, w); + setCuboidRegion(16 - roadStartX, (16 - roadStartX) + 1, this.wallheight + 1, this.roadheight + 2, 0, end, this.w_id, this.w_v, w); + setCuboidRegion(16 - roadStartX, (16 - roadStartX) + 1, 1, this.wallheight + 1, start, 16, this.wf_id, this.wf_v, w); + setCuboidRegion(16 - roadStartX, (16 - roadStartX) + 1, this.wallheight + 1, this.wallheight + 2, start, 16, this.w_id, this.w_v, w); + } + } + + // PLOT + + if (this.plotsize > 16) { + if (roadStartX <= 16) { + if (roadStartZ <= 16) { + setCuboidRegion(0, 16 - roadStartX, 1, this.plotheight, 0, 16 - roadStartZ, this.p_id, this.p_v, w); + setCuboidRegion(0, 16 - roadStartX, this.plotheight, this.plotheight + 1, 0, 16 - roadStartZ, this.f_id, this.f_v, w); + } + if (plotMinZ <= 16) { + setCuboidRegion(0, 16 - roadStartX, 1, this.plotheight, 16 - plotMinZ, 16, this.p_id, this.p_v, w); + setCuboidRegion(0, 16 - roadStartX, this.plotheight, this.plotheight + 1, 16 - plotMinZ, 16, this.f_id, this.f_v, w); + } + } else { + if (roadStartZ <= 16) { + if (plotMinX > 16) { + setCuboidRegion(0, 16, 1, this.plotheight, 0, 16 - roadStartZ, this.p_id, this.p_v, w); + setCuboidRegion(0, 16, this.plotheight, this.plotheight + 1, 0, 16 - roadStartZ, this.f_id, this.f_v, w); + } + } + } + if (plotMinX <= 16) { + if (plotMinZ <= 16) { + setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 16 - plotMinZ, 16, this.p_id, this.p_v, w); + setCuboidRegion(16 - plotMinX, 16, this.plotheight, this.plotheight + 1, 16 - plotMinZ, 16, this.f_id, this.f_v, w); + } else { + int z = 16 - roadStartZ; + if (z < 0) { + z = 16; + } + setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 0, z, this.p_id, this.p_v, w); + setCuboidRegion(16 - plotMinX, 16, this.plotheight, this.plotheight + 1, 0, z, this.f_id, this.f_v, w); + } + if (roadStartZ <= 16) { + setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 0, 16 - roadStartZ, this.p_id, this.p_v, w); + setCuboidRegion(16 - plotMinX, 16, this.plotheight, this.plotheight + 1, 0, 16 - roadStartZ, this.f_id, this.f_v, w); + } else { + if (roadStartX <= 16) { + if (plotMinZ > 16) { + int x = 16 - roadStartX; + if (x < 0) { + x = 16; + } + setCuboidRegion(0, x, 1, this.plotheight, 0, 16, this.p_id, this.p_v, w); + setCuboidRegion(0, x, this.plotheight, this.plotheight + 1, 0, 16, this.f_id, this.f_v, w); + } + } + } + } else { + if (plotMinZ <= 16) { + if (roadStartX > 16) { + int x = 16 - roadStartX; + if (x < 0) { + x = 16; + } + setCuboidRegion(0, x, 1, this.plotheight, 16 - plotMinZ, 16, this.p_id, this.p_v, w); + setCuboidRegion(0, x, this.plotheight, this.plotheight + 1, 16 - plotMinZ, 16, this.f_id, this.f_v, w); + } + } else { + if (roadStartZ > 16) { + int x = 16 - roadStartX; + if (x < 0) { + x = 16; + } + int z = 16 - roadStartZ; + if (z < 0) { + z = 16; + } + if (roadStartX > 16) { + setCuboidRegion(0, x, 1, this.plotheight, 0, z, this.p_id, this.p_v, w); + setCuboidRegion(0, x, this.plotheight, this.plotheight + 1, 0, z, this.f_id, this.f_v, w); + } else { + setCuboidRegion(0, x, 1, this.plotheight, 0, z, this.p_id, this.p_v, w); + setCuboidRegion(0, x, this.plotheight, this.plotheight + 1, 0, z, this.f_id, this.f_v, w); + } + } + } + } + } else { + if (roadStartX <= 16) { + if (roadStartZ <= 16) { + setCuboidRegion(0, 16 - roadStartX, 1, this.plotheight, 0, 16 - roadStartZ, this.p_id, this.p_v, w); + setCuboidRegion(0, 16 - roadStartX, this.plotheight, this.plotheight + 1, 0, 16 - roadStartZ, this.f_id, this.f_v, w); + } + if (plotMinZ <= 16) { + setCuboidRegion(0, 16 - roadStartX, 1, this.plotheight, 16 - plotMinZ, 16, this.p_id, this.p_v, w); + setCuboidRegion(0, 16 - roadStartX, this.plotheight, this.plotheight + 1, 16 - plotMinZ, 16, this.f_id, this.f_v, w); + } + } + if (plotMinX <= 16) { + if (plotMinZ <= 16) { + setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 16 - plotMinZ, 16, this.p_id, this.p_v, w); + setCuboidRegion(16 - plotMinX, 16, this.plotheight, this.plotheight + 1, 16 - plotMinZ, 16, this.f_id, this.f_v, w); + } + if (roadStartZ <= 16) { + setCuboidRegion(16 - plotMinX, 16, 1, this.plotheight, 0, 16 - roadStartZ, this.p_id, this.p_v, w); + setCuboidRegion(16 - plotMinX, 16, this.plotheight, this.plotheight + 1, 0, 16 - roadStartZ, this.f_id, this.f_v, w); + } + } + } + } + + private void setBlock(World w, int x, int y, int z, short id, byte val) { + w.getBlockAt(this.X + x, y, this.Z + z).setData(val, false); + } + +}