Plot analysis (#2239)

* Start to fix (and may have fixed) plot analysis with block buxkets and 1.13

* Standard deviation ought also be multiplied by 100, and only obtain the BlockBucket array once

* Add schematics to Plot Analysis
Add generateBlockBucketChunk method to SingleWorldGenerator
This commit is contained in:
dordsor21
2019-01-17 01:04:00 +00:00
committed by GitHub
parent 0817d7de5a
commit 223064567f
6 changed files with 377 additions and 251 deletions

View File

@ -27,6 +27,30 @@ public class HybridGen extends IndependentPlotGenerator {
}
}
@Override public BlockBucket[][] generateBlockBucketChunk(PlotArea settings) {
BlockBucket[][] blockBuckets = new BlockBucket[16][];
HybridPlotWorld hpw = (HybridPlotWorld) settings;
// Bedrock
if (hpw.PLOT_BEDROCK) {
for (short x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) {
blockBuckets[0][(z << 4) | x] =
BlockBucket.withSingle(PlotBlock.get("bedrock"));
}
}
}
for (short x = 0; x < 16; x++) {
for (short z = 0; z < 16; z++) {
for (int y = 1; y < hpw.PLOT_HEIGHT; y++) {
blockBuckets[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = hpw.MAIN_BLOCK;
}
blockBuckets[hpw.PLOT_HEIGHT >> 4][((hpw.PLOT_HEIGHT & 0xF) << 8) | (z << 4) | x] =
hpw.MAIN_BLOCK;
}
}
return blockBuckets;
}
@Override public void generateChunk(ScopedLocalBlockQueue result, PlotArea settings) {
HybridPlotWorld hpw = (HybridPlotWorld) settings;
// Biome
@ -41,8 +65,6 @@ public class HybridGen extends IndependentPlotGenerator {
}
// Coords
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;
short rbx;

View File

@ -1,10 +1,7 @@
package com.github.intellectualsites.plotsquared.plot.generator;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
import com.github.intellectualsites.plotsquared.plot.object.PlotManager;
import com.github.intellectualsites.plotsquared.plot.object.SetupObject;
import com.github.intellectualsites.plotsquared.plot.object.*;
import com.github.intellectualsites.plotsquared.plot.util.block.ScopedLocalBlockQueue;
/**
@ -19,6 +16,14 @@ public abstract class IndependentPlotGenerator {
*/
public abstract String getName();
/**
* Generates a 16x4096 array of BlockBuckets corresponding to the area settings to allow for plot analysis
*
* @param settings
* @return
*/
public abstract BlockBucket[][] generateBlockBucketChunk(PlotArea settings);
/**
* Use the setBlock or setBiome method of the PlotChunk result parameter to make changes.
* The PlotArea settings is the same one this was initialized with.

View File

@ -14,6 +14,7 @@ import com.github.intellectualsites.plotsquared.plot.util.*;
import com.github.intellectualsites.plotsquared.plot.util.area.QuadMap;
import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue;
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
import lombok.Getter;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -34,6 +35,7 @@ public abstract class PlotArea {
private final PlotId min;
private final PlotId max;
private final IndependentPlotGenerator generator;
@Getter private final BlockBucket[][] blockBucketChunk;
public int MAX_PLOT_MEMBERS = 128;
public boolean AUTO_MERGE = false;
public boolean ALLOW_SIGNS = true;
@ -66,8 +68,9 @@ public abstract class PlotArea {
private ConcurrentHashMap<String, Object> meta;
private QuadMap<PlotCluster> clusters;
public PlotArea(@Nonnull final String worldName, @Nullable final String id, @Nullable IndependentPlotGenerator generator,
@Nullable final PlotId min, @Nullable final PlotId max) {
public PlotArea(@Nonnull final String worldName, @Nullable final String id,
@Nullable IndependentPlotGenerator generator, @Nullable final PlotId min,
@Nullable final PlotId max) {
this.worldname = worldName;
this.id = id;
this.manager = generator != null ? generator.getNewPlotManager() : null;
@ -84,6 +87,11 @@ public abstract class PlotArea {
this.max = max;
}
this.worldhash = worldName.hashCode();
if (Settings.Enabled_Components.PLOT_EXPIRY) {
blockBucketChunk = generator.generateBlockBucketChunk(this);
} else {
blockBucketChunk = null;
}
}
/**
@ -395,7 +403,7 @@ public abstract class PlotArea {
*
* @return ConfigurationNode[]
*/
public abstract ConfigurationNode[] getSettingNodes();
public abstract ConfigurationNode[] getSettingNodes();
/**
* Gets the {@code Plot} at a location.
@ -591,7 +599,8 @@ public abstract class PlotArea {
return this.clusters != null ? this.clusters.get(plot.getId().x, plot.getId().y) : null;
}
@Nullable public PlotCluster getFirstIntersectingCluster(@Nonnull final PlotId pos1, @Nonnull final PlotId pos2) {
@Nullable public PlotCluster getFirstIntersectingCluster(@Nonnull final PlotId pos1,
@Nonnull final PlotId pos2) {
if (this.clusters == null) {
return null;
}
@ -615,6 +624,7 @@ public abstract class PlotArea {
* Session only plot metadata (session is until the server stops).
* <br>
* For persistent metadata use the flag system
*
* @see FlagManager
*/
public void setMeta(@Nonnull final String key, @Nullable final Object value) {

View File

@ -17,6 +17,39 @@ public class SingleWorldGenerator extends IndependentPlotGenerator {
return "PlotSquared:single";
}
@Override public BlockBucket[][] generateBlockBucketChunk(PlotArea settings) {
BlockBucket[][] blockBuckets = new BlockBucket[16][];
SinglePlotArea area = (SinglePlotArea) settings;
if (area.VOID) {
return blockBuckets;
}
for (int x = bedrock1.getX(); x <= bedrock2.getX(); x++) {
for (int z = bedrock1.getZ(); z <= bedrock2.getZ(); z++) {
for (int y = bedrock1.getY(); y <= bedrock2.getY(); y++) {
blockBuckets[y >> 4][((y & 0xF) << 8) | (z << 4) | x] =
BlockBucket.withSingle(PlotBlock.get("bedrock"));
}
}
}
for (int x = dirt1.getX(); x <= dirt2.getX(); x++) {
for (int z = dirt1.getZ(); z <= dirt2.getZ(); z++) {
for (int y = dirt1.getY(); y <= dirt2.getY(); y++) {
blockBuckets[y >> 4][((y & 0xF) << 8) | (z << 4) | x] =
BlockBucket.withSingle(PlotBlock.get("dirt"));
}
}
}
for (int x = grass1.getX(); x <= grass2.getX(); x++) {
for (int z = grass1.getZ(); z <= grass2.getZ(); z++) {
for (int y = grass1.getY(); y <= grass2.getY(); y++) {
blockBuckets[y >> 4][((y & 0xF) << 8) | (z << 4) | x] =
BlockBucket.withSingle(PlotBlock.get("grass_block"));
}
}
}
return blockBuckets;
}
@Override public void generateChunk(ScopedLocalBlockQueue result, PlotArea settings) {
SinglePlotArea area = (SinglePlotArea) settings;
if (area.VOID) {
@ -25,9 +58,9 @@ public class SingleWorldGenerator extends IndependentPlotGenerator {
result.setBlock(0, 0, 0, PlotBlock.get("bedrock"));
}
} else {
result.setCuboid(bedrock1, bedrock2, PlotBlock.get(7, 0));
result.setCuboid(dirt1, dirt2, PlotBlock.get(3, 0));
result.setCuboid(grass1, grass2, PlotBlock.get(2, 0));
result.setCuboid(bedrock1, bedrock2, PlotBlock.get("bedrock"));
result.setCuboid(dirt1, dirt2, PlotBlock.get("dirt"));
result.setCuboid(grass1, grass2, PlotBlock.get("grass_block"));
}
result.fillBiome("PLAINS");
}