Fix PathAreaTile
This commit is contained in:
@@ -22,6 +22,7 @@ package de.steamwar.bausystem.region.dynamic.path;
|
|||||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.math.transform.AffineTransform;
|
||||||
import de.steamwar.bausystem.region.Point;
|
import de.steamwar.bausystem.region.Point;
|
||||||
import de.steamwar.bausystem.region.Region;
|
import de.steamwar.bausystem.region.Region;
|
||||||
import de.steamwar.bausystem.region.RegionSystem;
|
import de.steamwar.bausystem.region.RegionSystem;
|
||||||
@@ -39,40 +40,44 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
public class PathAreaTile implements Region.Area {
|
public class PathAreaTile implements 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_actual");
|
||||||
private static final File PATH_CENTER = new File(PATH_DIR, "PathCenter.schem");
|
private static final File PATH_CENTER = new File(PATH_DIR, "PathCenter.schem");
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
private enum Path {
|
private enum Path {
|
||||||
North(0, -18, 5, 0),
|
North(0, -18, 5, 0, 0),
|
||||||
South(0, 19, 5, 14),
|
South(0, 19, 5, 0, 180),
|
||||||
West(-18, 0, 0, 5),
|
West(-18, 0, 5, 0, 90),
|
||||||
East(19, 0, 14, 5),
|
East(19, 0, 5, 0, 270),
|
||||||
;
|
;
|
||||||
|
|
||||||
private final int checkX;
|
private final int checkX;
|
||||||
private final int checkZ;
|
private final int checkZ;
|
||||||
private final int pasteX;
|
private final int pasteX;
|
||||||
private final int pasteZ;
|
private final int pasteZ;
|
||||||
private final Function<RegionType.ConnectionType, File> function = connectionType -> {
|
private final int rotate;
|
||||||
return new File(PATH_DIR, "Path" + name() + connectionType.name() + ".schem");
|
|
||||||
|
private static final Function<RegionType.ConnectionType, File> function = connectionType -> {
|
||||||
|
return new File(PATH_DIR, "PathEdge" + connectionType.name() + ".schem");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
private enum PathCorner {
|
private enum PathCorner {
|
||||||
NorthEast(Path.North, Path.East, 14, 0),
|
NorthEast(Path.North, Path.East, 14, 0, 0),
|
||||||
EastSouth(Path.East, Path.South, 14, 14),
|
EastSouth(Path.East, Path.South, 14, 0, 270),
|
||||||
SouthWest(Path.South, Path.West, 0, 14),
|
SouthWest(Path.South, Path.West, 14, 0, 180),
|
||||||
WestNorth(Path.West, Path.North, 0, 0),
|
WestNorth(Path.West, Path.North, 14, 0, 90),
|
||||||
;
|
;
|
||||||
|
|
||||||
private final Path check1;
|
private final Path check1;
|
||||||
private final Path check2;
|
private final Path check2;
|
||||||
private final int pasteX;
|
private final int pasteX;
|
||||||
private final int pasteZ;
|
private final int pasteZ;
|
||||||
private final TriFunction<RegionType.ConnectionType, RegionType.ConnectionType, RegionType.ConnectionType, File> function = (connectionType1, connectionType2, connectionTypeCorner) -> {
|
private final int rotate;
|
||||||
return new File(PATH_DIR, "Path" + name() + connectionType1.name() + connectionType2.name() + connectionTypeCorner.name() + ".schem");
|
|
||||||
|
private static final TriFunction<RegionType.ConnectionType, RegionType.ConnectionType, RegionType.ConnectionType, File> function = (connectionType1, connectionType2, connectionTypeCorner) -> {
|
||||||
|
return new File(PATH_DIR, "PathCorner" + connectionType1.name() + connectionType2.name() + connectionTypeCorner.name() + ".schem");
|
||||||
};
|
};
|
||||||
|
|
||||||
private interface TriFunction<T, U, V, W> {
|
private interface TriFunction<T, U, V, W> {
|
||||||
@@ -116,20 +121,20 @@ public class PathAreaTile implements Region.Area {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public File getResetFile() {
|
public File getResetFile() {
|
||||||
return null; // TODO: I know what I do!
|
return null; // I know what I do!
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reset(PasteBuilder pasteBuilder, boolean extension) {
|
public void reset(PasteBuilder pasteBuilder, boolean extension) {
|
||||||
Point minPoint = getMinPoint(false);
|
Point minPoint = getMinPoint(false);
|
||||||
|
|
||||||
paste(PATH_CENTER, minPoint.add(5, 0, 5));
|
paste(PATH_CENTER, minPoint.add(5, 0, 5), 0);
|
||||||
|
|
||||||
for (Path path : Path.values()) {
|
for (Path path : Path.values()) {
|
||||||
RegionType.ConnectionType connectionType = RegionSystem.INSTANCE.get(minPoint.add(path.checkX, 0, path.checkZ).toLocation((World) null)).getType().getConnectionType();
|
RegionType.ConnectionType connectionType = RegionSystem.INSTANCE.get(minPoint.add(path.checkX, 0, path.checkZ).toLocation((World) null)).getType().getConnectionType();
|
||||||
File schem = path.function.apply(connectionType);
|
File schem = path.function.apply(connectionType);
|
||||||
if (schem.exists()) {
|
if (schem.exists()) {
|
||||||
paste(schem, minPoint.add(path.pasteX, 0, path.pasteZ));
|
paste(schem, minPoint.add(path.pasteX, 0, path.pasteZ), path.rotate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,17 +144,19 @@ public class PathAreaTile implements Region.Area {
|
|||||||
RegionType.ConnectionType connectionTypeCorner = RegionSystem.INSTANCE.get(minPoint.add(corner.check1.checkX + corner.check2.checkX, 0, corner.check1.checkZ + corner.check2.checkZ).toLocation((World) null)).getType().getConnectionType();
|
RegionType.ConnectionType connectionTypeCorner = RegionSystem.INSTANCE.get(minPoint.add(corner.check1.checkX + corner.check2.checkX, 0, corner.check1.checkZ + corner.check2.checkZ).toLocation((World) null)).getType().getConnectionType();
|
||||||
File schem = corner.function.apply(connectionType1, connectionType2, connectionTypeCorner);
|
File schem = corner.function.apply(connectionType1, connectionType2, connectionTypeCorner);
|
||||||
if (schem.exists()) {
|
if (schem.exists()) {
|
||||||
paste(schem, minPoint.add(corner.pasteX, 0, corner.pasteZ));
|
System.out.println(connectionType1 + " " + connectionType2 + " " + connectionTypeCorner + " " + schem);
|
||||||
|
paste(schem, minPoint.add(corner.pasteX, 0, corner.pasteZ), corner.rotate);
|
||||||
} else {
|
} else {
|
||||||
paste(new File(PATH_DIR, "PathCornerUnknown.schem"), minPoint.add(corner.pasteX, 0, corner.pasteZ));
|
System.out.println(connectionType1 + " " + connectionType2 + " " + connectionTypeCorner + " " + PATH_DIR.getAbsolutePath() + "/PathCornerUnknown.schem");
|
||||||
|
paste(new File(PATH_DIR, "PathCornerUnknown.schem"), minPoint.add(corner.pasteX, 0, corner.pasteZ), corner.rotate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void paste(File file, Point minPoint) {
|
private void paste(File file, Point minPoint, int rotate) {
|
||||||
Clipboard clipboard = FlatteningWrapper.impl.loadSchematic(file);
|
Clipboard clipboard = FlatteningWrapper.impl.loadSchematic(file);
|
||||||
BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
|
BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
|
||||||
BlockVector3 to = minPoint.toBlockVector3().subtract(offset);
|
BlockVector3 to = minPoint.toBlockVector3().subtract(offset);
|
||||||
clipboard.paste(BukkitAdapter.adapt(Bukkit.getWorlds().get(0)), to);
|
clipboard.paste(BukkitAdapter.adapt(Bukkit.getWorlds().get(0)), to, false, true, new AffineTransform().rotateY(rotate));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user