Added Pattern.next(int, int, int).

This method can be used to avoid creating short-lived vectors in tight loops.
This commit is contained in:
TomyLobo 2011-10-31 22:00:53 +01:00
parent 8610dc2c89
commit 02a70cca4a
4 changed files with 33 additions and 4 deletions

View File

@ -54,10 +54,22 @@ public class ClipboardPattern implements Pattern {
* @return * @return
*/ */
public BaseBlock next(Vector pos) { public BaseBlock next(Vector pos) {
int x = Math.abs(pos.getBlockX()) % size.getBlockX(); return next(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
int y = Math.abs(pos.getBlockY()) % size.getBlockY(); }
int z = Math.abs(pos.getBlockZ()) % size.getBlockZ();
return clipboard.getPoint(new Vector(x, y, z)); /**
* Get next block.
*
* @param x
* @param y
* @param z
* @return
*/
public BaseBlock next(int x, int y, int z) {
int xp = Math.abs(x) % size.getBlockX();
int yp = Math.abs(y) % size.getBlockY();
int zp = Math.abs(z) % size.getBlockZ();
return clipboard.getPoint(new Vector(xp, yp, zp));
} }
} }

View File

@ -37,4 +37,13 @@ public interface Pattern {
* @return * @return
*/ */
public BaseBlock next(Vector pos); public BaseBlock next(Vector pos);
/**
* Get a block for a position. This return value of this method does
* not have to be consistent for the same position.
*
* @param pos
* @return
*/
public BaseBlock next(int x, int y, int z);
} }

View File

@ -82,4 +82,8 @@ public class RandomFillPattern implements Pattern {
throw new RuntimeException("ProportionalFillPattern"); throw new RuntimeException("ProportionalFillPattern");
} }
public BaseBlock next(int x, int y, int z) {
return next(null);
}
} }

View File

@ -52,6 +52,10 @@ public class SingleBlockPattern implements Pattern {
return block; return block;
} }
public BaseBlock next(int x, int y, int z) {
return block;
}
/** /**
* Get the block. * Get the block.
* *