Sonar: [squid:S3776] make the method easier
This commit is contained in:
@@ -17,6 +17,7 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Packet structure
|
Packet structure
|
||||||
@@ -89,19 +90,13 @@ public class ChunkDataPacket implements SCPacket {
|
|||||||
this.sectionList = sectionList;
|
this.sectionList = sectionList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public void writeSelf(NetOutputStream netStream) {
|
* @return max height chunk
|
||||||
if (sectionList == null && chunk == null) {
|
*/
|
||||||
log.warn("Empty chunk data!"); //TODO для такого нужна заглушка
|
private int calcAndWriteBitMask(NetOutputStream netStream) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
netStream.writeInt(x); // Chunk X
|
|
||||||
netStream.writeInt(z); // Chunk Y
|
|
||||||
netStream.writeBoolean(initChunk); // Init Chunk
|
|
||||||
|
|
||||||
int maxH = 0;
|
int maxH = 0;
|
||||||
int bitMask = 0;
|
int bitMask = 0;
|
||||||
|
|
||||||
if (sectionList == null && chunk != null) {
|
if (sectionList == null && chunk != null) {
|
||||||
for (int h = 15; h >= 0; h--) {
|
for (int h = 15; h >= 0; h--) {
|
||||||
bitMask = bitMask << 1;
|
bitMask = bitMask << 1;
|
||||||
@@ -126,60 +121,89 @@ public class ChunkDataPacket implements SCPacket {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
netStream.writeVarInt(bitMask); // Primary Bit Mask
|
netStream.writeVarInt(bitMask); // Primary Bit Mask
|
||||||
|
|
||||||
|
return maxH;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ChunkSection getChunkSection(int h) {
|
||||||
|
if (chunk != null) {
|
||||||
|
return chunk.getChunkSection(h);
|
||||||
|
} else if (sectionList != null) {
|
||||||
|
return sectionList.remove(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PalettedChunkSection createPalette(final ChunkSection chunkSection,
|
||||||
|
final List<CompoundTag> nbtList,
|
||||||
|
final AtomicBoolean biomeWrite,
|
||||||
|
final ByteArrayOutputNetStream biomes) {
|
||||||
|
|
||||||
|
final PalettedChunkSection palettedChunkSection = new PalettedChunkSection();
|
||||||
|
|
||||||
|
for (int y = 0; y < 16; y++) {
|
||||||
|
for (int z = 0; z < 16; z++) {
|
||||||
|
for (int x = 0; x < 16; x++) {
|
||||||
|
Block block = chunkSection.getBlock(x, y, z);
|
||||||
|
|
||||||
|
palettedChunkSection.addBlock(
|
||||||
|
block,
|
||||||
|
chunkSection.getSkyLight(x, y, z)
|
||||||
|
);
|
||||||
|
|
||||||
|
CompoundTag nbt = block.getNBTData();
|
||||||
|
if (nbt != null) {
|
||||||
|
nbtList.add(nbt);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (biomeWrite.get()) {
|
||||||
|
biomes.writeByte(chunk.getBiome(
|
||||||
|
(chunk.getX() << 4) + x,
|
||||||
|
(chunk.getZ() << 4) + z
|
||||||
|
).getId());
|
||||||
|
if (x == 15 && z == 15) {
|
||||||
|
biomeWrite.set(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return palettedChunkSection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeSelf(NetOutputStream netStream) {
|
||||||
|
if (sectionList == null && chunk == null) {
|
||||||
|
log.warn("Empty chunk data!"); //TODO для такого нужна заглушка
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
netStream.writeInt(x); // Chunk X
|
||||||
|
netStream.writeInt(z); // Chunk Y
|
||||||
|
netStream.writeBoolean(initChunk); // Init Chunk
|
||||||
|
|
||||||
|
final int maxH = calcAndWriteBitMask(netStream);
|
||||||
|
|
||||||
try (ByteArrayOutputNetStream data = new ByteArrayOutputNetStream();
|
try (ByteArrayOutputNetStream data = new ByteArrayOutputNetStream();
|
||||||
ByteArrayOutputNetStream biomes = new ByteArrayOutputNetStream()) {
|
ByteArrayOutputNetStream biomes = new ByteArrayOutputNetStream()) {
|
||||||
|
|
||||||
boolean biomeWrite = true;
|
AtomicBoolean biomeWrite = new AtomicBoolean(true);
|
||||||
|
|
||||||
List<CompoundTag> nbtList = new ArrayList<>();
|
List<CompoundTag> nbtList = new ArrayList<>();
|
||||||
|
|
||||||
for (int h = 0; h < maxH; h++) {
|
for (int h = 0; h < maxH; h++) {
|
||||||
ChunkSection chunkSection = null;
|
final ChunkSection chunkSection = getChunkSection(h);
|
||||||
|
|
||||||
if (chunk != null) {
|
|
||||||
chunkSection = chunk.getChunkSection(h);
|
|
||||||
} else if (sectionList != null) {
|
|
||||||
chunkSection = sectionList.remove(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chunkSection == null) {
|
if (chunkSection == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final PalettedChunkSection palettedChunkSection = new PalettedChunkSection();
|
|
||||||
|
|
||||||
for (int y = 0; y < 16; y++) {
|
|
||||||
for (int z = 0; z < 16; z++) {
|
|
||||||
for (int x = 0; x < 16; x++) {
|
|
||||||
Block block = chunkSection.getBlock(x, y, z);
|
|
||||||
|
|
||||||
palettedChunkSection.addBlock(
|
|
||||||
block,
|
|
||||||
chunkSection.getSkyLight(x, y, z)
|
|
||||||
);
|
|
||||||
|
|
||||||
CompoundTag nbt = block.getNBTData();
|
|
||||||
if (nbt != null) {
|
|
||||||
nbtList.add(nbt);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (biomeWrite) {
|
|
||||||
biomes.writeByte(chunk.getBiome(
|
|
||||||
(chunk.getX() << 4) + x,
|
|
||||||
(chunk.getZ() << 4) + z
|
|
||||||
).getId());
|
|
||||||
if (x == 15 && z == 15) {
|
|
||||||
biomeWrite = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// <Chunk Section>
|
// <Chunk Section>
|
||||||
palettedChunkSection.writeToNetStream(data);
|
createPalette(chunkSection, nbtList, biomeWrite, biomes)
|
||||||
|
.writeToNetStream(data);
|
||||||
// </Chunk Section>
|
// </Chunk Section>
|
||||||
}
|
}
|
||||||
// <Biomes>
|
// <Biomes>
|
||||||
|
|||||||
Reference in New Issue
Block a user