stash 2
This commit is contained in:
15
core/src/main/java/mc/core/world/Block.java
Normal file
15
core/src/main/java/mc/core/world/Block.java
Normal 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();
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
ByteArrayOutputNetStream baos = new ByteArrayOutputNetStream();
|
||||
for (Chunk chunk : chunks) {
|
||||
netStream.writeByte(4); // Bits Per Block
|
||||
// <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??
|
||||
}
|
||||
netStream.writeVarInt(baos.size()); // Size of Data in bytes
|
||||
netStream.writeBytes(baos.toByteArray()); // Data chunks
|
||||
|
||||
Reference in New Issue
Block a user