Archived
0
This commit is contained in:
2018-08-02 14:25:29 +03:00
parent e682abf662
commit 0152377289
4 changed files with 84 additions and 21 deletions

View File

@@ -0,0 +1,15 @@
/*
* DmitriyMX <dimon550@gmail.com>
* 2018-08-02
*/
package mc.core.world;
import mc.core.Location;
public interface Block {
int getId();
int getState();
int getMetadata();
int getLight();
Location getLocation();
}

View File

@@ -4,16 +4,15 @@
*/
package mc.core.world;
import mc.core.Location;
/* 16x16x16 */
public interface Chunk {
int getBlockType(int x, int y, int z);
void setBlockType(int x, int y, int z, int type);
int getBlockMetadata(int x, int y, int z);
void setBlockMetadata(int x, int y, int z, int metadata);
int getBlockLight(int x, int y, int z);
void setBlockLight(int x, int y, int z, int lightLevel);
Block getBlock(int x, int y, int z);
default Block getBlock(Location location) {
return getBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
void setBlock(Block block);
int getSkyLight(int x, int y, int z);
void setSkyLight(int x, int y, int z, int lightLevel);

View File

@@ -65,6 +65,10 @@ public class ByteArrayOutputNetStream extends NetOutputStream_p340 {
writeLong(Double.doubleToLongBits(value));
}
public int size() {
return baos.size();
}
public byte[] toByteArray() {
return baos.toByteArray();
}

View File

@@ -10,6 +10,7 @@ import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import mc.core.network.NetOutputStream;
import mc.core.network.SCPacket;
import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream;
import mc.core.world.Chunk;
import java.io.ByteArrayOutputStream;
@@ -17,6 +18,55 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/*
Packet structure
- https://wiki.vg/Chunk_Format#Packet_structure
+------------------------------------------------------+
| Field | Type |
|--------------------------|---------------------------|
| Chunk X | int |
|--------------------------|---------------------------|
| Chunk Y | int |
|--------------------------|---------------------------|
| Init Chunk | boolean | ("Ground-Up Continuous")
|--------------------------|---------------------------|
| Primary Bit Mask | VarInt |
|--------------------------|---------------------------|
| Size of Data | VarInt |
|--------------------------|---------------------------|
| Data | Byte array | - https://wiki.vg/Chunk_Format#Data_structure
| +------------------------------------------------+ |
| | Chunk Section | Byte array | | - https://wiki.vg/Chunk_Format#Chunk_Section_structure
| | +------------------------------------------+ | |
| | | Bits Per Block | Unsigned Byte | | |
| | |--------------------|---------------------| | |
| | | Palette | Byte array | | | - https://wiki.vg/Chunk_Format#Palettes
| | | +------------------------------------+ | | | (we use Indirect type palette)
| | | | Size of palette | VarInt | | | |
| | | |-----------------|------------------| | | |
| | | | Palette | Array of VarInt | | | |
| | | +------------------------------------+ | | |
| | |--------------------|---------------------| | |
| | | Size of Data Array | VarInt | | |
| | |--------------------|---------------------| | |
| | | Data Array | Array of Long | | |
| | |--------------------|---------------------| | |
| | | Block Light | Byte Array | | |
| | |--------------------|---------------------| | |
| | | Sky Light | Optional Byte Array | | |
| | +------------------------------------------+ | |
| |-----------------------|------------------------| |
| | Biomes | Optional Byte array | |
| +------------------------------------------------+ |
|--------------------------|---------------------------|
| Number of block entities | VarInt |
|--------------------------|---------------------------|
| Block entities | Array of NBT |
+------------------------------------------------------+
*/
@Slf4j
@NoArgsConstructor
public class ChunkDataPacket implements SCPacket {
@@ -36,19 +86,14 @@ public class ChunkDataPacket implements SCPacket {
netStream.writeBoolean(initChunk);
netStream.writeVarInt(0b11111111); // Primary Bit Mask
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
for (Chunk chunk : chunks) {
netStream.writeByte(4); // Bits Per Block
// <Palette />
// <Data Array Length />
// <Data Array />
// <Block Light />
// <Sky Light />
// baos.write(ChunkSerializer.serializeBiomes(chunk));
}
} catch (IOException e) {
log.error("Error serialize chunk", e); // what? is it possible??
ByteArrayOutputNetStream baos = new ByteArrayOutputNetStream();
for (Chunk chunk : chunks) {
// <Bits Per Block />
// <Palette />
// <Data Array Length />
// <Data Array />
// <Block Light />
// <Sky Light />
}
netStream.writeVarInt(baos.size()); // Size of Data in bytes
netStream.writeBytes(baos.toByteArray()); // Data chunks