Move to new generation API

- Currently not working due to lack of biome-setting capability via BiomeProvider for flat worlds
This commit is contained in:
dordsor21
2022-06-08 21:12:16 +01:00
parent 43150abb86
commit 9188c8c40d
14 changed files with 434 additions and 145 deletions

View File

@@ -787,7 +787,9 @@ public class PlotSquared {
if (world.equals("CheckingPlotSquaredGenerator")) {
return;
}
this.getPlotAreaManager().addWorld(world);
if (!this.getPlotAreaManager().addWorld(world)) {
return;
}
Set<String> worlds;
if (this.worldConfiguration.contains("worlds")) {
worlds = this.worldConfiguration.getConfigurationSection("worlds").getKeys(false);

View File

@@ -174,7 +174,7 @@ public class AugmentedUtils {
Location.at(world, blockX, area.getMinGenHeight(), blockZ),
Location.at(world, blockX + 15, area.getMaxGenHeight(), blockZ + 15)
);
generator.generateChunk(scoped, area);
generator.generateChunk(scoped, area, true);
generator.populateChunk(scoped, area);
}
if (enqueue) {

View File

@@ -61,7 +61,8 @@ public class HybridGen extends IndependentPlotGenerator {
short relativeZ,
int x,
int z,
boolean isRoad
boolean isRoad,
boolean biomes
) {
int minY; // Math.min(world.PLOT_HEIGHT, world.ROAD_HEIGHT);
if ((isRoad && Settings.Schematics.PASTE_ROAD_ON_TOP) || (!isRoad && Settings.Schematics.PASTE_ON_TOP)) {
@@ -77,6 +78,9 @@ public class HybridGen extends IndependentPlotGenerator {
}
}
}
if (!biomes) {
return;
}
BiomeType biome = world.G_SCH_B.get(MathMan.pair(relativeX, relativeZ));
if (biome != null) {
result.setBiome(x, z, biome);
@@ -84,13 +88,15 @@ public class HybridGen extends IndependentPlotGenerator {
}
@Override
public void generateChunk(@NonNull ZeroedDelegateScopedQueueCoordinator result, @NonNull PlotArea settings) {
public void generateChunk(@NonNull ZeroedDelegateScopedQueueCoordinator result, @NonNull PlotArea settings, boolean biomes) {
Preconditions.checkNotNull(result, "result cannot be null");
Preconditions.checkNotNull(settings, "settings cannot be null");
HybridPlotWorld hybridPlotWorld = (HybridPlotWorld) settings;
// Biome
result.fillBiome(hybridPlotWorld.getPlotBiome());
if (biomes) {
result.fillBiome(hybridPlotWorld.getPlotBiome());
}
// Bedrock
if (hybridPlotWorld.PLOT_BEDROCK) {
for (short x = 0; x < 16; x++) {
@@ -132,10 +138,8 @@ public class HybridGen extends IndependentPlotGenerator {
}
relativeX[i] = v;
if (hybridPlotWorld.ROAD_WIDTH != 0) {
insideRoadX[i] =
v < hybridPlotWorld.PATH_WIDTH_LOWER || v > hybridPlotWorld.PATH_WIDTH_UPPER;
insideWallX[i] =
v == hybridPlotWorld.PATH_WIDTH_LOWER || v == hybridPlotWorld.PATH_WIDTH_UPPER;
insideRoadX[i] = v < hybridPlotWorld.PATH_WIDTH_LOWER || v > hybridPlotWorld.PATH_WIDTH_UPPER;
insideWallX[i] = v == hybridPlotWorld.PATH_WIDTH_LOWER || v == hybridPlotWorld.PATH_WIDTH_UPPER;
}
}
// The Z-coordinate of a given Z coordinate, relative to the
@@ -153,14 +157,12 @@ public class HybridGen extends IndependentPlotGenerator {
}
relativeZ[i] = v;
if (hybridPlotWorld.ROAD_WIDTH != 0) {
insideRoadZ[i] =
v < hybridPlotWorld.PATH_WIDTH_LOWER || v > hybridPlotWorld.PATH_WIDTH_UPPER;
insideWallZ[i] =
v == hybridPlotWorld.PATH_WIDTH_LOWER || v == hybridPlotWorld.PATH_WIDTH_UPPER;
insideRoadZ[i] = v < hybridPlotWorld.PATH_WIDTH_LOWER || v > hybridPlotWorld.PATH_WIDTH_UPPER;
insideWallZ[i] = v == hybridPlotWorld.PATH_WIDTH_LOWER || v == hybridPlotWorld.PATH_WIDTH_UPPER;
}
}
// generation
int startY = hybridPlotWorld.getMinGenHeight() + (hybridPlotWorld.PLOT_BEDROCK ? 1: 0);
int startY = hybridPlotWorld.getMinGenHeight() + (hybridPlotWorld.PLOT_BEDROCK ? 1 : 0);
for (short x = 0; x < 16; x++) {
if (insideRoadX[x]) {
for (short z = 0; z < 16; z++) {
@@ -169,7 +171,7 @@ public class HybridGen extends IndependentPlotGenerator {
result.setBlock(x, y, z, hybridPlotWorld.ROAD_BLOCK.toPattern());
}
if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, true);
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, true, biomes);
}
}
} else if (insideWallX[x]) {
@@ -180,9 +182,7 @@ public class HybridGen extends IndependentPlotGenerator {
result.setBlock(x, y, z, hybridPlotWorld.ROAD_BLOCK.toPattern());
}
if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z,
true
);
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, true, biomes);
}
} else {
// wall
@@ -191,14 +191,10 @@ public class HybridGen extends IndependentPlotGenerator {
}
if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
if (hybridPlotWorld.PLACE_TOP_BLOCK) {
result.setBlock(x, hybridPlotWorld.WALL_HEIGHT + 1, z,
hybridPlotWorld.WALL_BLOCK.toPattern()
);
result.setBlock(x, hybridPlotWorld.WALL_HEIGHT + 1, z, hybridPlotWorld.WALL_BLOCK.toPattern());
}
} else {
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z,
true
);
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, true, biomes);
}
}
}
@@ -210,9 +206,7 @@ public class HybridGen extends IndependentPlotGenerator {
result.setBlock(x, y, z, hybridPlotWorld.ROAD_BLOCK.toPattern());
}
if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z,
true
);
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, true, biomes);
}
} else if (insideWallZ[z]) {
// wall
@@ -221,27 +215,19 @@ public class HybridGen extends IndependentPlotGenerator {
}
if (!hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
if (hybridPlotWorld.PLACE_TOP_BLOCK) {
result.setBlock(x, hybridPlotWorld.WALL_HEIGHT + 1, z,
hybridPlotWorld.WALL_BLOCK.toPattern()
);
result.setBlock(x, hybridPlotWorld.WALL_HEIGHT + 1, z, hybridPlotWorld.WALL_BLOCK.toPattern());
}
} else {
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z,
true
);
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, true, biomes);
}
} else {
// plot
for (int y = startY; y < hybridPlotWorld.PLOT_HEIGHT; y++) {
result.setBlock(x, y, z, hybridPlotWorld.MAIN_BLOCK.toPattern());
}
result.setBlock(x, hybridPlotWorld.PLOT_HEIGHT, z,
hybridPlotWorld.TOP_BLOCK.toPattern()
);
result.setBlock(x, hybridPlotWorld.PLOT_HEIGHT, z, hybridPlotWorld.TOP_BLOCK.toPattern());
if (hybridPlotWorld.PLOT_SCHEMATIC) {
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z,
false
);
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, false, biomes);
}
}
}
@@ -259,4 +245,33 @@ public class HybridGen extends IndependentPlotGenerator {
// All initialization is done in the PlotArea class
}
@Override
public BiomeType getBiome(final PlotArea settings, final int worldX, final int worldY, final int worldZ) {
HybridPlotWorld hybridPlotWorld = (HybridPlotWorld) settings;
if (!hybridPlotWorld.PLOT_SCHEMATIC && !hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
return hybridPlotWorld.getPlotBiome();
}
int relativeX = worldX;
int relativeZ = worldZ;
if (hybridPlotWorld.ROAD_OFFSET_X != 0) {
relativeX -= hybridPlotWorld.ROAD_OFFSET_X;
}
if (hybridPlotWorld.ROAD_OFFSET_Z != 0) {
relativeZ -= hybridPlotWorld.ROAD_OFFSET_Z;
}
int size = hybridPlotWorld.PLOT_WIDTH + hybridPlotWorld.ROAD_WIDTH;
if (relativeX < 0) {
relativeX = size + (relativeX % size);
} else {
relativeX = relativeX % size;
}
if (relativeZ < 0) {
relativeZ = size + (relativeZ % size);
} else {
relativeZ = relativeZ % size;
}
BiomeType biome = hybridPlotWorld.G_SCH_B.get(MathMan.pair((short) relativeX, (short) relativeZ));
return biome == null ? hybridPlotWorld.getPlotBiome() : biome;
}
}

View File

@@ -170,7 +170,7 @@ public class HybridUtils {
int relChunkZ = chunkPos.getZ() - cbz;
oldBlockQueue.setOffsetX(relChunkX << 4);
oldBlockQueue.setOffsetZ(relChunkZ << 4);
hpw.getGenerator().generateChunk(oldBlockQueue, hpw);
hpw.getGenerator().generateChunk(oldBlockQueue, hpw, false);
});
final BlockState[][][] oldBlocks = oldBlockQueue.getBlockStates();

View File

@@ -30,6 +30,7 @@ import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.queue.ZeroedDelegateScopedQueueCoordinator;
import com.plotsquared.core.setup.PlotAreaBuilder;
import com.sk89q.worldedit.world.biome.BiomeType;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
@@ -51,10 +52,11 @@ public abstract class IndependentPlotGenerator {
* The PlotArea settings is the same one this was initialized with.
* The PseudoRandom random is a fast random object.
*
* @param result queue
* @param result Queue to write to
* @param settings PlotArea (settings)
* @param biomes If biomes should be generated
*/
public abstract void generateChunk(ZeroedDelegateScopedQueueCoordinator result, PlotArea settings);
public abstract void generateChunk(ZeroedDelegateScopedQueueCoordinator result, PlotArea settings, boolean biomes);
public boolean populateChunk(ZeroedDelegateScopedQueueCoordinator result, PlotArea setting) {
return false;
@@ -100,6 +102,18 @@ public abstract class IndependentPlotGenerator {
return (GeneratorWrapper<T>) PlotSquared.platform().wrapPlotGenerator(world, this);
}
/**
* Get the biome to be generated at a specific point
*
* @param settings PlotArea settings to provide biome
* @param x World x position
* @param y World y position
* @param z World z position
* @return Biome type to be generated
* @since TODO
*/
public abstract BiomeType getBiome(PlotArea settings, int x, int y, int z);
@Override
public String toString() {
return getName();

View File

@@ -33,7 +33,9 @@ import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.plot.world.SinglePlotArea;
import com.plotsquared.core.plot.world.SinglePlotAreaManager;
import com.plotsquared.core.queue.ZeroedDelegateScopedQueueCoordinator;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -45,6 +47,9 @@ public class SingleWorldGenerator extends IndependentPlotGenerator {
private static final Location dirt2 = Location.at("", 15, 2, 15);
private static final Location grass1 = Location.at("", 0, 3, 0);
private static final Location grass2 = Location.at("", 15, 3, 15);
private static final BlockState BEDROCK = BlockTypes.BEDROCK.getDefaultState();
private static final BlockState DIRT = BlockTypes.DIRT.getDefaultState();
private static final BlockState GRASS_BLOCK = BlockTypes.GRASS_BLOCK.getDefaultState();
private final PlotAreaManager plotAreaManager;
@@ -59,19 +64,21 @@ public class SingleWorldGenerator extends IndependentPlotGenerator {
}
@Override
public void generateChunk(ZeroedDelegateScopedQueueCoordinator result, PlotArea settings) {
public void generateChunk(ZeroedDelegateScopedQueueCoordinator result, PlotArea settings, boolean biomes) {
SinglePlotArea area = (SinglePlotArea) settings;
if (area.VOID) {
Location min = result.getMin();
if (min.getX() == 0 && min.getZ() == 0) {
result.setBlock(0, 0, 0, BlockTypes.BEDROCK.getDefaultState());
result.setBlock(0, 0, 0, BEDROCK);
}
} else {
result.setCuboid(bedrock1, bedrock2, BlockTypes.BEDROCK.getDefaultState());
result.setCuboid(dirt1, dirt2, BlockTypes.DIRT.getDefaultState());
result.setCuboid(grass1, grass2, BlockTypes.GRASS_BLOCK.getDefaultState());
result.setCuboid(bedrock1, bedrock2, BEDROCK);
result.setCuboid(dirt1, dirt2, DIRT);
result.setCuboid(grass1, grass2, GRASS_BLOCK);
}
if (biomes) {
result.fillBiome(BiomeTypes.PLAINS);
}
result.fillBiome(BiomeTypes.PLAINS);
}
@Override
@@ -83,4 +90,9 @@ public class SingleWorldGenerator extends IndependentPlotGenerator {
public void initialize(PlotArea area) {
}
@Override
public BiomeType getBiome(final PlotArea settings, final int x, final int y, final int z) {
return BiomeTypes.PLAINS;
}
}

View File

@@ -41,14 +41,14 @@ import org.khelekore.prtree.SimpleMBR;
* An unmodifiable 6-tuple (world,x,y,z,yaw,pitch)
*/
@SuppressWarnings("unused")
public final class Location extends BlockLoc implements Comparable<Location> {
public class Location extends BlockLoc implements Comparable<Location> {
private final float yaw;
private final float pitch;
private final BlockVector3 blockVector3;
private final World<?> world;
private Location(
protected Location(
final @NonNull World<?> world, final @NonNull BlockVector3 blockVector3,
final float yaw, final float pitch
) {

View File

@@ -0,0 +1,68 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2014 - 2022 IntellectualSites
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.location;
import com.plotsquared.core.util.AnnotationHelper;
import com.sk89q.worldedit.math.BlockVector3;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* Used internally for generation to reference locations in worlds that "don't exist yet". There is no guarantee that the world
* name provided by {@link UncheckedWorldLocation#getWorldName()} exists on the server.
*/
@AnnotationHelper.ApiDescription(info = "Internal use only. Subject to changes at any time.")
public class UncheckedWorldLocation extends Location {
private final String worldName;
private UncheckedWorldLocation(
final @NonNull String worldName, final int x, final int y, final int z
) {
super(World.nullWorld(), BlockVector3.at(x, y, z), 0f, 0f);
this.worldName = worldName;
}
/**
* Construct a new location with yaw and pitch equal to 0
*
* @param world World
* @param x X coordinate
* @param y Y coordinate
* @param z Z coordinate
* @return New location
*/
public static @NonNull UncheckedWorldLocation at(
final @NonNull String world, final int x, final int y, final int z
) {
return new UncheckedWorldLocation(world, x, y, z);
}
@Override
public @NonNull String getWorldName() {
return this.worldName;
}
}

View File

@@ -117,54 +117,60 @@ public final class BlockBucket implements ConfigurationSerializable {
if (isCompiled()) {
return;
}
this.compiled = true;
String string = this.input.toString();
if (string.isEmpty()) {
this.single = null;
this.pattern = null;
return;
}
// Convert legacy format
boolean legacy = false;
String[] blocksStr = string.split(",(?![^\\(\\[]*[\\]\\)])");
if (blocksStr.length == 1) {
try {
Matcher matcher = regex.matcher(string);
// Synchronized as BlockBuckets may require compilation asynchronously due to async chunk generation on Paper servers
synchronized (this) {
if (isCompiled()) {
return;
}
String string = this.input.toString();
if (string.isEmpty()) {
this.single = null;
this.pattern = null;
return;
}
// Convert legacy format
boolean legacy = false;
String[] blocksStr = string.split(",(?![^\\(\\[]*[\\]\\)])");
if (blocksStr.length == 1) {
try {
Matcher matcher = regex.matcher(string);
if (matcher.find()) {
String chanceStr = matcher.group("chance");
String block = matcher.group("block");
//noinspection PointlessNullCheck
if (chanceStr != null && block != null && !MathMan.isInteger(block) && MathMan
.isInteger(chanceStr)) {
String namespace = matcher.group("namespace");
string = (namespace == null ? "" : namespace + ":") + block;
}
}
this.single = BlockUtil.get(string);
this.pattern = new BlockPattern(single);
return;
} catch (Exception ignore) {
}
}
for (int i = 0; i < blocksStr.length; i++) {
String entry = blocksStr[i];
Matcher matcher = regex.matcher(entry);
if (matcher.find()) {
String chanceStr = matcher.group("chance");
String block = matcher.group("block");
//noinspection PointlessNullCheck
if (chanceStr != null && block != null && !MathMan.isInteger(block) && MathMan
.isInteger(chanceStr)) {
String namespace = matcher.group("namespace");
string = (namespace == null ? "" : namespace + ":") + block;
if (chanceStr != null && MathMan.isInteger(chanceStr)) {
String[] parts = entry.split(":");
parts = Arrays.copyOf(parts, parts.length - 1);
entry = chanceStr + "%" + StringMan.join(parts, ":");
blocksStr[i] = entry;
legacy = true;
}
}
this.single = BlockUtil.get(string);
this.pattern = new BlockPattern(single);
return;
} catch (Exception ignore) {
}
}
for (int i = 0; i < blocksStr.length; i++) {
String entry = blocksStr[i];
Matcher matcher = regex.matcher(entry);
if (matcher.find()) {
String chanceStr = matcher.group("chance");
//noinspection PointlessNullCheck
if (chanceStr != null && MathMan.isInteger(chanceStr)) {
String[] parts = entry.split(":");
parts = Arrays.copyOf(parts, parts.length - 1);
entry = chanceStr + "%" + StringMan.join(parts, ":");
blocksStr[i] = entry;
legacy = true;
}
if (legacy) {
string = StringMan.join(blocksStr, ",");
}
pattern = PatternUtil.parse(null, string);
this.compiled = true;
}
if (legacy) {
string = StringMan.join(blocksStr, ",");
}
pattern = PatternUtil.parse(null, string);
}
public boolean isCompiled() {

View File

@@ -144,15 +144,16 @@ public class DefaultPlotAreaManager implements PlotAreaManager {
}
@Override
public void addWorld(final @NonNull String worldName) {
public boolean addWorld(final @NonNull String worldName) {
PlotWorld world = this.plotWorlds.get(worldName);
if (world != null) {
return;
return false;
}
// Create a new empty world. When a new area is added
// the world will be re-recreated with the correct type
world = new StandardPlotWorld(worldName, null);
this.plotWorlds.put(worldName, world);
return true;
}
@Override

View File

@@ -117,8 +117,9 @@ public interface PlotAreaManager {
* Add a world
*
* @param worldName Name of the world to add
* @return true if successful. False if world already existed
*/
void addWorld(@NonNull String worldName);
boolean addWorld(@NonNull String worldName);
/**
* Remove a world

View File

@@ -179,8 +179,8 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager {
}
@Override
public void addWorld(final @NonNull String worldName) {
super.addWorld(worldName);
public boolean addWorld(final @NonNull String worldName) {
return super.addWorld(worldName);
}
@Override