Schematic Placement

This commit is contained in:
Daniel Mills 2020-01-08 03:10:26 -05:00
parent 9940e61fec
commit 0d55247dd9
2 changed files with 34 additions and 12 deletions

View File

@ -28,8 +28,10 @@ public class Schematic
private int w; private int w;
private int h; private int h;
private int d; private int d;
private String name = "?";
private final GMap<BlockVector, MB> s; private final GMap<BlockVector, MB> s;
private BlockVector mount; private BlockVector mount;
private int mountHeight;
public Schematic(int w, int h, int d) public Schematic(int w, int h, int d)
{ {
@ -52,7 +54,6 @@ public class Schematic
} }
} }
GList<BlockVector> fmount = new GList<>(); GList<BlockVector> fmount = new GList<>();
for(BlockVector i : s.k()) for(BlockVector i : s.k())
@ -76,7 +77,9 @@ public class Schematic
c++; c++;
} }
mount = new BlockVector(avg(avx), avg(avy), avg(avz)); mountHeight = avg(avy);
mount = new BlockVector(avg(avx), 0, avg(avz));
L.i(" Corrected Mount Point: 0,0,0 -> " + mount.getBlockX() + "," + mount.getBlockY() + "," + mount.getBlockZ());
} }
private int avg(double[] v) private int avg(double[] v)
@ -85,7 +88,7 @@ public class Schematic
for(int i = 0; i < v.length; i++) for(int i = 0; i < v.length; i++)
{ {
g+=v[i]; g += v[i];
} }
return (int) Math.round(g / (double) v.length); return (int) Math.round(g / (double) v.length);
@ -199,7 +202,13 @@ public class Schematic
public void place(World source, int wx, int wy, int wz) public void place(World source, int wx, int wy, int wz)
{ {
Location start = new Location(source, wx, wy, wz).clone().add(sh(w), sh(h) + 1, sh(d)); Location start = new Location(source, wx, wy, wz).clone().add(sh(w), sh(h) + 1, sh(d)).subtract(mount);
int highestY = source.getHighestBlockYAt(start);
if(start.getBlockY() + mountHeight > highestY)
{
start.subtract(0, start.getBlockY() + mountHeight - highestY, 0);
}
for(BlockVector i : getSchematic().k()) for(BlockVector i : getSchematic().k())
{ {
@ -236,10 +245,16 @@ public class Schematic
public static Schematic load(File f) throws IOException public static Schematic load(File f) throws IOException
{ {
Schematic s = new Schematic(1, 1, 1); Schematic s = new Schematic(1, 1, 1);
s.name = f.getName().replaceAll("\\Q.ish\\E", "");
FileInputStream fin = new FileInputStream(f); FileInputStream fin = new FileInputStream(f);
s.read(fin); s.read(fin);
L.i("Loaded Schematic: " + f.getPath() + " Size: " + s.getSchematic().size()); L.i("Loaded Schematic: " + f.getPath() + " Size: " + s.getSchematic().size());
return s; return s;
} }
public String getName()
{
return name;
}
} }

View File

@ -102,5 +102,12 @@ public class SchematicGroup
public void processVariants() public void processVariants()
{ {
L.v("Processing " + name + " Objects"); L.v("Processing " + name + " Objects");
for(Schematic i : getSchematics())
{
L.v("# Processing " + i.getName());
L.flush();
i.computeMountShift();
}
} }
} }