Archived
0

Block serialization

This commit is contained in:
Forwolk
2018-07-26 13:51:46 +03:00
parent 4f214ed250
commit be91e114df
8 changed files with 97 additions and 7 deletions

View File

@@ -7,7 +7,7 @@ import mc.core.Location;
public abstract class AbstractBlock implements Block {
@Getter@Setter
private Location location;
@Getter@Setter
@Getter
private int meta;
@Getter
private final BlockType blockType;
@@ -16,6 +16,11 @@ public abstract class AbstractBlock implements Block {
this.blockType = type;
}
protected AbstractBlock(BlockType type, int meta) {
this.blockType = type;
this.meta = meta;
}
@Override
public int getId() {
return blockType.getId();

View File

@@ -3,20 +3,20 @@ package mc.core.block;
import mc.core.Location;
/**
* Serialize info about block
* Serialization block info
*
* +------------+--------+------------+
* | param | range | bits |
* +------------+--------+------------+
* | id | 0-255 | 8 |
* | id | 0:255 | 8 |
* +------------+--------+------------+
* | meta | 0-15 | 4 |
* | meta | 0:15 | 4 |
* +------------+--------+------------+
* | x | 0-15 | 4 |
* | x | 0:15 | 4 |
* +------------+--------+------------+
* | y | 0-15 | 4 |
* | y | 0:15 | 4 |
* +------------+--------+------------+
* | z | 0-15 | 4 |
* | z | 0:15 | 4 |
* +------------+--------+------------+
*
* Total: 24 bits per block (3 bytes)

View File

@@ -0,0 +1,17 @@
package mc.core.block;
public class BlockFactory {
public Block create(BlockType blockType, int meta) {
return new EmbeddedBlock(blockType, meta);
}
/**
* For first-time generation
*/
private class EmbeddedBlock extends AbstractBlock {
EmbeddedBlock(BlockType type, int meta) {
super(type, meta);
}
}
}

View File

@@ -0,0 +1,6 @@
package mc.core.serialization;
import mc.core.block.Block;
public interface BlockDeserializer extends Deserializer<Block> {
}

View File

@@ -0,0 +1,6 @@
package mc.core.serialization;
import mc.core.block.Block;
public interface BlockSerializer extends Serializer<Block> {
}

View File

@@ -0,0 +1,5 @@
package mc.core.serialization;
public interface Deserializer<T> {
T deserialize (byte[] bytes);
}

View File

@@ -0,0 +1,5 @@
package mc.core.serialization;
public interface Serializer<T> {
byte[] serialize (T t);
}