Clean up HybridGen

- There's no need for while loops acting as a modulo after we've already performed a modulo
 - Make the code-sections calculating if positions are in the wall/road more readable
 - Collaps duplicate if-elseif bodies
This commit is contained in:
dordsor21 2022-06-11 13:24:03 +01:00
parent 058c65e34c
commit e159fa054d
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B

View File

@ -138,35 +138,35 @@ public class HybridGen extends IndependentPlotGenerator {
short[] relativeX = new short[16]; short[] relativeX = new short[16];
boolean[] insideRoadX = new boolean[16]; boolean[] insideRoadX = new boolean[16];
boolean[] insideWallX = new boolean[16]; boolean[] insideWallX = new boolean[16];
short offsetX = relativeOffsetX;
for (short i = 0; i < 16; i++) { for (short i = 0; i < 16; i++) {
short v = (short) (relativeOffsetX + i); if (offsetX >= hybridPlotWorld.SIZE) {
while (v >= hybridPlotWorld.SIZE) { offsetX -= hybridPlotWorld.SIZE;
v -= hybridPlotWorld.SIZE;
} }
relativeX[i] = v; relativeX[i] = offsetX;
if (hybridPlotWorld.ROAD_WIDTH != 0) { if (hybridPlotWorld.ROAD_WIDTH != 0) {
insideRoadX[i] = v < hybridPlotWorld.PATH_WIDTH_LOWER || v > hybridPlotWorld.PATH_WIDTH_UPPER; insideRoadX[i] = offsetX < hybridPlotWorld.PATH_WIDTH_LOWER || offsetX > hybridPlotWorld.PATH_WIDTH_UPPER;
insideWallX[i] = v == hybridPlotWorld.PATH_WIDTH_LOWER || v == hybridPlotWorld.PATH_WIDTH_UPPER; insideWallX[i] = offsetX == hybridPlotWorld.PATH_WIDTH_LOWER || offsetX == hybridPlotWorld.PATH_WIDTH_UPPER;
} }
offsetX++;
} }
// The Z-coordinate of a given Z coordinate, relative to the // The Z-coordinate of a given Z coordinate, relative to the
// plot (Counting from the corner with the least positive // plot (Counting from the corner with the least positive
// coordinates) // coordinates)
short[] relativeZ = new short[16]; short[] relativeZ = new short[16];
// Whether the given Z coordinate belongs to the road
boolean[] insideRoadZ = new boolean[16]; boolean[] insideRoadZ = new boolean[16];
// Whether the given Z coordinate belongs to the wall
boolean[] insideWallZ = new boolean[16]; boolean[] insideWallZ = new boolean[16];
short offsetZ = relativeOffsetZ;
for (short i = 0; i < 16; i++) { for (short i = 0; i < 16; i++) {
short v = (short) (relativeOffsetZ + i); if (offsetZ >= hybridPlotWorld.SIZE) {
while (v >= hybridPlotWorld.SIZE) { offsetZ -= hybridPlotWorld.SIZE;
v -= hybridPlotWorld.SIZE;
} }
relativeZ[i] = v; relativeZ[i] = offsetZ;
if (hybridPlotWorld.ROAD_WIDTH != 0) { if (hybridPlotWorld.ROAD_WIDTH != 0) {
insideRoadZ[i] = v < hybridPlotWorld.PATH_WIDTH_LOWER || v > hybridPlotWorld.PATH_WIDTH_UPPER; insideRoadZ[i] = offsetZ < hybridPlotWorld.PATH_WIDTH_LOWER || offsetZ > hybridPlotWorld.PATH_WIDTH_UPPER;
insideWallZ[i] = v == hybridPlotWorld.PATH_WIDTH_LOWER || v == hybridPlotWorld.PATH_WIDTH_UPPER; insideWallZ[i] = offsetZ == hybridPlotWorld.PATH_WIDTH_LOWER || offsetZ == hybridPlotWorld.PATH_WIDTH_UPPER;
} }
offsetZ++;
} }
// generation // generation
int startY = hybridPlotWorld.getMinGenHeight() + (hybridPlotWorld.PLOT_BEDROCK ? 1 : 0); int startY = hybridPlotWorld.getMinGenHeight() + (hybridPlotWorld.PLOT_BEDROCK ? 1 : 0);
@ -278,9 +278,6 @@ public class HybridGen extends IndependentPlotGenerator {
boolean[] insideRoadX = new boolean[16]; boolean[] insideRoadX = new boolean[16];
boolean[] insideWallX = new boolean[16]; boolean[] insideWallX = new boolean[16];
short offsetX = relativeOffsetX; short offsetX = relativeOffsetX;
while (offsetX >= hybridPlotWorld.SIZE) {
offsetX -= hybridPlotWorld.SIZE;
}
for (short i = 0; i < 16; i++) { for (short i = 0; i < 16; i++) {
if (offsetX >= hybridPlotWorld.SIZE) { if (offsetX >= hybridPlotWorld.SIZE) {
offsetX -= hybridPlotWorld.SIZE; offsetX -= hybridPlotWorld.SIZE;
@ -304,13 +301,10 @@ public class HybridGen extends IndependentPlotGenerator {
boolean[] insideRoadZ = new boolean[16]; boolean[] insideRoadZ = new boolean[16];
boolean[] insideWallZ = new boolean[16]; boolean[] insideWallZ = new boolean[16];
short offsetZ = relativeOffsetZ; short offsetZ = relativeOffsetZ;
while (offsetZ >= hybridPlotWorld.SIZE) {
offsetZ -= hybridPlotWorld.SIZE;
overlap = true;
}
for (short i = 0; i < 16; i++) { for (short i = 0; i < 16; i++) {
if (offsetZ >= hybridPlotWorld.SIZE) { if (offsetZ >= hybridPlotWorld.SIZE) {
offsetZ -= hybridPlotWorld.SIZE; offsetZ -= hybridPlotWorld.SIZE;
overlap = true;
} }
relativeZ[i] = offsetZ; relativeZ[i] = offsetZ;
if (hybridPlotWorld.ROAD_WIDTH != 0) { if (hybridPlotWorld.ROAD_WIDTH != 0) {
@ -323,13 +317,7 @@ public class HybridGen extends IndependentPlotGenerator {
offsetZ++; offsetZ++;
} }
for (short x = 0; x < 16; x++) { for (short x = 0; x < 16; x++) {
if (insideRoadX[x]) { if (insideRoadX[x] || insideWallX[x]) {
if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
for (short z = 0; z < 16; z++) {
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, true, true);
}
}
} else if (insideWallX[x]) {
if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) { if (hybridPlotWorld.ROAD_SCHEMATIC_ENABLED) {
for (short z = 0; z < 16; z++) { for (short z = 0; z < 16; z++) {
placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, true, true); placeSchem(hybridPlotWorld, result, relativeX[x], relativeZ[z], x, z, true, true);