mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Schematic Placement
This commit is contained in:
parent
9940e61fec
commit
0d55247dd9
@ -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)
|
||||||
{
|
{
|
||||||
@ -43,7 +45,7 @@ public class Schematic
|
|||||||
public void computeMountShift()
|
public void computeMountShift()
|
||||||
{
|
{
|
||||||
int ly = Integer.MAX_VALUE;
|
int ly = Integer.MAX_VALUE;
|
||||||
|
|
||||||
for(BlockVector i : s.k())
|
for(BlockVector i : s.k())
|
||||||
{
|
{
|
||||||
if(i.getBlockY() < ly)
|
if(i.getBlockY() < ly)
|
||||||
@ -52,9 +54,8 @@ public class Schematic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GList<BlockVector> fmount = new GList<>();
|
GList<BlockVector> fmount = new GList<>();
|
||||||
|
|
||||||
for(BlockVector i : s.k())
|
for(BlockVector i : s.k())
|
||||||
{
|
{
|
||||||
if(i.getBlockY() == ly)
|
if(i.getBlockY() == ly)
|
||||||
@ -62,12 +63,12 @@ public class Schematic
|
|||||||
fmount.add(i);
|
fmount.add(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double avx[] = new double[fmount.size()];
|
double avx[] = new double[fmount.size()];
|
||||||
double avy[] = new double[fmount.size()];
|
double avy[] = new double[fmount.size()];
|
||||||
double avz[] = new double[fmount.size()];
|
double avz[] = new double[fmount.size()];
|
||||||
int c = 0;
|
int c = 0;
|
||||||
|
|
||||||
for(BlockVector i : fmount)
|
for(BlockVector i : fmount)
|
||||||
{
|
{
|
||||||
avx[c] = i.getBlockX();
|
avx[c] = i.getBlockX();
|
||||||
@ -75,19 +76,21 @@ public class Schematic
|
|||||||
avz[c] = i.getBlockZ();
|
avz[c] = i.getBlockZ();
|
||||||
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)
|
||||||
{
|
{
|
||||||
double g = 0;
|
double g = 0;
|
||||||
|
|
||||||
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,8 +202,14 @@ 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())
|
||||||
{
|
{
|
||||||
MB b = getSchematic().get(i);
|
MB b = getSchematic().get(i);
|
||||||
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user