mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-26 11:07:53 +01:00
Add Palette#getAll and Palette#setAll
This commit is contained in:
parent
9327dfaccf
commit
0662a3c604
@ -23,10 +23,14 @@ public sealed interface Palette extends Writeable permits PaletteImpl {
|
||||
|
||||
int get(int x, int y, int z);
|
||||
|
||||
void getAll(@NotNull EntryConsumer consumer);
|
||||
|
||||
void set(int x, int y, int z, int value);
|
||||
|
||||
void fill(int value);
|
||||
|
||||
void setAll(@NotNull EntrySupplier supplier);
|
||||
|
||||
/**
|
||||
* Returns the number of entries in this palette.
|
||||
*/
|
||||
@ -56,4 +60,14 @@ public sealed interface Palette extends Writeable permits PaletteImpl {
|
||||
int dimension();
|
||||
|
||||
@NotNull Palette clone();
|
||||
|
||||
@FunctionalInterface
|
||||
interface EntrySupplier {
|
||||
int get(int x, int y, int z);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface EntryConsumer {
|
||||
void accept(int x, int y, int z, int value);
|
||||
}
|
||||
}
|
||||
|
@ -81,6 +81,18 @@ final class PaletteImpl implements Palette, Cloneable {
|
||||
return hasPalette ? paletteToValueList.getInt(value) : value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAll(@NotNull EntryConsumer consumer) {
|
||||
// TODO optimize
|
||||
for (int x = 0; x < dimension; x++) {
|
||||
for (int y = 0; y < dimension; y++) {
|
||||
for (int z = 0; z < dimension; z++) {
|
||||
consumer.accept(x, y, z, get(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, int value) {
|
||||
if (x < 0 || y < 0 || z < 0) {
|
||||
@ -150,6 +162,18 @@ final class PaletteImpl implements Palette, Cloneable {
|
||||
this.count = placedAir ? 0 : maxSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAll(@NotNull EntrySupplier supplier) {
|
||||
// TODO optimize
|
||||
for (int x = 0; x < dimension; x++) {
|
||||
for (int y = 0; y < dimension; y++) {
|
||||
for (int z = 0; z < dimension; z++) {
|
||||
set(x, y, z, supplier.get(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return count;
|
||||
|
@ -109,6 +109,15 @@ public class PaletteTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bulkAll() {
|
||||
var palettes = testPalettes();
|
||||
for (Palette palette : palettes) {
|
||||
palette.setAll((x, y, z) -> x + y + z);
|
||||
palette.getAll((x, y, z, value) -> assertEquals(x + y + z, value));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dimension() {
|
||||
assertThrows(Exception.class, () -> Palette.newPalette(-4, 5, 3, 1));
|
||||
|
Loading…
Reference in New Issue
Block a user