Fix CFI smooth creating incorrect //undo

This commit is contained in:
Jesse Boyd 2018-03-15 18:44:36 +11:00
parent 485427c667
commit bc5241274c
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 30 additions and 6 deletions

View File

@ -476,7 +476,27 @@ public class HeightMapMCAGenerator extends MCAWriter implements SimpleWorld, Faw
} }
} else { } else {
this.heights.setByte(index, (byte) (blockHeight)); this.heights.setByte(index, (byte) (blockHeight));
}
}
private final void setLayerHeightRaw(int index, int height) {
int blockHeight = (height) >> 3;
int layerHeight = (height) & 0x7;
setLayerHeightRaw(index, blockHeight, layerHeight);
}
private final void setLayerHeightRaw(int index, int blockHeight, int layerHeight) {
int floorId = floor.get()[index] >> 4;
if (floorId == 78 || floorId == 80) {
if (layerHeight != 0) {
this.heights.getByteArray()[index] = (byte) (blockHeight + 1);
this.floor.getCharArray()[index] = (char) (1248 + layerHeight);
} else {
this.heights.getByteArray()[index] = (byte) (blockHeight);
this.floor.getCharArray()[index] = (char) (1280);
}
} else {
this.heights.getByteArray()[index] = (byte) (blockHeight);
} }
} }
@ -512,7 +532,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements SimpleWorld, Faw
int height = img.getRGB(x, z) & 0xFF; int height = img.getRGB(x, z) & 0xFF;
if (height == 255 || height > 0 && !white && PseudoRandom.random.nextInt(256) <= height) { if (height == 255 || height > 0 && !white && PseudoRandom.random.nextInt(256) <= height) {
int newHeight = table.average(x, z, index); int newHeight = table.average(x, z, index);
setLayerHeight(index, newHeight); setLayerHeightRaw(index, newHeight);
} }
} }
} }
@ -525,7 +545,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements SimpleWorld, Faw
mutable.mutY(y); mutable.mutY(y);
if (mask.test(mutable)) { if (mask.test(mutable)) {
int newHeight = table.average(x, z, index); int newHeight = table.average(x, z, index);
setLayerHeight(index, newHeight); setLayerHeightRaw(index, newHeight);
} }
} }
} }
@ -533,7 +553,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements SimpleWorld, Faw
for (int z = 0; z < getLength(); z++) { for (int z = 0; z < getLength(); z++) {
for (int x = 0; x < getWidth(); x++, index++) { for (int x = 0; x < getWidth(); x++, index++) {
int newHeight = table.average(x, z, index); int newHeight = table.average(x, z, index);
setLayerHeight(index, newHeight); setLayerHeightRaw(index, newHeight);
} }
} }
} }

View File

@ -60,8 +60,8 @@ public final class DifferentialArray<T> implements DifferentialCollection<T> {
changes = (T) (changesChars = new char[length]); changes = (T) (changesChars = new char[length]);
} }
} }
boolean changed = false;
T tmp; T tmp;
boolean changed = this.changed;
if (changed) { if (changed) {
tmp = (T) MainUtil.copyNd(data); tmp = (T) MainUtil.copyNd(data);
} else { } else {
@ -83,9 +83,11 @@ public final class DifferentialArray<T> implements DifferentialCollection<T> {
if (tmpChar != dataChar) { if (tmpChar != dataChar) {
this.changed = true; this.changed = true;
tmpChars[i] -= dataChar; tmpChars[i] -= dataChar;
} else {
tmpChars[i] = 0;
} }
} }
if (tmp != changes) { if (changed) {
for (int i = 0; i < tmpChars.length; i++) { for (int i = 0; i < tmpChars.length; i++) {
changesChars[i] += tmpChars[i]; changesChars[i] += tmpChars[i];
} }
@ -98,9 +100,11 @@ public final class DifferentialArray<T> implements DifferentialCollection<T> {
if (tmpByte != dataByte) { if (tmpByte != dataByte) {
this.changed = true; this.changed = true;
tmpBytes[i] -= dataByte; tmpBytes[i] -= dataByte;
} else {
tmpBytes[i] = 0;
} }
} }
if (tmp != changes) { if (changed) {
for (int i = 0; i < tmpBytes.length; i++) { for (int i = 0; i < tmpBytes.length; i++) {
changesBytes[i] += tmpBytes[i]; changesBytes[i] += tmpBytes[i];
} }