Plex-FAWE/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/BitSetBlocks.java

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

202 lines
5.0 KiB
Java
Raw Normal View History

2019-07-19 15:29:49 +00:00
package com.boydti.fawe.beta.implementation.blocks;
2019-08-07 00:13:07 +00:00
import com.boydti.fawe.FaweCache;
2019-07-19 15:29:49 +00:00
import com.boydti.fawe.beta.IChunkSet;
import com.boydti.fawe.beta.implementation.lighting.HeightMapType;
2019-07-19 15:29:49 +00:00
import com.boydti.fawe.object.collection.MemBlockSet;
import com.sk89q.jnbt.CompoundTag;
2019-10-03 23:35:55 +00:00
import com.sk89q.worldedit.math.BlockVector3;
2019-07-19 15:29:49 +00:00
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
2020-07-14 02:50:59 +00:00
2019-08-10 06:01:42 +00:00
import java.util.Arrays;
import java.util.Collections;
2019-07-19 15:29:49 +00:00
import java.util.Map;
import java.util.Set;
import java.util.UUID;
public class BitSetBlocks implements IChunkSet {
2019-08-06 15:29:09 +00:00
2019-07-19 15:29:49 +00:00
private final MemBlockSet.RowZ row;
private final BlockState blockState;
public BitSetBlocks(BlockState blockState) {
this.row = new MemBlockSet.RowZ();
this.blockState = blockState;
}
@Override
public boolean hasSection(int layer) {
return row.rows[layer] != MemBlockSet.NULL_ROW_Y;
}
2019-07-19 15:29:49 +00:00
@Override
public boolean setBiome(int x, int y, int z, BiomeType biome) {
return false;
}
@Override
public <T extends BlockStateHolder<T>> boolean setBlock(int x, int y, int z, T holder) {
2019-07-19 15:29:49 +00:00
row.set(null, x, y, z);
return true;
}
@Override
2019-10-23 04:23:52 +00:00
public void setBlocks(int layer, char[] data) {
row.reset(layer);
int by = layer << 4;
for (int y = 0, index = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++, index++) {
if (data[index] != 0) {
row.set(null, x, by + y, z);
}
}
}
}
2019-07-19 15:29:49 +00:00
}
2019-10-03 23:35:55 +00:00
@Override
2019-10-23 04:23:52 +00:00
public boolean isEmpty() {
return row.isEmpty();
2019-10-03 23:35:55 +00:00
}
2019-07-19 15:29:49 +00:00
@Override
2019-08-10 06:01:42 +00:00
public boolean setTile(int x, int y, int z, CompoundTag tile) {
return false;
2019-08-06 15:29:09 +00:00
}
2019-07-19 15:29:49 +00:00
@Override
public void setBlockLight(int x, int y, int z, int value) {
}
@Override
public void setSkyLight(int x, int y, int z, int value) {
}
@Override
public void setHeightMap(HeightMapType type, int[] heightMap) {
}
@Override
public void setLightLayer(int layer, char[] toSet) {
}
@Override
public void setSkyLightLayer(int layer, char[] toSet) {
}
@Override
public void removeSectionLighting(int layer, boolean sky) {
}
@Override
public void setFullBright(int layer) {
}
2019-07-19 15:29:49 +00:00
@Override
2019-08-06 15:29:09 +00:00
public void setEntity(CompoundTag tag) {
}
2019-07-19 15:29:49 +00:00
@Override
2019-08-06 15:29:09 +00:00
public void removeEntity(UUID uuid) {
}
2019-07-19 15:29:49 +00:00
@Override
public BlockState getBlock(int x, int y, int z) {
if (row.get(null, x, y, z)) {
return blockState;
}
return null;
}
@Override
2019-11-07 10:28:17 +00:00
public char[] load(int layer) {
char[] arr = FaweCache.IMP.SECTION_BITS_TO_CHAR.get();
2019-08-10 06:01:42 +00:00
MemBlockSet.IRow nullRowY = row.getRow(layer);
if (nullRowY instanceof MemBlockSet.RowY) {
char value = blockState.getOrdinalChar();
MemBlockSet.RowY rowY = (MemBlockSet.RowY) nullRowY;
long[] bits = rowY.getBits();
for (int y = 0, longIndex = 0, blockIndex = 0; y < 16; y++) {
for (int z = 0; z < 16; z += 4, longIndex++, blockIndex += 64) {
long bitBuffer = bits[longIndex];
if (bitBuffer != 0) {
if (bitBuffer == -1L) {
Arrays.fill(arr, blockIndex, blockIndex + 64, value);
continue;
}
Arrays.fill(arr, Character.MIN_VALUE);
do {
final long lowBit = Long.lowestOneBit(bitBuffer);
final int bitIndex = Long.bitCount(lowBit - 1);
arr[blockIndex + bitIndex] = value;
bitBuffer = bitBuffer ^ lowBit;
} while (bitBuffer != 0);
}
}
}
}
return arr;
2019-07-19 15:29:49 +00:00
}
@Override
public BiomeType[] getBiomes() {
return null;
}
@Override
public char[][] getLight() {
return new char[0][];
}
@Override
public char[][] getSkyLight() {
return new char[0][];
}
2019-10-26 13:21:49 +00:00
@Override
2019-12-19 16:19:46 +00:00
public BiomeType getBiomeType(int x, int y, int z) {
2019-10-26 13:21:49 +00:00
return null;
}
2019-07-19 15:29:49 +00:00
@Override
2019-10-23 04:23:52 +00:00
public Map<BlockVector3, CompoundTag> getTiles() {
return Collections.emptyMap();
2019-07-19 15:29:49 +00:00
}
@Override
public CompoundTag getTile(int x, int y, int z) {
2019-07-19 15:29:49 +00:00
return null;
}
@Override
public Set<CompoundTag> getEntities() {
return Collections.emptySet();
2019-07-19 15:29:49 +00:00
}
@Override
public Set<UUID> getEntityRemoves() {
return null;
2019-07-19 15:29:49 +00:00
}
@Override
public IChunkSet reset() {
row.reset();
return this;
}
@Override
public boolean trim(boolean aggressive) {
return false;
}
@Override
public boolean trim(boolean aggressive, int layer) {
return false;
}
2019-07-19 15:29:49 +00:00
}