Replace many booleans with EnumSet

This commit is contained in:
dordsor21 2022-06-20 12:58:44 +01:00
parent 76c2f0ff0b
commit 62f842eae5
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B

View File

@ -42,6 +42,8 @@ import com.sk89q.worldedit.world.block.BlockTypes;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.EnumSet;
public class HybridGen extends IndependentPlotGenerator { public class HybridGen extends IndependentPlotGenerator {
private static final CuboidRegion CHUNK = new CuboidRegion(BlockVector3.ZERO, BlockVector3.at(15, 396, 15)); private static final CuboidRegion CHUNK = new CuboidRegion(BlockVector3.ZERO, BlockVector3.at(15, 396, 15));
@ -64,12 +66,11 @@ public class HybridGen extends IndependentPlotGenerator {
short relativeZ, short relativeZ,
int x, int x,
int z, int z,
boolean isRoad, EnumSet<SchematicFeature> features
boolean isPopulating,
boolean biomes
) { ) {
int minY; // Math.min(world.PLOT_HEIGHT, world.ROAD_HEIGHT); int minY; // Math.min(world.PLOT_HEIGHT, world.ROAD_HEIGHT);
if ((isRoad && Settings.Schematics.PASTE_ROAD_ON_TOP) || (!isRoad && Settings.Schematics.PASTE_ON_TOP)) { if ((features.contains(SchematicFeature.ROAD) && Settings.Schematics.PASTE_ROAD_ON_TOP)
|| (!features.contains(SchematicFeature.ROAD) && Settings.Schematics.PASTE_ON_TOP)) {
minY = world.SCHEM_Y; minY = world.SCHEM_Y;
} else { } else {
minY = world.getMinBuildHeight(); minY = world.getMinBuildHeight();
@ -78,13 +79,13 @@ public class HybridGen extends IndependentPlotGenerator {
if (blocks != null) { if (blocks != null) {
for (int y = 0; y < blocks.length; y++) { for (int y = 0; y < blocks.length; y++) {
if (blocks[y] != null) { if (blocks[y] != null) {
if (!isPopulating || blocks[y].hasNbtData()) { if (!features.contains(SchematicFeature.POPULATING) || blocks[y].hasNbtData()) {
result.setBlock(x, minY + y, z, blocks[y]); result.setBlock(x, minY + y, z, blocks[y]);
} }
} }
} }
} }
if (!biomes) { if (!features.contains(SchematicFeature.BIOMES)) {
return; return;
} }
BiomeType biome = world.G_SCH_B.get(MathMan.pair(relativeX, relativeZ)); BiomeType biome = world.G_SCH_B.get(MathMan.pair(relativeX, relativeZ));
@ -111,6 +112,13 @@ public class HybridGen extends IndependentPlotGenerator {
} }
} }
} }
EnumSet<SchematicFeature> roadFeatures = EnumSet.of(SchematicFeature.ROAD);
EnumSet<SchematicFeature> plotFeatures = EnumSet.noneOf(SchematicFeature.class);
if (biomes) {
roadFeatures.add(SchematicFeature.BIOMES);
plotFeatures.add(SchematicFeature.BIOMES);
}
// Coords // Coords
Location min = result.getMin(); Location min = result.getMin();
int bx = min.getX() - hybridPlotWorld.ROAD_OFFSET_X; int bx = min.getX() - hybridPlotWorld.ROAD_OFFSET_X;
@ -169,7 +177,7 @@ public class HybridGen extends IndependentPlotGenerator {
result.setBlock(x, y, z, hybridPlotWorld.ROAD_BLOCK.toPattern()); result.setBlock(x, y, z, hybridPlotWorld.ROAD_BLOCK.toPattern());
} }
if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) { if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, true, false, biomes); placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, roadFeatures);
} }
} }
} else if (insideWallX[x]) { } else if (insideWallX[x]) {
@ -180,7 +188,7 @@ public class HybridGen extends IndependentPlotGenerator {
result.setBlock(x, y, z, hybridPlotWorld.ROAD_BLOCK.toPattern()); result.setBlock(x, y, z, hybridPlotWorld.ROAD_BLOCK.toPattern());
} }
if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) { if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, true, false, biomes); placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, roadFeatures);
} }
} else { } else {
// wall // wall
@ -192,7 +200,7 @@ public class HybridGen extends IndependentPlotGenerator {
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 { } else {
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, true, false, biomes); placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, roadFeatures);
} }
} }
} }
@ -204,7 +212,7 @@ public class HybridGen extends IndependentPlotGenerator {
result.setBlock(x, y, z, hybridPlotWorld.ROAD_BLOCK.toPattern()); result.setBlock(x, y, z, hybridPlotWorld.ROAD_BLOCK.toPattern());
} }
if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) { if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, true, false, biomes); placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, roadFeatures);
} }
} else if (insideWallZ[z]) { } else if (insideWallZ[z]) {
// wall // wall
@ -216,7 +224,7 @@ public class HybridGen extends IndependentPlotGenerator {
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 { } else {
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, true, false, biomes); placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, roadFeatures);
} }
} else { } else {
// plot // plot
@ -225,7 +233,7 @@ public class HybridGen extends IndependentPlotGenerator {
} }
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) { if (hybridPlotWorld.PLOT_SCHEMATIC) {
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, false, false, biomes); placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, plotFeatures);
} }
} }
} }
@ -239,6 +247,9 @@ public class HybridGen extends IndependentPlotGenerator {
if (!hybridPlotWorld.populationNeeded()) { if (!hybridPlotWorld.populationNeeded()) {
return false; return false;
} }
EnumSet<SchematicFeature> roadFeatures = EnumSet.of(SchematicFeature.POPULATING, SchematicFeature.ROAD);
EnumSet<SchematicFeature> plotFeatures = EnumSet.of(SchematicFeature.POPULATING);
// Coords // Coords
Location min = result.getMin(); Location min = result.getMin();
int bx = min.getX() - hybridPlotWorld.ROAD_OFFSET_X; int bx = min.getX() - hybridPlotWorld.ROAD_OFFSET_X;
@ -303,17 +314,17 @@ public class HybridGen extends IndependentPlotGenerator {
if (insideRoadX[x] || insideWallX[x]) { if (insideRoadX[x] || insideWallX[x]) {
if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) { if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
for (short z = 0; z < 16; z++) { for (short z = 0; z < 16; z++) {
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, true, true, false); placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, roadFeatures);
} }
} }
} else { } else {
for (short z = 0; z < 16; z++) { for (short z = 0; z < 16; z++) {
if (insideRoadZ[z] || insideWallZ[z]) { if (insideRoadZ[z] || insideWallZ[z]) {
if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) { if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, true, true, false); placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, roadFeatures);
} }
} else if (hybridPlotWorld.PLOT_SCHEMATIC) { } else if (hybridPlotWorld.PLOT_SCHEMATIC) {
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, false, true, false); placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, plotFeatures);
} }
} }
} }
@ -442,4 +453,10 @@ public class HybridGen extends IndependentPlotGenerator {
} }
private enum SchematicFeature {
BIOMES,
ROAD,
POPULATING
}
} }