Merge pull request #1292 from Gerrygames/palette_fix

fix setPaletteEntry
This commit is contained in:
Myles 2019-04-25 22:53:07 +01:00 committed by GitHub
commit 63fc733c88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -92,8 +92,18 @@ public class ChunkSection {
public void setPaletteEntry(int index, int id) { public void setPaletteEntry(int index, int id) {
if (index < 0 || index >= palette.size()) throw new IndexOutOfBoundsException(); if (index < 0 || index >= palette.size()) throw new IndexOutOfBoundsException();
palette.set(index, id); int oldId = palette.set(index, id);
if (oldId == id) return;
inversePalette.put(id, index); inversePalette.put(id, index);
if (inversePalette.get(oldId) == index) {
inversePalette.remove(oldId);
for (int i = 0; i < palette.size(); i++) {
if (palette.get(i) == oldId) {
inversePalette.put(oldId, i);
break;
}
}
}
} }
public void replacePaletteEntry(int oldId, int newId) { public void replacePaletteEntry(int oldId, int newId) {