PlotSquared/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/generator/HybridGen.java

237 lines
9.2 KiB
Java
Raw Normal View History

package com.github.intellectualsites.plotsquared.plot.generator;
2016-02-10 19:59:51 +01:00
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.object.*;
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler;
import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue;
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue;
import com.sk89q.jnbt.CompoundTag;
2018-08-10 17:01:10 +02:00
import java.util.HashMap;
import java.util.Map.Entry;
2016-02-10 19:59:51 +01:00
public class HybridGen extends IndependentPlotGenerator {
2018-08-10 17:01:10 +02:00
@Override public String getName() {
return PlotSquared.imp().getPluginName();
2016-02-10 19:59:51 +01:00
}
2016-03-23 02:41:37 +01:00
2018-08-10 17:01:10 +02:00
private void placeSchem(HybridPlotWorld world, ScopedLocalBlockQueue result, short relativeX,
short relativeZ, int x, int z) {
2017-03-13 08:02:05 +01:00
int minY = Math.min(world.PLOT_HEIGHT, world.ROAD_HEIGHT);
String[] blocks = world.G_SCH.get(MathMan.pair(relativeX, relativeZ));
2016-12-31 07:23:46 +01:00
if (blocks != null) {
for (int y = 0; y < blocks.length; y++) {
if (blocks[y] != null) {
PlotBlock block = PlotBlock.get(blocks[y]);
2017-03-13 08:02:05 +01:00
result.setBlock(x, minY + y, z, block);
2016-12-31 07:23:46 +01:00
}
}
}
}
@Override public void generateChunk(ScopedLocalBlockQueue result, PlotArea settings) {
2016-02-10 19:59:51 +01:00
HybridPlotWorld hpw = (HybridPlotWorld) settings;
// Biome
2016-09-06 16:28:01 +02:00
result.fillBiome(hpw.PLOT_BIOME);
2016-02-10 19:59:51 +01:00
// Bedrock
if (hpw.PLOT_BEDROCK) {
for (short x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) {
result.setBlock(x, 0, z, PlotBlock.get("bedrock"));
2016-02-10 19:59:51 +01:00
}
}
}
// Coords
2016-06-13 06:47:50 +02:00
Location min = result.getMin();
int cx = min.getX() >> 4;
int cz = min.getZ() >> 4;
int bx = (min.getX()) - hpw.ROAD_OFFSET_X;
int bz = (min.getZ()) - hpw.ROAD_OFFSET_Z;
2016-03-23 02:41:37 +01:00
short rbx;
if (bx < 0) {
rbx = (short) (hpw.SIZE + (bx % hpw.SIZE));
} else {
rbx = (short) (bx % hpw.SIZE);
}
short rbz;
if (bz < 0) {
rbz = (short) (hpw.SIZE + (bz % hpw.SIZE));
} else {
rbz = (short) (bz % hpw.SIZE);
}
2016-02-10 19:59:51 +01:00
short[] rx = new short[16];
boolean[] gx = new boolean[16];
boolean[] wx = new boolean[16];
for (short i = 0; i < 16; i++) {
short v = (short) (rbx + i);
if (v >= hpw.SIZE) {
v -= hpw.SIZE;
}
rx[i] = v;
if (hpw.ROAD_WIDTH != 0) {
gx[i] = v < hpw.PATH_WIDTH_LOWER || v > hpw.PATH_WIDTH_UPPER;
wx[i] = v == hpw.PATH_WIDTH_LOWER || v == hpw.PATH_WIDTH_UPPER;
}
}
short[] rz = new short[16];
boolean[] gz = new boolean[16];
boolean[] wz = new boolean[16];
for (short i = 0; i < 16; i++) {
short v = (short) (rbz + i);
if (v >= hpw.SIZE) {
v -= hpw.SIZE;
}
rz[i] = v;
if (hpw.ROAD_WIDTH != 0) {
gz[i] = v < hpw.PATH_WIDTH_LOWER || v > hpw.PATH_WIDTH_UPPER;
wz[i] = v == hpw.PATH_WIDTH_LOWER || v == hpw.PATH_WIDTH_UPPER;
}
}
// generation
HashMap<Integer, String[]> sch = hpw.G_SCH;
2016-02-10 19:59:51 +01:00
for (short x = 0; x < 16; x++) {
if (gx[x]) {
for (short z = 0; z < 16; z++) {
// Road
for (int y = 1; y <= hpw.ROAD_HEIGHT; y++) {
2018-12-19 17:19:54 +01:00
result.setBlock(x, y, z, hpw.ROAD_BLOCK.getBlock());
2016-02-10 19:59:51 +01:00
}
if (hpw.ROAD_SCHEMATIC_ENABLED) {
2016-12-31 07:23:46 +01:00
placeSchem(hpw, result, rx[x], rz[z], x, z);
2016-02-10 19:59:51 +01:00
}
}
} else if (wx[x]) {
for (short z = 0; z < 16; z++) {
if (gz[z]) {
// road
for (int y = 1; y <= hpw.ROAD_HEIGHT; y++) {
2018-12-19 17:19:54 +01:00
result.setBlock(x, y, z, hpw.ROAD_BLOCK.getBlock());
2016-02-10 19:59:51 +01:00
}
if (hpw.ROAD_SCHEMATIC_ENABLED) {
2016-12-31 07:23:46 +01:00
placeSchem(hpw, result, rx[x], rz[z], x, z);
2016-02-10 19:59:51 +01:00
}
} else {
// wall
for (int y = 1; y <= hpw.WALL_HEIGHT; y++) {
2018-12-19 17:19:54 +01:00
result.setBlock(x, y, z, hpw.WALL_FILLING.getBlock());
2016-02-10 19:59:51 +01:00
}
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
2018-12-19 17:19:54 +01:00
result.setBlock(x, hpw.WALL_HEIGHT + 1, z, hpw.WALL_BLOCK.getBlock());
2016-02-10 19:59:51 +01:00
} else {
2016-12-31 07:23:46 +01:00
placeSchem(hpw, result, rx[x], rz[z], x, z);
2016-02-10 19:59:51 +01:00
}
}
}
} else {
for (short z = 0; z < 16; z++) {
if (gz[z]) {
// road
for (int y = 1; y <= hpw.ROAD_HEIGHT; y++) {
2018-12-19 17:19:54 +01:00
result.setBlock(x, y, z, hpw.ROAD_BLOCK.getBlock());
2016-02-10 19:59:51 +01:00
}
if (hpw.ROAD_SCHEMATIC_ENABLED) {
2016-12-31 07:23:46 +01:00
placeSchem(hpw, result, rx[x], rz[z], x, z);
2016-02-10 19:59:51 +01:00
}
} else if (wz[z]) {
// wall
for (int y = 1; y <= hpw.WALL_HEIGHT; y++) {
2018-12-19 17:19:54 +01:00
result.setBlock(x, y, z, hpw.WALL_FILLING.getBlock());
2016-02-10 19:59:51 +01:00
}
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
2018-12-19 17:19:54 +01:00
result.setBlock(x, hpw.WALL_HEIGHT + 1, z, hpw.WALL_BLOCK.getBlock());
2016-02-10 19:59:51 +01:00
} else {
2016-12-31 07:23:46 +01:00
placeSchem(hpw, result, rx[x], rz[z], x, z);
2016-02-10 19:59:51 +01:00
}
} else {
// plot
for (int y = 1; y < hpw.PLOT_HEIGHT; y++) {
result.setBlock(x, y, z, hpw.MAIN_BLOCK.getBlock());
2016-02-10 19:59:51 +01:00
}
result.setBlock(x, hpw.PLOT_HEIGHT, z, hpw.TOP_BLOCK.getBlock());
2016-02-10 19:59:51 +01:00
if (hpw.PLOT_SCHEMATIC) {
2016-12-31 07:23:46 +01:00
placeSchem(hpw, result, rx[x], rz[z], x, z);
2016-02-10 19:59:51 +01:00
}
}
}
}
}
}
2016-03-23 02:41:37 +01:00
@Override public boolean populateChunk(ScopedLocalBlockQueue result, PlotArea settings) {
HybridPlotWorld hpw = (HybridPlotWorld) settings;
if (hpw.G_SCH_STATE != null) {
2016-06-13 06:47:50 +02:00
Location min = result.getMin();
int cx = min.getX() >> 4;
int cz = min.getZ() >> 4;
int p1x = cx << 4;
int p1z = cz << 4;
int bx = p1x - hpw.ROAD_OFFSET_X;
int bz = p1z - hpw.ROAD_OFFSET_Z;
short rbx;
if (bx < 0) {
rbx = (short) (hpw.SIZE + (bx % hpw.SIZE));
} else {
rbx = (short) (bx % hpw.SIZE);
}
short rbz;
if (bz < 0) {
rbz = (short) (hpw.SIZE + (bz % hpw.SIZE));
} else {
rbz = (short) (bz % hpw.SIZE);
}
short[] rx = new short[16];
for (short i = 0; i < 16; i++) {
short v = (short) (rbx + i);
if (v >= hpw.SIZE) {
v -= hpw.SIZE;
}
rx[i] = v;
}
short[] rz = new short[16];
for (short i = 0; i < 16; i++) {
short v = (short) (rbz + i);
if (v >= hpw.SIZE) {
v -= hpw.SIZE;
}
rz[i] = v;
}
2016-06-16 02:31:25 +02:00
LocalBlockQueue queue = null;
for (short x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) {
int pair = MathMan.pair(rx[x], rz[z]);
HashMap<Integer, CompoundTag> map = hpw.G_SCH_STATE.get(pair);
if (map != null) {
for (Entry<Integer, CompoundTag> entry : map.entrySet()) {
2016-06-16 02:31:25 +02:00
if (queue == null) {
queue = GlobalBlockQueue.IMP.getNewQueue(hpw.worldname, false);
}
CompoundTag tag = entry.getValue();
2018-08-10 17:01:10 +02:00
SchematicHandler.manager
.restoreTile(queue, tag, p1x + x, entry.getKey(), p1z + z);
}
}
}
}
if (queue != null) {
queue.flush();
}
}
return false;
}
2018-08-10 17:01:10 +02:00
@Override public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) {
2016-02-10 19:59:51 +01:00
return new HybridPlotWorld(world, id, this, min, max);
}
2016-03-23 02:41:37 +01:00
2018-08-10 17:01:10 +02:00
@Override public PlotManager getNewPlotManager() {
return new HybridPlotManager();
2016-02-10 19:59:51 +01:00
}
2016-03-23 02:41:37 +01:00
2018-08-10 17:01:10 +02:00
@Override public void initialize(PlotArea area) {
2016-02-10 19:59:51 +01:00
// All initialization is done in the PlotArea class
}
}