Block serialization
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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)
|
||||
|
||||
17
core/src/main/java/mc/core/block/BlockFactory.java
Normal file
17
core/src/main/java/mc/core/block/BlockFactory.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package mc.core.serialization;
|
||||
|
||||
import mc.core.block.Block;
|
||||
|
||||
public interface BlockDeserializer extends Deserializer<Block> {
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package mc.core.serialization;
|
||||
|
||||
import mc.core.block.Block;
|
||||
|
||||
public interface BlockSerializer extends Serializer<Block> {
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package mc.core.serialization;
|
||||
|
||||
public interface Deserializer<T> {
|
||||
T deserialize (byte[] bytes);
|
||||
}
|
||||
5
core/src/main/java/mc/core/serialization/Serializer.java
Normal file
5
core/src/main/java/mc/core/serialization/Serializer.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package mc.core.serialization;
|
||||
|
||||
public interface Serializer<T> {
|
||||
byte[] serialize (T t);
|
||||
}
|
||||
Reference in New Issue
Block a user