Save structure center Y level

This commit is contained in:
dfsek 2020-10-02 22:15:05 -07:00
parent 3d428c32d4
commit 28ebd9c31d
2 changed files with 16 additions and 6 deletions

View File

@ -2,6 +2,7 @@ package com.dfsek.terra.structure;
import com.dfsek.terra.Debug; import com.dfsek.terra.Debug;
import org.bukkit.block.data.MultipleFacing; import org.bukkit.block.data.MultipleFacing;
import org.bukkit.util.Vector;
import org.polydev.gaea.math.Range; import org.polydev.gaea.math.Range;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
@ -51,7 +52,7 @@ public class GaeaStructure implements Serializable {
} }
public GaeaStructure(@NotNull Location l1, @NotNull Location l2, @NotNull String id) throws InitializationException { public GaeaStructure(@NotNull Location l1, @NotNull Location l2, @NotNull String id) throws InitializationException {
int centerX = -1, centerZ = -1; int centerX = -1, centerY = -1, centerZ = -1;
this.id = id; this.id = id;
this.uuid = UUID.randomUUID(); this.uuid = UUID.randomUUID();
if(l1.getX() > l2.getX() || l1.getY() > l2.getY() || l1.getZ() > l2.getZ()) throw new IllegalArgumentException("Invalid locations provided!"); if(l1.getX() > l2.getX() || l1.getY() > l2.getY() || l1.getZ() > l2.getZ()) throw new IllegalArgumentException("Invalid locations provided!");
@ -71,6 +72,7 @@ public class GaeaStructure implements Serializable {
useState = false; useState = false;
if(s.getLine(1).equals("[CENTER]")) { if(s.getLine(1).equals("[CENTER]")) {
centerX = x; centerX = x;
centerY = y;
centerZ = z; centerZ = z;
} else if(s.getLine(1).startsWith("[SPAWN=") && s.getLine(1).endsWith("]")) { } else if(s.getLine(1).startsWith("[SPAWN=") && s.getLine(1).endsWith("]")) {
String og = s.getLine(1); String og = s.getLine(1);
@ -97,8 +99,8 @@ public class GaeaStructure implements Serializable {
} }
} }
} }
if(centerX < 0 || centerZ < 0) throw new InitializationException("No structure center specified."); if(centerX < 0 || centerY < 0 || centerZ < 0) throw new InitializationException("No structure center specified.");
structureInfo = new GaeaStructureInfo(l2.getBlockX()-l1.getBlockX()+1, l2.getBlockY()-l1.getBlockY()+1, l2.getBlockZ()-l1.getBlockZ()+1, centerX, centerZ); structureInfo = new GaeaStructureInfo(l2.getBlockX()-l1.getBlockX()+1, l2.getBlockY()-l1.getBlockY()+1, l2.getBlockZ()-l1.getBlockZ()+1, new Vector(centerX, centerY, centerZ));
} }
public ArrayList<StructureSpawnRequirement> getSpawns() { public ArrayList<StructureSpawnRequirement> getSpawns() {

View File

@ -1,5 +1,7 @@
package com.dfsek.terra.structure; package com.dfsek.terra.structure;
import org.bukkit.util.Vector;
import java.io.Serializable; import java.io.Serializable;
public class GaeaStructureInfo implements Serializable { public class GaeaStructureInfo implements Serializable {
@ -9,12 +11,14 @@ public class GaeaStructureInfo implements Serializable {
private final int sizeZ; private final int sizeZ;
private final int centerX; private final int centerX;
private final int centerZ; private final int centerZ;
public GaeaStructureInfo(int sizeX, int sizeY, int sizeZ, int centerX, int centerZ) { private final int centerY;
public GaeaStructureInfo(int sizeX, int sizeY, int sizeZ, Vector center) {
this.sizeX = sizeX; this.sizeX = sizeX;
this.sizeY = sizeY; this.sizeY = sizeY;
this.sizeZ = sizeZ; this.sizeZ = sizeZ;
this.centerX = centerX; this.centerX = center.getBlockX();
this.centerZ = centerZ; this.centerZ = center.getBlockZ();
this.centerY = center.getBlockY();
} }
public int getSizeX() { public int getSizeX() {
@ -33,6 +37,10 @@ public class GaeaStructureInfo implements Serializable {
return centerX; return centerX;
} }
public int getCenterY() {
return centerY;
}
public int getCenterZ() { public int getCenterZ() {
return centerZ; return centerZ;
} }