Update VariantSelector and implement Database Folder for Schematics

This commit is contained in:
2026-09-07 11:42:22 +02:00
parent 818a437ee0
commit a6d77256a9
13 changed files with 146 additions and 85 deletions
@@ -26,19 +26,19 @@ import lombok.RequiredArgsConstructor;
@Getter @Getter
public enum RegionType { public enum RegionType {
GLOBAL(ConnectionType.Global), GLOBAL(ConnectionType.Void),
/** /**
* This should not be used by the DynamicRegionSystem * This should not be used by the DynamicRegionSystem
*/ */
NORMAL(ConnectionType.Closed), NORMAL(ConnectionType.Plot),
SPAWN(ConnectionType.Closed), SPAWN(ConnectionType.Plot),
SPAWN_PATH(ConnectionType.Path), SPAWN_PATH(ConnectionType.Path),
SPAWN_EXTENSION(ConnectionType.Closed), SPAWN_EXTENSION(ConnectionType.Plot),
PATH(ConnectionType.Path), PATH(ConnectionType.Path),
DRY(ConnectionType.Closed), DRY(ConnectionType.Void),
DRY_SPECIAL(ConnectionType.Closed), DRY_SPECIAL(ConnectionType.Plot),
WET(ConnectionType.Water), WET(ConnectionType.Water),
WET_SPECIAL(ConnectionType.Water), WET_SPECIAL(ConnectionType.Water),
; ;
@@ -66,10 +66,10 @@ public enum RegionType {
} }
public enum ConnectionType { public enum ConnectionType {
Closed, Plot,
Path, Path,
Water, Water,
Global, Void,
Garden, Garden,
} }
} }
@@ -99,7 +99,7 @@ public class DynamicRegionEditor implements SWPlayer.Component, Listener {
moveInteractionEntities(Point.fromLocation(player.getLocation())); moveInteractionEntities(Point.fromLocation(player.getLocation()));
CArea area = new CArea(entityServer); CArea area = new CArea(entityServer);
area.setPos1And2(new Location(null, -Tile.maxTile, 1, -Tile.maxTile), new Location(null, Tile.maxTile, 1, Tile.maxTile)); area.setPos1And2(new Location(null, -Tile.maxTile, 51, -Tile.maxTile), new Location(null, Tile.maxTile, 51, Tile.maxTile));
area.setBlock(Material.BEDROCK.createBlockData()); area.setBlock(Material.BEDROCK.createBlockData());
task = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), this::showHotbar, 0, 20); task = Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), this::showHotbar, 0, 20);
@@ -141,7 +141,7 @@ public class DynamicRegionEditor implements SWPlayer.Component, Listener {
List<RInteraction> interactionList = entityServer.getEntitiesByType(RInteraction.class); List<RInteraction> interactionList = entityServer.getEntitiesByType(RInteraction.class);
for (int x = -5; x <= 5; x++) { for (int x = -5; x <= 5; x++) {
for (int z = -5; z <= 5; z++) { for (int z = -5; z <= 5; z++) {
interactionList.removeFirst().move(position.getX() + x + 0.5, 0, position.getZ() + z + 0.5, 0, 0, (byte) 0); interactionList.removeFirst().move(position.getX() + x + 0.5, 50, position.getZ() + z + 0.5, 0, 0, (byte) 0);
} }
} }
} }
@@ -191,7 +191,7 @@ public class DynamicRegionEditor implements SWPlayer.Component, Listener {
for (RInteraction interaction : entityServer.getEntitiesByType(RInteraction.class)) { for (RInteraction interaction : entityServer.getEntitiesByType(RInteraction.class)) {
float x = (float) (interaction.getX() - 0.5); float x = (float) (interaction.getX() - 0.5);
float z = (float) (interaction.getZ() - 0.5); float z = (float) (interaction.getZ() - 0.5);
if (intersection.test(x, (float) 0.95, z, x + 1, (float) 1.05, z + 1)) { if (intersection.test(x, (float) 50.95, z, x + 1, (float) 51.05, z + 1)) {
int tileX = (int) x; int tileX = (int) x;
int tileZ = (int) z; int tileZ = (int) z;
if (type.visualize(area, tileX, tileZ)) { if (type.visualize(area, tileX, tileZ)) {
@@ -216,7 +216,7 @@ public class DynamicRegionEditor implements SWPlayer.Component, Listener {
for (RInteraction interaction : entityServer.getEntitiesByType(RInteraction.class)) { for (RInteraction interaction : entityServer.getEntitiesByType(RInteraction.class)) {
float x = (float) (interaction.getX() - 0.5); float x = (float) (interaction.getX() - 0.5);
float z = (float) (interaction.getZ() - 0.5); float z = (float) (interaction.getZ() - 0.5);
if (intersection.test(x, (float) 0.95, z, x + 1, (float) 1.05, z + 1)) { if (intersection.test(x, (float) 50.95, z, x + 1, (float) 51.05, z + 1)) {
int tileX = (int) x; int tileX = (int) x;
int tileZ = (int) z; int tileZ = (int) z;
type.run(event.getPlayer(), tileX, tileZ); type.run(event.getPlayer(), tileX, tileZ);
@@ -318,8 +318,8 @@ public class DynamicRegionEditor implements SWPlayer.Component, Listener {
} }
private boolean selectSpawn(CArea area) { private boolean selectSpawn(CArea area) {
Location minLoc = new Location(null, -1, 1, -1); Location minLoc = new Location(null, -1, 51, -1);
Location maxLoc = new Location(null, 1, 1, 1); Location maxLoc = new Location(null, 1, 51, 1);
area.setBlock(DELETE); area.setBlock(DELETE);
area.setPos1And2(minLoc, maxLoc); area.setPos1And2(minLoc, maxLoc);
valid = true; valid = true;
@@ -333,8 +333,8 @@ public class DynamicRegionEditor implements SWPlayer.Component, Listener {
valid = false; valid = false;
return false; return false;
} }
Location minLoc = new Location(null, minTile.getTileX(), 1, minTile.getTileZ()); Location minLoc = new Location(null, minTile.getTileX(), 51, minTile.getTileZ());
Location maxLoc = new Location(null, maxTile.getTileX(), 1, maxTile.getTileZ()); Location maxLoc = new Location(null, maxTile.getTileX(), 51, maxTile.getTileZ());
area.setBlock(DELETE); area.setBlock(DELETE);
area.setPos1And2(minLoc, maxLoc); area.setPos1And2(minLoc, maxLoc);
valid = true; valid = true;
@@ -496,7 +496,7 @@ public class DynamicRegionEditor implements SWPlayer.Component, Listener {
area.setBlock(INVALID); area.setBlock(INVALID);
valid = false; valid = false;
} }
area.setPos1And2(new Location(null, tileX, 1, tileZ), new Location(null, tileX + widthX, 1, tileZ + widthZ)); area.setPos1And2(new Location(null, tileX, 51, tileZ), new Location(null, tileX + widthX, 51, tileZ + widthZ));
return true; return true;
} }
@@ -39,7 +39,7 @@ public class DynamicRegionVisualizer implements SWPlayer.Component {
private final REntityServer entityServer = new REntityServer(); private final REntityServer entityServer = new REntityServer();
private DynamicRegionVisualizer() { private DynamicRegionVisualizer() {
RTextDisplay text = new RTextDisplay(entityServer, new Location(null, 0.5, 1.1, 0.5)); RTextDisplay text = new RTextDisplay(entityServer, new Location(null, 0.5, 51.1, 0.5));
text.setText("Spawn"); text.setText("Spawn");
text.setBillboard(Display.Billboard.VERTICAL); text.setBillboard(Display.Billboard.VERTICAL);
text.setBackgroundColor(0); text.setBackgroundColor(0);
@@ -73,7 +73,7 @@ public class DynamicRegionVisualizer implements SWPlayer.Component {
public static Point toVisualization(Location worldLocation) { public static Point toVisualization(Location worldLocation) {
Tile tile = Tile.fromLocation(worldLocation).orElseThrow(); Tile tile = Tile.fromLocation(worldLocation).orElseThrow();
return new Point(tile.getTileX(), 0, tile.getTileZ()); return new Point(tile.getTileX(), 50, tile.getTileZ());
} }
private static class CRegion extends CEntity { private static class CRegion extends CEntity {
@@ -96,7 +96,7 @@ public class DynamicRegionVisualizer implements SWPlayer.Component {
area.setPos1And2(point.toLocation((World) null).add(0, 1 - CArea.DEFAULT_WIDTH, 0), point.toLocation((World) null).add(widthX - 1, 1 - CArea.DEFAULT_WIDTH, widthZ - 1)); area.setPos1And2(point.toLocation((World) null).add(0, 1 - CArea.DEFAULT_WIDTH, 0), point.toLocation((World) null).add(widthX - 1, 1 - CArea.DEFAULT_WIDTH, widthZ - 1));
entities.add(area); entities.add(area);
RTextDisplay text = new RTextDisplay(server, point.toLocation((World) null).add(widthX / 2.0, 1.1, widthZ / 2.0)); RTextDisplay text = new RTextDisplay(server, point.toLocation((World) null).add(widthX / 2.0, 51.1, widthZ / 2.0));
text.setText(data.name()); text.setText(data.name());
text.setBillboard(Display.Billboard.VERTICAL); text.setBillboard(Display.Billboard.VERTICAL);
text.setBackgroundColor(0); text.setBackgroundColor(0);
@@ -29,10 +29,13 @@ import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import de.steamwar.bausystem.region.Point; import de.steamwar.bausystem.region.Point;
import de.steamwar.bausystem.utils.FlatteningWrapper; import de.steamwar.bausystem.utils.FlatteningWrapper;
import de.steamwar.sql.SchematicData;
import de.steamwar.sql.SchematicNode;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import java.io.File; import java.io.File;
import java.io.IOException;
@UtilityClass @UtilityClass
public class PasteUtils { public class PasteUtils {
@@ -52,11 +55,23 @@ public class PasteUtils {
public static EditSession paste(File file, Point minPoint, int rotate) { public static EditSession paste(File file, Point minPoint, int rotate) {
try (Clipboard clipboard = FlatteningWrapper.impl.loadSchematic(file)) { try (Clipboard clipboard = FlatteningWrapper.impl.loadSchematic(file)) {
BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); return paste(clipboard, minPoint, rotate);
BlockVector3 to = minPoint.toBlockVector3().subtract(offset);
return clipboard.paste(BukkitAdapter.adapt(Bukkit.getWorlds().get(0)), to, false, true, new AffineTransform().rotateY(rotate));
} catch (SecurityException exception) { } catch (SecurityException exception) {
return null; return null;
} }
} }
public static EditSession paste(SchematicNode schematic, Point minPoint, int rotate) {
try (Clipboard clipboard = new SchematicData(schematic).load()) {
return paste(clipboard, minPoint, rotate);
} catch (SecurityException | IOException exception) {
return null;
}
}
private static EditSession paste(Clipboard clipboard, Point minPoint, int rotate) {
BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
BlockVector3 to = minPoint.toBlockVector3().subtract(offset);
return clipboard.paste(BukkitAdapter.adapt(Bukkit.getWorlds().get(0)), to, false, true, new AffineTransform().rotateY(rotate));
}
} }
@@ -115,6 +115,10 @@ public class Tile {
return new Location(null, getMinX(tileX), 0, getMinZ(tileZ)); return new Location(null, getMinX(tileX), 0, getMinZ(tileZ));
} }
public Point getMinPoint() {
return new Point(getMinX(tileX), 0, getMinZ(tileZ));
}
public Location getMinLocation() { public Location getMinLocation() {
return getMinLocation(tileX, tileZ); return getMinLocation(tileX, tileZ);
} }
@@ -19,6 +19,7 @@
package de.steamwar.bausystem.region.dynamic; package de.steamwar.bausystem.region.dynamic;
import de.steamwar.sql.SchematicNode;
import lombok.NonNull; import lombok.NonNull;
import java.io.File; import java.io.File;
@@ -34,7 +35,7 @@ public abstract class VariantSelector {
private static final Random RANDOM = new Random(); private static final Random RANDOM = new Random();
public static final VariantSelector EMPTY = new VariantSelector() { public static final VariantSelector EMPTY = new VariantSelector() {
@Override @Override
public Optional<File> select() { public Optional<SchematicNode> select() {
return Optional.empty(); return Optional.empty();
} }
}; };
@@ -42,14 +43,14 @@ public abstract class VariantSelector {
private VariantSelector() { private VariantSelector() {
} }
public abstract Optional<File> select(); public abstract Optional<SchematicNode> select();
public final VariantSelector or(VariantSelector other) { public final VariantSelector or(VariantSelector other) {
if (this == EMPTY) return other; if (this == EMPTY) return other;
VariantSelector self = this; VariantSelector self = this;
return new VariantSelector() { return new VariantSelector() {
@Override @Override
public Optional<File> select() { public Optional<SchematicNode> select() {
return self.select().or(() -> other.select()); return self.select().or(() -> other.select());
} }
}; };
@@ -60,7 +61,7 @@ public abstract class VariantSelector {
VariantSelector self = this; VariantSelector self = this;
return new VariantSelector() { return new VariantSelector() {
@Override @Override
public Optional<File> select() { public Optional<SchematicNode> select() {
LocalDate date = LocalDate.now(); LocalDate date = LocalDate.now();
if (date.getDayOfMonth() == day && date.getMonth() == month) { if (date.getDayOfMonth() == day && date.getMonth() == month) {
return self.select(); return self.select();
@@ -78,8 +79,9 @@ public abstract class VariantSelector {
final File file = files[0]; final File file = files[0];
return new VariantSelector() { return new VariantSelector() {
@Override @Override
public Optional<File> select() { public Optional<SchematicNode> select() {
return Optional.of(file); return Optional.empty();
// return Optional.of(file);
} }
}; };
} }
@@ -88,8 +90,41 @@ public abstract class VariantSelector {
final int filesCount = files.length; final int filesCount = files.length;
return new VariantSelector() { return new VariantSelector() {
@Override @Override
public Optional<File> select() { public Optional<SchematicNode> select() {
return Optional.of(files[RANDOM.nextInt(filesCount)]); return Optional.empty();
// return Optional.of(files[RANDOM.nextInt(filesCount)]);
}
};
}
public static VariantSelector Folder(int folderId) {
SchematicNode[] schematics = SchematicNode.getSchematicNodeInNode(folderId).toArray(SchematicNode[]::new);
if (schematics.length == 0) return EMPTY;
if (schematics.length == 1) {
final SchematicNode node = schematics[0];
return new VariantSelector() {
@Override
public Optional<SchematicNode> select() {
return Optional.of(node);
}
};
}
final int count = schematics.length;
return new VariantSelector() {
@Override
public Optional<SchematicNode> select() {
return Optional.of(schematics[RANDOM.nextInt(count)]);
}
};
}
public static VariantSelector Schematic(int schematicId) {
SchematicNode schematic = SchematicNode.getSchematicNode(schematicId);
return new VariantSelector() {
@Override
public Optional<SchematicNode> select() {
return Optional.of(schematic);
} }
}; };
} }
@@ -161,7 +161,7 @@ public class AreaBlock extends Region.Area {
@Override @Override
public void place(PasteBuilder pasteBuilder, boolean extension) { public void place(PasteBuilder pasteBuilder, boolean extension) {
EditSession editSession = pasteBuilder EditSession editSession = pasteBuilder
.with(PasteBuilder.ClipboardProvider.file(selector.select().orElse(null))) .with(PasteBuilder.ClipboardProvider.schematic(selector.select().orElse(null)))
.pastePoint(copyPoint) .pastePoint(copyPoint)
.run(); .run();
region.getHistory() region.getHistory()
@@ -25,6 +25,7 @@ import de.steamwar.bausystem.region.dynamic.PasteUtils;
import de.steamwar.bausystem.region.dynamic.Tile; import de.steamwar.bausystem.region.dynamic.Tile;
import de.steamwar.bausystem.region.dynamic.VariantSelector; import de.steamwar.bausystem.region.dynamic.VariantSelector;
import de.steamwar.bausystem.utils.PasteBuilder; import de.steamwar.bausystem.utils.PasteBuilder;
import de.steamwar.sql.SchematicNode;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
@@ -66,7 +67,7 @@ public class AreaTile extends Region.Area {
@Override @Override
public void place(PasteBuilder pasteBuilder, boolean extension) { public void place(PasteBuilder pasteBuilder, boolean extension) {
File resetFile = selector.select().orElse(null); SchematicNode reset = selector.select().orElse(null);
if (resetFile != null) PasteUtils.paste(resetFile, minPoint, 0); if (reset != null) PasteUtils.paste(reset, minPoint, 0);
} }
} }
@@ -31,6 +31,7 @@ import de.steamwar.bausystem.region.dynamic.VariantSelector;
import de.steamwar.bausystem.region.dynamic.spawn.SpawnRegion; import de.steamwar.bausystem.region.dynamic.spawn.SpawnRegion;
import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.shared.Pair;
import de.steamwar.bausystem.utils.PasteBuilder; import de.steamwar.bausystem.utils.PasteBuilder;
import de.steamwar.sql.SchematicNode;
import lombok.NonNull; import lombok.NonNull;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -46,15 +47,15 @@ public class PathArea extends Region.Area {
private static final File PATH_DIR = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "sections/path"); private static final File PATH_DIR = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "sections/path");
private static final File FALLBACK_SCHEM = new File(PATH_DIR, "Fallback.schem"); private static final File FALLBACK_SCHEM = new File(PATH_DIR, "Fallback.schem");
private static final VariantSelector CENTER_NORMAL = VariantSelector.Get(new File(PATH_DIR, "center/normal")); private static final VariantSelector CENTER = VariantSelector.Folder(179927);
private static final VariantSelector SIDE_GLOBAL = VariantSelector.Get(new File(PATH_DIR, "side/global")); private static final VariantSelector SIDE_VOID = VariantSelector.Folder(179930);
private static final VariantSelector CORNER_INNER_GLOBAL = VariantSelector.Get(new File(PATH_DIR, "cinner/global")); private static final VariantSelector CORNER_INNER_VOID = VariantSelector.Folder(179937);
private static final VariantSelector CORNER_OUTER_GLOBAL = VariantSelector.Get(new File(PATH_DIR, "couter/global")); private static final VariantSelector CORNER_OUTER_VOID = VariantSelector.Folder(179942);
private static final VariantSelector SIDE_WATER = VariantSelector.Get(new File(PATH_DIR, "side/water")); private static final VariantSelector SIDE_WATER = VariantSelector.Folder(179931);
private static final VariantSelector CORNER_INNER_WATER = VariantSelector.Get(new File(PATH_DIR, "cinner/water")); private static final VariantSelector CORNER_INNER_WATER = VariantSelector.Folder(179938);
private static final VariantSelector CORNER_OUTER_WATER = VariantSelector.Get(new File(PATH_DIR, "couter/water")); private static final VariantSelector CORNER_OUTER_WATER = VariantSelector.Folder(179943);
private static final VariantSelector SIDE_CLOSED = VariantSelector.Get(new File(PATH_DIR, "side/closed")); private static final VariantSelector SIDE_CLOSED = VariantSelector.Get(new File(PATH_DIR, "side/closed"));
private static final VariantSelector CORNER_INNER_CLOSED = VariantSelector.Get(new File(PATH_DIR, "cinner/closed")); private static final VariantSelector CORNER_INNER_CLOSED = VariantSelector.Get(new File(PATH_DIR, "cinner/closed"));
@@ -67,23 +68,23 @@ public class PathArea extends Region.Area {
private static final VariantSelector CORNER_OUTER_GARDEN = VariantSelector.Get(new File(PATH_DIR, "couter/garden")); private static final VariantSelector CORNER_OUTER_GARDEN = VariantSelector.Get(new File(PATH_DIR, "couter/garden"));
private static final SelectorSide SELECTOR_SIDE = new SelectorSide() private static final SelectorSide SELECTOR_SIDE = new SelectorSide()
.Case(Path, CENTER_NORMAL) .Case(Path, CENTER)
.Case(Global, SIDE_GLOBAL) .Case(Void, SIDE_VOID)
.Case(Water, SIDE_WATER) .Case(Water, SIDE_WATER)
.Case(Closed, SIDE_CLOSED) .Case(Plot, SIDE_CLOSED)
.Case(Garden, SIDE_GARDEN_CONNECTED); .Case(Garden, SIDE_GARDEN_CONNECTED);
private static final SelectorCorner SELECTOR_CORNER = new SelectorCorner() private static final SelectorCorner SELECTOR_CORNER = new SelectorCorner()
// Path to Path // Path to Path
.Case(Path, Path, Path, CENTER_NORMAL, RotationCorrection.UsingOrdinal) .Case(Path, Path, Path, CENTER, RotationCorrection.UsingOrdinal)
// Path to Global // Path to Global
.Case(Path, Global, Global, SIDE_GLOBAL, RotationCorrection.WithCorrection) .Case(Path, Void, Void, SIDE_VOID, RotationCorrection.WithCorrection)
.Case(Global, Path, Path, SIDE_GLOBAL) .Case(Void, Path, Path, SIDE_VOID)
.Case(Global, Path, Global, SIDE_GLOBAL) .Case(Void, Path, Void, SIDE_VOID)
.Case(Path, Global, Path, SIDE_GLOBAL, RotationCorrection.WithCorrection) .Case(Path, Void, Path, SIDE_VOID, RotationCorrection.WithCorrection)
.Case(Global, Global, Global, CORNER_OUTER_GLOBAL, RotationCorrection.UsingOrdinal) .Case(Void, Void, Void, CORNER_OUTER_VOID, RotationCorrection.UsingOrdinal)
.Case(Global, Global, Path, CORNER_OUTER_GLOBAL, RotationCorrection.UsingOrdinal) .Case(Void, Void, Path, CORNER_OUTER_VOID, RotationCorrection.UsingOrdinal)
.Case(Path, Path, Global, CORNER_INNER_GLOBAL, RotationCorrection.UsingOrdinal) .Case(Path, Path, Void, CORNER_INNER_VOID, RotationCorrection.UsingOrdinal)
// Path to Water // Path to Water
.Case(Path, Water, Water, SIDE_WATER, RotationCorrection.WithCorrection) .Case(Path, Water, Water, SIDE_WATER, RotationCorrection.WithCorrection)
.Case(Water, Path, Path, SIDE_WATER) .Case(Water, Path, Path, SIDE_WATER)
@@ -93,13 +94,13 @@ public class PathArea extends Region.Area {
.Case(Water, Water, Path, CORNER_OUTER_WATER, RotationCorrection.UsingOrdinal) .Case(Water, Water, Path, CORNER_OUTER_WATER, RotationCorrection.UsingOrdinal)
.Case(Path, Path, Water, CORNER_INNER_WATER, RotationCorrection.UsingOrdinal) .Case(Path, Path, Water, CORNER_INNER_WATER, RotationCorrection.UsingOrdinal)
// Path to Closed // Path to Closed
.Case(Path, Closed, Closed, SIDE_CLOSED, RotationCorrection.WithCorrection) .Case(Path, Plot, Plot, SIDE_CLOSED, RotationCorrection.WithCorrection)
.Case(Closed, Path, Path, SIDE_CLOSED) .Case(Plot, Path, Path, SIDE_CLOSED)
.Case(Closed, Path, Closed, SIDE_CLOSED) .Case(Plot, Path, Plot, SIDE_CLOSED)
.Case(Path, Closed, Path, SIDE_CLOSED, RotationCorrection.WithCorrection) .Case(Path, Plot, Path, SIDE_CLOSED, RotationCorrection.WithCorrection)
.Case(Closed, Closed, Closed, CORNER_OUTER_CLOSED, RotationCorrection.UsingOrdinal) .Case(Plot, Plot, Plot, CORNER_OUTER_CLOSED, RotationCorrection.UsingOrdinal)
.Case(Closed, Closed, Path, CORNER_OUTER_CLOSED, RotationCorrection.UsingOrdinal) .Case(Plot, Plot, Path, CORNER_OUTER_CLOSED, RotationCorrection.UsingOrdinal)
.Case(Path, Path, Closed, CORNER_INNER_CLOSED, RotationCorrection.UsingOrdinal) .Case(Path, Path, Plot, CORNER_INNER_CLOSED, RotationCorrection.UsingOrdinal)
// Path to Garden // Path to Garden
.Case(Path, Garden, Garden, SIDE_GARDEN, RotationCorrection.WithCorrection) .Case(Path, Garden, Garden, SIDE_GARDEN, RotationCorrection.WithCorrection)
.Case(Garden, Path, Path, SIDE_GARDEN) .Case(Garden, Path, Path, SIDE_GARDEN)
@@ -159,27 +160,29 @@ public class PathArea extends Region.Area {
} }
public void reset(PathSide side) { public void reset(PathSide side) {
File resetFile = null; SchematicNode reset = null;
VariantSelector selector = SELECTOR_SIDE.Select(tile, side); VariantSelector selector = SELECTOR_SIDE.Select(tile, side);
if (selector != null) resetFile = selector.select().orElse(null); if (selector != null) reset = selector.select().orElse(null);
if (selector == null || resetFile == null) { if (selector == null || reset == null) {
if (!BauSystem.DEV_SERVER) return; if (!BauSystem.DEV_SERVER) return;
resetFile = FALLBACK_SCHEM; // reset = FALLBACK_SCHEM;
return;
} }
PasteUtils.paste(resetFile, minPoint.add(side.pasteOffsetX, 0, side.pasteOffsetZ), side.rotate); PasteUtils.paste(reset, minPoint.add(side.pasteOffsetX, 0, side.pasteOffsetZ), side.rotate);
} }
public void reset(PathCorner corner) { public void reset(PathCorner corner) {
File resetFile = null; SchematicNode reset = null;
Pair<VariantSelector, RotationCorrection> pair = SELECTOR_CORNER.Select(tile, corner); Pair<VariantSelector, RotationCorrection> pair = SELECTOR_CORNER.Select(tile, corner);
VariantSelector selector = pair.getKey(); VariantSelector selector = pair.getKey();
RotationCorrection rotationCorrection = pair.getValue(); RotationCorrection rotationCorrection = pair.getValue();
if (selector != null) resetFile = selector.select().orElse(null); if (selector != null) reset = selector.select().orElse(null);
if (selector == null || resetFile == null) { if (selector == null || reset == null) {
if (!BauSystem.DEV_SERVER) return; if (!BauSystem.DEV_SERVER) return;
resetFile = FALLBACK_SCHEM; // reset = FALLBACK_SCHEM;
rotationCorrection = RotationCorrection.Unchanged; // rotationCorrection = RotationCorrection.Unchanged;
return;
} }
int rotate = corner.rotate; int rotate = corner.rotate;
@@ -194,22 +197,22 @@ public class PathArea extends Region.Area {
break; break;
} }
PasteUtils.paste(resetFile, minPoint.add(corner.pasteOffsetX, 0, corner.pasteOffsetZ), rotate); PasteUtils.paste(reset, minPoint.add(corner.pasteOffsetX, 0, corner.pasteOffsetZ), rotate);
} }
@Override @Override
public void place(PasteBuilder pasteBuilder, boolean extension) { public void place(PasteBuilder pasteBuilder, boolean extension) {
if (region.isGarden()) { if (region.isGarden()) {
File resetFile = GARDEN.select().orElse(null); SchematicNode reset = GARDEN.select().orElse(null);
if (resetFile != null) { if (reset != null) {
PasteUtils.paste(resetFile, minPoint, 0); PasteUtils.paste(reset, minPoint, 0);
} }
return; return;
} }
File resetFile = CENTER_NORMAL.select().orElse(null); SchematicNode reset = CENTER.select().orElse(null);
if (resetFile != null) { if (reset != null) {
PasteUtils.paste(resetFile, minPoint.add(7, 0, 7), 0); PasteUtils.paste(reset, minPoint.add(7, 0, 7), 0);
} }
for (PathSide side : PathSide.values()) { for (PathSide side : PathSide.values()) {
@@ -227,7 +230,7 @@ public class PathArea extends Region.Area {
optionalTile = optionalTile.flatMap(t -> t.add(optionalSide.tileOffsetX, optionalSide.tileOffsetZ)); optionalTile = optionalTile.flatMap(t -> t.add(optionalSide.tileOffsetX, optionalSide.tileOffsetZ));
} }
if (optionalTile.isEmpty()) { if (optionalTile.isEmpty()) {
return Global; return Void;
} }
tile = optionalTile.get(); tile = optionalTile.get();
Region region = DynamicRegionSystem.INSTANCE.get(tile); Region region = DynamicRegionSystem.INSTANCE.get(tile);
@@ -238,7 +241,7 @@ public class PathArea extends Region.Area {
if (optionalSide == null && side.opposite().equals(spawnRegion.getPathSide())) { if (optionalSide == null && side.opposite().equals(spawnRegion.getPathSide())) {
return spawnPathConnection; return spawnPathConnection;
} else { } else {
return Closed; return Plot;
} }
} }
return region.getType().getConnectionType(); return region.getType().getConnectionType();
@@ -29,9 +29,7 @@ import lombok.NonNull;
import org.bukkit.Material; import org.bukkit.Material;
import java.io.IOException; import java.io.IOException;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
@RegionConstructorData( @RegionConstructorData(
identifier = "path", identifier = "path",
@@ -59,8 +59,8 @@ class SelectorCorner {
} }
public Pair<VariantSelector, PathArea.RotationCorrection> Select(Tile tile, PathCorner corner) { public Pair<VariantSelector, PathArea.RotationCorrection> Select(Tile tile, PathCorner corner) {
RegionType.ConnectionType left = PathArea.getConnectionType(tile, corner.side1, null, RegionType.ConnectionType.Closed); RegionType.ConnectionType left = PathArea.getConnectionType(tile, corner.side1, null, RegionType.ConnectionType.Plot);
RegionType.ConnectionType right = PathArea.getConnectionType(tile, corner.side2, null, RegionType.ConnectionType.Closed); RegionType.ConnectionType right = PathArea.getConnectionType(tile, corner.side2, null, RegionType.ConnectionType.Plot);
RegionType.ConnectionType diagonal = PathArea.getConnectionType(tile, corner.side1, corner.side2); RegionType.ConnectionType diagonal = PathArea.getConnectionType(tile, corner.side1, corner.side2);
int index = getIndex(left, right, diagonal); int index = getIndex(left, right, diagonal);
return new Pair<>(selectors[index], rotationCorrections[index]); return new Pair<>(selectors[index], rotationCorrections[index]);
@@ -24,7 +24,9 @@ import de.steamwar.bausystem.region.Point;
import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.Region;
import de.steamwar.bausystem.region.RegionType; import de.steamwar.bausystem.region.RegionType;
import de.steamwar.bausystem.region.dynamic.DynamicRegion; import de.steamwar.bausystem.region.dynamic.DynamicRegion;
import de.steamwar.bausystem.region.dynamic.PasteUtils;
import de.steamwar.bausystem.region.dynamic.Tile; import de.steamwar.bausystem.region.dynamic.Tile;
import de.steamwar.bausystem.region.dynamic.VariantSelector;
import de.steamwar.bausystem.utils.PasteBuilder; import de.steamwar.bausystem.utils.PasteBuilder;
import lombok.NonNull; import lombok.NonNull;
@@ -32,6 +34,8 @@ import java.util.List;
public class SpawnArea extends Region.Area { public class SpawnArea extends Region.Area {
private static final VariantSelector SPAWN_BIG = VariantSelector.Schematic(179980);
private final Tile tile; private final Tile tile;
public SpawnArea(Tile tile) { public SpawnArea(Tile tile) {
@@ -60,7 +64,7 @@ public class SpawnArea extends Region.Area {
.toList(); .toList();
if (regions.stream().map(DynamicRegion::getType).allMatch(RegionType::isSpawn)) { if (regions.stream().map(DynamicRegion::getType).allMatch(RegionType::isSpawn)) {
// TODO: Implement big spawn! PasteUtils.paste(SPAWN_BIG.select().orElseThrow(), Tile.TILE_NN.getMinPoint().setY(WORLD_MIN_Y), 0);
return; return;
} }
@@ -28,6 +28,7 @@ import de.steamwar.bausystem.region.dynamic.PasteUtils;
import de.steamwar.bausystem.region.dynamic.Tile; import de.steamwar.bausystem.region.dynamic.Tile;
import de.steamwar.bausystem.region.dynamic.VariantSelector; import de.steamwar.bausystem.region.dynamic.VariantSelector;
import de.steamwar.bausystem.utils.PasteBuilder; import de.steamwar.bausystem.utils.PasteBuilder;
import de.steamwar.sql.SchematicNode;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -103,8 +104,8 @@ public class SpecialArea extends Region.Area {
@Override @Override
public void place(PasteBuilder pasteBuilder, boolean extension) { public void place(PasteBuilder pasteBuilder, boolean extension) {
File resetFile = resetFiles.select().orElse(null); SchematicNode reset = resetFiles.select().orElse(null);
if (resetFile != null) PasteUtils.paste(resetFile, minPoint, 0); if (reset != null) PasteUtils.paste(reset, minPoint, 0);
resetting = false; resetting = false;
} }
} }