ViaVersion/api/src/main/java/com/viaversion/viaversion/api/minecraft/chunks/ChunkSection.java

176 lines
5.3 KiB
Java
Raw Normal View History

/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
2024-01-12 10:01:48 +01:00
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.minecraft.chunks;
import org.checkerframework.checker.nullness.qual.Nullable;
public interface ChunkSection {
2020-04-04 00:32:00 +02:00
2018-07-18 18:23:57 +02:00
/**
2018-10-25 13:56:40 +02:00
* Size (dimensions) of blocks in a chunks section.
*/
int SIZE = 16 * 16 * 16; // width * depth * height
/**
* Size (dimensions) of biomes in a chunks section.
*/
int BIOME_SIZE = 4 * 4 * 4;
static int index(int x, int y, int z) {
return y << 8 | z << 4 | x;
}
static int xFromIndex(int idx) {
return idx & 0xF;
}
static int yFromIndex(int idx) {
return idx >> 8 & 0xF;
}
static int zFromIndex(int idx) {
return idx >> 4 & 0xF;
}
2021-09-14 17:38:52 +02:00
@Deprecated/*(forRemoval = true)*/
default int getFlatBlock(int idx) {
return palette(PaletteType.BLOCKS).idAt(idx);
2021-09-14 17:38:52 +02:00
}
2021-09-14 17:38:52 +02:00
@Deprecated/*(forRemoval = true)*/
default int getFlatBlock(int x, int y, int z) {
return getFlatBlock(index(x, y, z));
}
2021-09-14 17:38:52 +02:00
@Deprecated/*(forRemoval = true)*/
default void setFlatBlock(int idx, int id) {
palette(PaletteType.BLOCKS).setIdAt(idx, id);
2021-09-14 17:38:52 +02:00
}
2018-10-25 13:56:40 +02:00
2021-09-14 17:38:52 +02:00
@Deprecated/*(forRemoval = true)*/
default void setFlatBlock(int x, int y, int z, int id) {
setFlatBlock(index(x, y, z), id);
2018-10-25 13:56:40 +02:00
}
2021-09-14 17:38:52 +02:00
@Deprecated/*(forRemoval = true)*/
default int getBlockWithoutData(int x, int y, int z) {
2018-10-25 13:56:40 +02:00
return getFlatBlock(x, y, z) >> 4;
}
2021-09-14 17:38:52 +02:00
@Deprecated/*(forRemoval = true)*/
default int getBlockData(int x, int y, int z) {
2018-10-25 13:56:40 +02:00
return getFlatBlock(x, y, z) & 0xF;
}
2021-09-14 17:38:52 +02:00
@Deprecated/*(forRemoval = true)*/
default void setBlockWithData(int x, int y, int z, int type, int data) {
setFlatBlock(index(x, y, z), type << 4 | (data & 0xF));
2018-10-25 13:56:40 +02:00
}
2021-09-14 17:38:52 +02:00
@Deprecated/*(forRemoval = true)*/
default void setBlockWithData(int idx, int type, int data) {
setFlatBlock(idx, type << 4 | (data & 0xF));
2018-10-25 13:56:40 +02:00
}
2021-09-14 17:38:52 +02:00
@Deprecated/*(forRemoval = true)*/
default void setPaletteIndex(int idx, int index) {
palette(PaletteType.BLOCKS).setPaletteIndexAt(idx, index);
2021-09-14 17:38:52 +02:00
}
2018-10-25 13:56:40 +02:00
2021-09-14 17:38:52 +02:00
@Deprecated/*(forRemoval = true)*/
default int getPaletteIndex(int idx) {
return palette(PaletteType.BLOCKS).paletteIndexAt(idx);
2021-09-14 17:38:52 +02:00
}
2018-10-25 13:56:40 +02:00
2021-09-14 17:38:52 +02:00
@Deprecated/*(forRemoval = true)*/
default int getPaletteSize() {
return palette(PaletteType.BLOCKS).size();
}
2019-09-19 11:22:06 +02:00
2021-09-14 17:38:52 +02:00
@Deprecated/*(forRemoval = true)*/
default int getPaletteEntry(int index) {
return palette(PaletteType.BLOCKS).idByIndex(index);
2021-09-14 17:38:52 +02:00
}
2018-10-25 13:56:40 +02:00
2021-09-14 17:38:52 +02:00
@Deprecated/*(forRemoval = true)*/
default void setPaletteEntry(int index, int id) {
palette(PaletteType.BLOCKS).setIdByIndex(index, id);
2021-09-14 17:38:52 +02:00
}
2019-09-19 11:22:06 +02:00
2021-09-14 17:38:52 +02:00
@Deprecated/*(forRemoval = true)*/
default void replacePaletteEntry(int oldId, int newId) {
palette(PaletteType.BLOCKS).replaceId(oldId, newId);
2021-09-14 17:38:52 +02:00
}
2018-10-25 13:56:40 +02:00
2021-09-14 17:38:52 +02:00
@Deprecated/*(forRemoval = true)*/
default void addPaletteEntry(int id) {
palette(PaletteType.BLOCKS).addId(id);
2021-09-14 17:38:52 +02:00
}
2021-09-14 17:38:52 +02:00
@Deprecated/*(forRemoval = true)*/
default void clearPalette() {
palette(PaletteType.BLOCKS).clear();
}
2018-07-18 18:23:57 +02:00
/**
* Returns the number of non-air blocks in this section.
*
* @return non-air blocks in this section
*/
int getNonAirBlocksCount();
void setNonAirBlocksCount(int nonAirBlocksCount);
/**
* Returns whether this section holds light data.
2021-05-22 19:39:26 +02:00
* Only true for &lt; 1.14 chunks.
*
* @return whether this section holds light data
*/
default boolean hasLight() {
return getLight() != null;
2018-10-25 13:56:40 +02:00
}
2020-02-09 13:06:23 +01:00
2021-05-22 19:39:26 +02:00
/**
* Returns the light of the chunk section.
* Only present for &lt; 1.14 chunks, otherwise sent separately.
*
* @return chunk section light if present
*/
@Nullable ChunkSectionLight getLight();
2020-02-09 13:06:23 +01:00
void setLight(@Nullable ChunkSectionLight light);
2021-09-14 17:38:52 +02:00
/**
* Returns the palette of the given type if present.
*
* @param type type of the palette
* @return palette
*/
@Nullable DataPalette palette(PaletteType type);
void addPalette(PaletteType type, DataPalette blockPalette);
2021-09-14 17:38:52 +02:00
void removePalette(PaletteType type);
}