added protection against filler errors and fixed array out of bounds for cylinder, fix #1604
This commit is contained in:
parent
c5a912a222
commit
aa6d085e8b
2 changed files with 42 additions and 27 deletions
|
@ -20,6 +20,7 @@ import buildcraft.api.blueprints.SchematicRegistry;
|
|||
import buildcraft.api.filler.IFillerPattern;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.blueprints.Blueprint;
|
||||
import buildcraft.core.blueprints.BlueprintBase;
|
||||
import buildcraft.core.blueprints.BptBuilderTemplate;
|
||||
import buildcraft.core.blueprints.Template;
|
||||
import buildcraft.core.utils.StringUtils;
|
||||
|
@ -68,7 +69,9 @@ public abstract class FillerPattern implements IFillerPattern {
|
|||
for (int y = yMin; y <= yMax; ++y) {
|
||||
for (int x = xMin; x <= xMax; ++x) {
|
||||
for (int z = zMin; z <= zMax; ++z) {
|
||||
template.contents[x][y][z] = new SchematicMask(true);
|
||||
if (isValid(x, y, z, template)) {
|
||||
template.contents[x][y][z] = new SchematicMask(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -83,7 +86,9 @@ public abstract class FillerPattern implements IFillerPattern {
|
|||
for (int y = yMax; y >= yMin; y--) {
|
||||
for (int x = xMin; x <= xMax; ++x) {
|
||||
for (int z = zMin; z <= zMax; ++z) {
|
||||
template.contents[x][y][z] = null;
|
||||
if (isValid(x, y, z, template)) {
|
||||
template.contents[x][y][z] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +103,9 @@ public abstract class FillerPattern implements IFillerPattern {
|
|||
for (int x = xMin; x <= xMax; ++x) {
|
||||
for (int z = zMin; z <= zMax; ++z) {
|
||||
for (int y = yMax; y >= yMin; --y) {
|
||||
template.contents [x][y][z] = new SchematicMask(true);
|
||||
if (isValid(x, y, z, template)) {
|
||||
template.contents [x][y][z] = new SchematicMask(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -129,4 +136,8 @@ public abstract class FillerPattern implements IFillerPattern {
|
|||
public BptBuilderTemplate getTemplateBuilder (Box box, World world) {
|
||||
return new BptBuilderTemplate(getTemplate(box, world), world, box.xMin, box.yMin, box.zMin);
|
||||
}
|
||||
|
||||
private static boolean isValid (int x, int y, int z, BlueprintBase bpt) {
|
||||
return x >= 0 && y >= 0 && z >= 0 && x < bpt.sizeX && y < bpt.sizeY && z < bpt.sizeZ;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,19 +55,21 @@ public class PatternCylinder extends FillerPattern {
|
|||
int stoppingX = twoBSquare * xRadius;
|
||||
int stoppingZ = 0;
|
||||
|
||||
while (stoppingX >= stoppingZ) {
|
||||
fillFourColumns(xCenter, zCenter, dx, dz, xFix, zFix, yMin,
|
||||
yMax, result);
|
||||
if (twoASquare > 0) {
|
||||
while (stoppingX >= stoppingZ) {
|
||||
fillFourColumns(xCenter, zCenter, dx, dz, xFix, zFix, yMin,
|
||||
yMax, result);
|
||||
|
||||
++dz;
|
||||
stoppingZ += twoASquare;
|
||||
ellipseError += zChange;
|
||||
zChange += twoASquare;
|
||||
if (2 * ellipseError + xChange > 0) {
|
||||
--dx;
|
||||
stoppingX -= twoBSquare;
|
||||
ellipseError += xChange;
|
||||
xChange += twoBSquare;
|
||||
++dz;
|
||||
stoppingZ += twoASquare;
|
||||
ellipseError += zChange;
|
||||
zChange += twoASquare;
|
||||
if (2 * ellipseError + xChange > 0) {
|
||||
--dx;
|
||||
stoppingX -= twoBSquare;
|
||||
ellipseError += xChange;
|
||||
xChange += twoBSquare;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,19 +81,21 @@ public class PatternCylinder extends FillerPattern {
|
|||
stoppingX = 0;
|
||||
stoppingZ = twoASquare * zRadius;
|
||||
|
||||
while (stoppingX <= stoppingZ) {
|
||||
fillFourColumns(xCenter, zCenter, dx, dz, xFix, zFix, yMin,
|
||||
yMax, result);
|
||||
if (twoBSquare > 0) {
|
||||
while (stoppingX <= stoppingZ) {
|
||||
fillFourColumns(xCenter, zCenter, dx, dz, xFix, zFix, yMin,
|
||||
yMax, result);
|
||||
|
||||
++dx;
|
||||
stoppingX += twoBSquare;
|
||||
ellipseError += xChange;
|
||||
xChange += twoBSquare;
|
||||
if (2 * ellipseError + zChange > 0) {
|
||||
--dz;
|
||||
stoppingZ -= twoASquare;
|
||||
ellipseError += zChange;
|
||||
zChange += twoASquare;
|
||||
++dx;
|
||||
stoppingX += twoBSquare;
|
||||
ellipseError += xChange;
|
||||
xChange += twoBSquare;
|
||||
if (2 * ellipseError + zChange > 0) {
|
||||
--dz;
|
||||
stoppingZ -= twoASquare;
|
||||
ellipseError += zChange;
|
||||
zChange += twoASquare;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue