/* * Decompiled with CFR 0.152. * * Could not load the following classes: * org.apache.commons.lang3.Validate * org.jspecify.annotations.Nullable */ package net.minecraft.world.level.chunk; import java.util.List; import java.util.function.Predicate; import net.minecraft.core.IdMap; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.VarInt; import net.minecraft.world.level.chunk.Palette; import net.minecraft.world.level.chunk.PaletteResize; import org.apache.commons.lang3.Validate; import org.jspecify.annotations.Nullable; public class SingleValuePalette implements Palette { private @Nullable T value; public SingleValuePalette(List paletteEntries) { if (paletteEntries.size() > 0) { Validate.isTrue((paletteEntries.size() <= 1 ? 1 : 0) != 0, (String)"Can't initialize SingleValuePalette with %d values.", (long)paletteEntries.size()); this.value = paletteEntries.get(0); } } public static Palette create(int bits, List paletteEntries) { return new SingleValuePalette(paletteEntries); } @Override public int idFor(T value, PaletteResize resizeHandler) { if (this.value == null || this.value == value) { this.value = value; return 0; } return resizeHandler.onResize(1, value); } @Override public boolean maybeHas(Predicate predicate) { if (this.value == null) { throw new IllegalStateException("Use of an uninitialized palette"); } return predicate.test(this.value); } @Override public T valueFor(int index) { if (this.value == null || index != 0) { throw new IllegalStateException("Missing Palette entry for id " + index + "."); } return this.value; } @Override public void read(FriendlyByteBuf buffer, IdMap globalMap) { this.value = globalMap.byIdOrThrow(buffer.readVarInt()); } @Override public void write(FriendlyByteBuf buffer, IdMap globalMap) { if (this.value == null) { throw new IllegalStateException("Use of an uninitialized palette"); } buffer.writeVarInt(globalMap.getId(this.value)); } @Override public int getSerializedSize(IdMap globalMap) { if (this.value == null) { throw new IllegalStateException("Use of an uninitialized palette"); } return VarInt.getByteSize(globalMap.getId(this.value)); } @Override public int getSize() { return 1; } @Override public Palette copy() { if (this.value == null) { throw new IllegalStateException("Use of an uninitialized palette"); } return this; } }