From 6716b21a4a62009a6db10075cc5b0a9d49bc775f Mon Sep 17 00:00:00 2001 From: TheMode Date: Thu, 3 Feb 2022 16:09:43 +0100 Subject: [PATCH] Bring back palette optimization Signed-off-by: TheMode --- .../server/instance/palette/AdaptivePalette.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minestom/server/instance/palette/AdaptivePalette.java b/src/main/java/net/minestom/server/instance/palette/AdaptivePalette.java index 290d714d5..bbdba5d03 100644 --- a/src/main/java/net/minestom/server/instance/palette/AdaptivePalette.java +++ b/src/main/java/net/minestom/server/instance/palette/AdaptivePalette.java @@ -123,10 +123,14 @@ final class AdaptivePalette implements Palette { if (currentPalette instanceof FlexiblePalette flexiblePalette) { final int count = flexiblePalette.count(); if (count == 0) { - currentPalette = new FilledPalette(dimension, 0); - this.palette = currentPalette; + return (this.palette = new FilledPalette(dimension, 0)); + } else if (count == flexiblePalette.maxSize()) { + var palette = flexiblePalette.paletteToValueList; + if (palette.size() == 2 && palette.getInt(0) == 0) { + // first element is air, second should be the value the palette is filled with + return (this.palette = new FilledPalette(dimension, palette.getInt(1))); + } } - // TODO optimize the case where the palette is filled with a single value } return currentPalette; }