Optimized populator

This commit is contained in:
boy0001 2015-04-22 00:03:27 +10:00
parent f020d9e640
commit 80a3c14189
5 changed files with 95 additions and 54 deletions

View File

@ -110,7 +110,8 @@ public class Setup extends SubCommand {
break;
}
case 1: { // choose world type
List<String> allTypes = Arrays.asList(new String[] { "default", "augmented", "partial" });
List<String> allTypes = Arrays.asList(new String[] { "default", "augmented", "partial"});
List<String> allDesc = Arrays.asList(new String[] { "Standard plot generation", "Plot generation with vanilla terrain", "Vanilla with clusters of plots"});
ArrayList<String> types = new ArrayList<>();
if (SetupUtils.generators.get(object.setupGenerator) instanceof PlotGenerator) {
types.add("default");
@ -120,51 +121,55 @@ public class Setup extends SubCommand {
types.add("partial");
}
if ((args.length != 1) || !types.contains(args[0].toLowerCase())) {
MainUtil.sendMessage(plr, "&cYou must choose a world type!" + "\n&8 - &2DEFAULT&8 - &7Standard plot generation" + "\n&8 - &7AUGMENTED&8 - &7Plot generation with terrain" + "\n&8 - &7PARTIAL&8 - &7Vanilla with clusters of plots");
MainUtil.sendMessage(plr, "&cYou must choose a world type!");
for (String type : types) {
int i = allTypes.indexOf(type);
if (type.equals("default")) {
MainUtil.sendMessage(plr, "&8 - &2" + type + " &8-&7 " + allDesc.get(i));
}
else {
MainUtil.sendMessage(plr, "&8 - &7" + type + " &8-&7 " + allDesc.get(i));
}
}
return false;
}
object.type = allTypes.indexOf(args[0].toLowerCase());
ChunkGenerator gen = SetupUtils.generators.get(object.setupGenerator);
if (object.type == 0) {
object.current++;
if (object.step == null) {
ChunkGenerator gen = SetupUtils.generators.get(object.setupGenerator);
if (gen instanceof PlotGenerator) {
object.plotManager = object.setupGenerator;
object.step = ((PlotGenerator) SetupUtils.generators.get(object.setupGenerator)).getNewPlotWorld(null).getSettingNodes();
((PlotGenerator) gen).processSetup(object, plr);
}
else {
MainUtil.sendMessage(plr, "&c[WARNING] The specified generator does not identify as PlotGenerator");
MainUtil.sendMessage(plr, "&7Searching for a configuration script...");
boolean script = false;
// TODO allow external configuration scripts
MainUtil.sendMessage(plr, "&cNo script has been found:");
MainUtil.sendMessage(plr, "&7 - You may need to manually configure the other plugin");
object.step = ((PlotGenerator) SetupUtils.generators.get("PlotSquared")).getNewPlotWorld(null).getSettingNodes();
}
object.plotManager = object.setupGenerator;
object.step = ((PlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes();
}
final ConfigurationNode step = object.step[object.setup_index];
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
} else {
if (gen instanceof PlotGenerator) {
object.plotManager = object.setupGenerator;
object.setupGenerator = null;
object.step = ((PlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes();
}
else {
object.plotManager = "PlotSquared";
MainUtil.sendMessage(plr, "&c[WARNING] The specified generator does not identify as PlotGenerator");
MainUtil.sendMessage(plr, "&7 - You may need to manually configure the other plugin");
object.step = ((PlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes();
}
MainUtil.sendMessage(plr, "&6What terrain would you like in plots?" + "\n&8 - &2NONE&8 - &7No terrain at all" + "\n&8 - &7ORE&8 - &7Just some ore veins and trees" + "\n&8 - &7ALL&8 - &7Entirely vanilla generation");
}
object.current++;
break;
}
case 2: { // Choose terrain
final List<String> terrain = Arrays.asList(new String[] { "none", "ore", "all" });
final List<String> terrain = Arrays.asList(new String[] { "none", "ore", "road", "all" });
if ((args.length != 1) || !terrain.contains(args[0].toLowerCase())) {
MainUtil.sendMessage(plr, "&cYou must choose the terrain!" + "\n&8 - &2NONE&8 - &7No terrain at all" + "\n&8 - &7ORE&8 - &7Just some ore veins and trees" + "\n&8 - &7ALL&8 - &7Entirely vanilla generation");
MainUtil.sendMessage(plr, "&cYou must choose the terrain!" + "\n&8 - &2NONE&8 - &7No terrain at all" + "\n&8 - &7ORE&8 - &7Just some ore veins and trees" + "\n&8 - &7ALL&8 - &7Entirely vanilla generation&8 - &7ROAD&8 - &7Vanilla except for roads\n" + "&8 - &7ALL&8 - &7Entirely vanilla generation");
return false;
}
object.terrain = terrain.indexOf(args[0].toLowerCase());
object.current++;
if (object.step == null) {
object.step = SetupUtils.generators.get(object.generator).getNewPlotWorld(null).getSettingNodes();
object.step = ((PlotGenerator) SetupUtils.generators.get(object.plotManager)).getNewPlotWorld(null).getSettingNodes();
}
final ConfigurationNode step = object.step[object.setup_index];
sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + "");
@ -211,11 +216,11 @@ public class Setup extends SubCommand {
object.world = args[0];
SetupUtils.setupMap.remove(plr.getName());
final String world;
if (object.manager == null) {
if (object.setupManager == null) {
world = SetupUtils.manager.setupWorld(object);
}
else {
world = object.setupManager.setupWorld(object);
}
try {
plr.teleport(BlockManager.manager.getSpawn(world));

View File

@ -90,14 +90,21 @@ public class Template extends SubCommand {
} catch (IOException e) {
e.printStackTrace();
}
String generator = worldConfig.getString("generator.plugin");
if (generator == null) {
generator = "PlotSquared";
String manager = worldConfig.getString("generator.plugin");
if (manager == null) {
manager = "PlotSquared";
}
String generator = worldConfig.getString("generator.init");
if (generator == null) {
generator = manager;
}
int type = worldConfig.getInt("generator.type");
int terrain = worldConfig.getInt("generator.terrain");
SetupObject setup = new SetupObject();
setup.generator = generator;
setup.plotManager = manager;
setup.setupGenerator = generator;
setup.type = type;
setup.terrain = terrain;
setup.step = new ConfigurationNode[0];

View File

@ -51,19 +51,36 @@ public class AugmentedPopulator extends BlockPopulator {
}
}
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 z = (a >> 4);
final int x = a - (z << 4);
final int z1 = (a >> 4);
final int x1 = a - (z1 << 4);
if (r[i] == null) {
return (c && (((Z + z) < this.bz) || ((Z + z) > this.tz) || ((X + x) < this.bx) || ((X + x) > this.tx))) ? null : new BlockWrapper(x, y, z, (short) 0, (byte) 0);
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 + z) < this.bz) || ((Z + z) > this.tz) || ((X + x) < this.bx) || ((X + x) > this.tx))) ? null : new BlockWrapper(x, y, z, r[i][j], (byte) 0);
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);
}
}
private short[][] x_loc;
private short[][] y_loc;
private short[][] z_loc;
public AugmentedPopulator(final String world, final PlotGenerator generator, final PlotCluster cluster, final boolean p, final boolean b) {
for (int i = 0; i < 16; i++) {
int i4 = i << 4;
for (int j = 0; j < 4096; j++) {
final int y = (i4) + (j >> 8);
final int a = (j - ((y & 0xF) << 8));
final int z1 = (a >> 4);
final int x1 = a - (z1 << 4);
x_loc[i][j] = (short) x1;
y_loc[i][j] = (short) y;
z_loc[i][j] = (short) z1;
}
}
this.cluster = cluster;
this.generator = generator;
this.plotworld = PlotSquared.getPlotWorld(world);
@ -95,6 +112,10 @@ public class AugmentedPopulator extends BlockPopulator {
@Override
public void populate(final World world, final Random rand, final Chunk chunk) {
if (this.plotworld.TERRAIN == 3) {
// FIXME check CURRENT_PLOT_CLEAR && FORCE_PASTE
return;
}
final int X = chunk.getX();
final int Z = chunk.getZ();
final int x = X << 4;
@ -116,7 +137,7 @@ public class AugmentedPopulator extends BlockPopulator {
} else {
check = false;
}
if (this.plotworld.TERRAIN == 2) {
if (this.plotworld.TERRAIN > 1) {
final PlotId plot1 = this.manager.getPlotIdAbs(this.plotworld, x, 0, z);
final PlotId plot2 = this.manager.getPlotIdAbs(this.plotworld, x2, 0, z2);
if ((plot1 != null) && (plot2 != null) && plot1.equals(plot2)) {
@ -129,7 +150,8 @@ public class AugmentedPopulator extends BlockPopulator {
TaskManager.runTaskLater(new Runnable() {
@Override
public void run() {
populateBiome(world, x, z);
// Don't need to populate biome with this
// populateBiome(world, x, z);
MainUtil.update(world.getName(), new ChunkLoc(chunk.getX(), chunk.getZ()));
}
}, 20);
@ -161,28 +183,32 @@ public class AugmentedPopulator extends BlockPopulator {
}
}
}
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);
final int length = result[0].length;
for (int i = 0; i < result.length; i++) {
for (int j = 0; j < length; j++) {
final BlockWrapper blockInfo = get(x, z, i, j, result, check);
if (blockInfo == null) {
continue;
}
final int xx = x + blockInfo.x;
final int zz = z + blockInfo.z;
if (this.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) {
if (result[i] != null) {
for (int j = 0; j < 4096; j++) {
int x1 = x_loc[i][j];
int y = y_loc[i][j];
int z1 = z_loc[i][j];
short id = result[i][j];
final int xx = x + x1;
final int zz = z + z1;
if (check && (((z + z1) < this.bz) || ((z + z1) > this.tz) || ((x + x1) < this.bx) || ((x + x1) > this.tx))) {
continue;
}
if (this.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) {
continue;
}
}
BukkitSetBlockManager.setBlockManager.set(world, xx, y, zz, id, (byte) 0);
}
BukkitSetBlockManager.setBlockManager.set(world, xx, blockInfo.y, zz, blockInfo.id, (byte) 0);
}
}
for (final BlockPopulator populator : this.generator.getDefaultPopulators(world)) {

View File

@ -178,5 +178,5 @@ public abstract class PlotGenerator extends ChunkGenerator {
public abstract PlotManager getPlotManager();
public void processSetup(SetupObject object, PlotPlayer player) {};
public void processSetup(SetupObject object) {};
}

View File

@ -13,6 +13,7 @@ import org.bukkit.plugin.Plugin;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.ConfigurationNode;
import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.SetupObject;
import com.intellectualcrafters.plot.util.SetupUtils;
@ -44,6 +45,8 @@ public class BukkitSetupUtils extends SetupUtils {
@Override
public String setupWorld(final SetupObject object) {
SetupUtils.manager.updateGenerators();
((PlotGenerator) SetupUtils.generators.get(object.plotManager)).processSetup(object);;
final ConfigurationNode[] steps = object.step;
final String world = object.world;
for (final ConfigurationNode step : steps) {