DimDoors/StevenDimDoors/mod_pocketDim/schematic/CompactBoundsOperation.java
SenseiKiwi 77efb63a5f Improved Schematic Class
Improved the Schematic class. Added support for reading schematic files.
That functionality still needs to be integrated and tested. Made minor
changes to WorldOperation and its derived classes. Also fixed a few bugs
in Schematic's export functions that were found during testing. The
exporting code still doesn't do all the changes (e.g. block
standardization) that had been implemented before.
2013-07-27 17:29:55 -04:00

73 lines
1.5 KiB
Java

package StevenDimDoors.mod_pocketDim.schematic;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.Point3D;
public class CompactBoundsOperation extends WorldOperation
{
private int minX;
private int minY;
private int minZ;
private int maxX;
private int maxY;
private int maxZ;
public CompactBoundsOperation()
{
super("CompactBoundsOperation");
}
@Override
protected boolean initialize(World world, int x, int y, int z, int width, int height, int length)
{
minX = Integer.MAX_VALUE;
minY = Integer.MAX_VALUE;
minZ = Integer.MAX_VALUE;
maxX = x;
maxY = y;
maxZ = z;
return true;
}
@Override
protected boolean applyToBlock(World world, int x, int y, int z)
{
//This could be done more efficiently, but honestly, this is the simplest approach and it
//makes it easy for us to verify that the code is correct.
if (!world.isAirBlock(x, y, z))
{
maxX = x > maxX ? x : maxX;
maxZ = z > maxZ ? z : maxZ;
maxY = y > maxY ? y : maxY;
minX = x < minX ? x : minX;
minZ = z < minZ ? z : minZ;
minY = y < minY ? y : minY;
}
return true;
}
protected boolean finish()
{
if (minX == Integer.MAX_VALUE)
{
//The whole search space was empty!
//Compact the space to a single block.
minX = maxX;
minY = maxY;
minZ = maxZ;
return false;
}
return true;
}
public Point3D getMaxCorner()
{
return new Point3D(maxX, maxY, maxZ);
}
public Point3D getMinCorner()
{
return new Point3D(minX, minY, minZ);
}
}