This commit is contained in:
themode 2022-01-04 03:27:20 +01:00 committed by TheMode
parent 0662a3c604
commit 4a46065a67
2 changed files with 38 additions and 43 deletions

View File

@ -238,9 +238,9 @@ final class PaletteImpl implements Palette, Cloneable {
private void resize(int newBitsPerEntry) {
newBitsPerEntry = fixBitsPerEntry(newBitsPerEntry);
PaletteImpl palette = new PaletteImpl(dimension, maxBitsPerEntry, newBitsPerEntry, bitsIncrement);
for (int y = 0; y < dimension; y++) {
for (int z = 0; z < dimension; z++) {
for (int x = 0; x < dimension; x++) {
for (int x = 0; x < dimension; x++) {
for (int y = 0; y < dimension; y++) {
for (int z = 0; z < dimension; z++) {
palette.set(x, y, z, get(x, y, z));
}
}
@ -282,16 +282,13 @@ final class PaletteImpl implements Palette, Cloneable {
}
private static int validateDimension(int dimension) {
if(dimension <= 1) {
if (dimension <= 1) {
throw new IllegalArgumentException("Dimension must be greater 1");
}
double log2 = Math.log(dimension) / Math.log(2);
if ((int) Math.ceil(log2) != (int)Math.floor(log2)) {
if ((int) Math.ceil(log2) != (int) Math.floor(log2)) {
throw new IllegalArgumentException("Dimension must be a power of 2");
}
return (int) log2;
}
}

View File

@ -3,7 +3,6 @@ package net.minestom.server.instance;
import net.minestom.server.instance.palette.Palette;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
@ -89,8 +88,8 @@ public class PaletteTest {
palette.fill(6);
assertEquals(6, palette.get(0, 0, 0));
assertEquals(palette.maxSize(), palette.size());
for (int y = 0; y < palette.dimension(); y++) {
for (int x = 0; x < palette.dimension(); x++) {
for (int x = 0; x < palette.dimension(); x++) {
for (int y = 0; y < palette.dimension(); y++) {
for (int z = 0; z < palette.dimension(); z++) {
assertEquals(6, palette.get(x, y, z));
}
@ -99,8 +98,8 @@ public class PaletteTest {
palette.fill(0);
assertEquals(0, palette.size());
for (int y = 0; y < palette.dimension(); y++) {
for (int x = 0; x < palette.dimension(); x++) {
for (int x = 0; x < palette.dimension(); x++) {
for (int y = 0; y < palette.dimension(); y++) {
for (int z = 0; z < palette.dimension(); z++) {
assertEquals(0, palette.get(x, y, z));
}
@ -109,6 +108,30 @@ public class PaletteTest {
}
}
@Test
public void bulk() {
var palettes = testPalettes();
for (Palette palette : palettes) {
final int dimension = palette.dimension();
// Place
for (int x = 0; x < dimension; x++) {
for (int y = 0; y < dimension; y++) {
for (int z = 0; z < dimension; z++) {
palette.set(x, y, z, x + y + z);
}
}
}
// Verify
for (int x = 0; x < dimension; x++) {
for (int y = 0; y < dimension; y++) {
for (int z = 0; z < dimension; z++) {
assertEquals(x + y + z, palette.get(x, y, z));
}
}
}
}
}
@Test
public void bulkAll() {
var palettes = testPalettes();
@ -131,35 +154,10 @@ public class PaletteTest {
}
private static List<Palette> testPalettes() {
List<Palette> palettes = new ArrayList<>();
palettes.add(Palette.newPalette(2, 5, 3, 1));
palettes.add(Palette.newPalette(4, 5, 3, 1));
palettes.add(Palette.newPalette(8, 5, 3, 1));
palettes.add(Palette.newPalette(16, 5, 3, 1));
return palettes;
}
@Test
public void bulk() {
var palettes = testPalettes();
for (Palette palette : palettes) {
final int dimension = palette.dimension();
// Place
for (int x = 0; x < dimension; x++) {
for (int y = 0; y < dimension; y++) {
for (int z = 0; z < dimension; z++) {
palette.set(x, y, z, x + y + z);
}
}
}
// Verify
for (int x = 0; x < dimension; x++) {
for (int y = 0; y < dimension; y++) {
for (int z = 0; z < dimension; z++) {
assertEquals(x + y + z, palette.get(x, y, z));
}
}
}
}
return List.of(
Palette.newPalette(2, 5, 3, 1),
Palette.newPalette(4, 5, 3, 1),
Palette.newPalette(8, 5, 3, 1),
Palette.newPalette(16, 5, 3, 1));
}
}