2013-07-27 12:52:30 +02:00
|
|
|
package StevenDimDoors.mod_pocketDim.schematic;
|
|
|
|
|
2013-07-30 19:58:14 +02:00
|
|
|
import StevenDimDoors.mod_pocketDim.Point3D;
|
2013-07-27 12:52:30 +02:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
public abstract class WorldOperation {
|
|
|
|
|
|
|
|
private String name;
|
|
|
|
|
|
|
|
public WorldOperation(String name)
|
|
|
|
{
|
|
|
|
this.name = name;
|
|
|
|
}
|
|
|
|
|
2013-07-27 23:29:55 +02:00
|
|
|
protected boolean initialize(World world, int x, int y, int z, int width, int height, int length)
|
2013-07-27 12:52:30 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected abstract boolean applyToBlock(World world, int x, int y, int z);
|
|
|
|
|
|
|
|
protected boolean finish()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-30 19:58:14 +02:00
|
|
|
public boolean apply(World world, Point3D minCorner, Point3D maxCorner)
|
|
|
|
{
|
|
|
|
int x = minCorner.getX();
|
|
|
|
int y = minCorner.getY();
|
|
|
|
int z = minCorner.getZ();
|
|
|
|
int width = maxCorner.getX() - x + 1;
|
|
|
|
int height = maxCorner.getY() - y + 1;
|
|
|
|
int length = maxCorner.getZ() - z + 1;
|
|
|
|
return apply(world, x, y, z, width, height, length);
|
|
|
|
}
|
|
|
|
|
2013-07-27 12:52:30 +02:00
|
|
|
public boolean apply(World world, int x, int y, int z, int width, int height, int length)
|
|
|
|
{
|
2013-07-27 23:29:55 +02:00
|
|
|
if (!initialize(world, x, y, z, width, height, length))
|
2013-07-27 12:52:30 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
int cx, cy, cz;
|
|
|
|
int limitX = x + width;
|
|
|
|
int limitY = y + height;
|
|
|
|
int limitZ = z + length;
|
|
|
|
|
|
|
|
//The order of these loops is important. Don't change it! It's used to avoid calculating
|
|
|
|
//indeces in some schematic operations. The proper order is YZX.
|
|
|
|
for (cy = y; cy < limitY; cy++)
|
|
|
|
{
|
|
|
|
for (cz = z; cz < limitZ; cz++)
|
|
|
|
{
|
|
|
|
for (cx = x; cx < limitX; cx++)
|
|
|
|
{
|
|
|
|
if (!applyToBlock(world, cx, cy, cz))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String getName()
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString()
|
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
}
|