Archived
0

Interfaces

This commit is contained in:
Forwolk
2018-08-02 09:15:59 +03:00
parent 827c13f9b8
commit ad4a088949
6 changed files with 48 additions and 17 deletions

View File

@@ -1,9 +1,14 @@
package mc.core.block;
import com.flowpowered.nbt.Tag;
import lombok.Getter;
import lombok.Setter;
import mc.core.Location;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;
public abstract class AbstractBlock implements Block {
@Getter@Setter
private Location location;
@@ -11,6 +16,7 @@ public abstract class AbstractBlock implements Block {
private int meta;
@Getter
private final BlockType blockType;
private final Map<String, Tag<?>> nbtTagsMap = new HashMap<>();
protected AbstractBlock(BlockType type) {
this.blockType = type;
@@ -25,4 +31,19 @@ public abstract class AbstractBlock implements Block {
public int getId() {
return blockType.getId();
}
@Override
public Tag<?> getTag(String name) {
return nbtTagsMap.get(name);
}
@Override
public void setTag(Tag<?> tag) {
nbtTagsMap.put(tag.getName(), tag);
}
@Override
public Stream<Tag<?>> tagStream() {
return nbtTagsMap.values().stream();
}
}

View File

@@ -1,6 +1,10 @@
package mc.core.block;
import com.flowpowered.nbt.Tag;
import mc.core.Location;
import mc.core.nbt.Taggable;
import java.io.Serializable;
/**
* Serialization block info
@@ -23,23 +27,13 @@ import mc.core.Location;
*
*/
public interface Block {
public interface Block extends Taggable, Serializable{
static Block airBlock (int x, int y, int z) {
return new Block() {
return new AbstractBlock(BlockType.AIR) {
@Override
public int getId() {
return 0;
}
@Override
public int getMeta() {
return 0;
}
@Override
public BlockType getBlockType() {
return BlockType.AIR;
public Tag<?> getTag(String name) {
return null;
}
@Override

View File

@@ -0,0 +1,11 @@
package mc.core.nbt;
import com.flowpowered.nbt.Tag;
import java.util.stream.Stream;
public interface Taggable {
Tag<?> getTag(String name);
void setTag(Tag<?> tag);
Stream<Tag<?>> tagStream();
}

View File

@@ -6,6 +6,8 @@ package mc.core.world;
import mc.core.block.Block;
import java.io.Serializable;
/**
* Serialization chunk info
*
@@ -24,7 +26,7 @@ import mc.core.block.Block;
*
*/
/* 16x16x16 */
public interface Chunk {
public interface Chunk extends Serializable{
int getBlockType(int x, int y, int z);
void setBlockType(int x, int y, int z, int type);

View File

@@ -3,6 +3,7 @@ package mc.core.world;
import mc.core.serialization.Serializer;
import java.io.IOException;
import java.io.Serializable;
/**
* Simple world generation unit
@@ -18,7 +19,7 @@ import java.io.IOException;
* Total: 2097152 bits (256 Kb)
*
*/
public interface Region {
public interface Region extends Serializable{
Chunk getChunkAt(int x, int y, int z);
void setChunk(int x, int y, int z, Chunk chunk);

View File

@@ -5,7 +5,9 @@
package mc.core.world;
import mc.core.Location;
import mc.core.nbt.Taggable;
import java.io.Serializable;
import java.util.UUID;
/**
@@ -39,7 +41,7 @@ import java.util.UUID;
* --> []player_uuid.dat
*/
public interface World {
public interface World extends Taggable, Serializable{
UUID getWorldId();
IWorldType getWorldType();