mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 08:58:02 -04:00
basic world data types with dummy data (wip 2)
This commit is contained in:
parent
faab6664c6
commit
00239e9f18
@ -8,12 +8,11 @@ import java.util.HashMap;
|
||||
public class Chunk {
|
||||
private final HashMap<ChunkLocation, WorldBlock> blocks;
|
||||
|
||||
public Chunk() {
|
||||
blocks = new HashMap<>();
|
||||
public Chunk(HashMap<ChunkLocation, WorldBlock> blocks) {
|
||||
this.blocks = blocks;
|
||||
}
|
||||
|
||||
public WorldBlock getWorldBlock(ChunkLocation loc) {
|
||||
//ToDo will return air if null
|
||||
return blocks.get(loc);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package de.bixilon.minosoft.game.datatypes;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.blocks.Blocks;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
@ -7,9 +9,13 @@ import java.util.HashMap;
|
||||
*/
|
||||
public class ChunkColumn {
|
||||
private final HashMap<Byte, Chunk> chunks;
|
||||
final int x;
|
||||
final int z;
|
||||
|
||||
public ChunkColumn(int x, int z) {
|
||||
chunks = new HashMap<>();
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public WorldBlock getWorldBlock(byte x, short y, byte z) {
|
||||
@ -17,7 +23,14 @@ public class ChunkColumn {
|
||||
throw new IllegalArgumentException(String.format("Invalid chunk location %s %s %s", x, y, z));
|
||||
}
|
||||
byte heightNumber = (byte) (y / 16);
|
||||
return chunks.get(heightNumber).getWorldBlock(x, (byte) (y - (heightNumber * 16)), z);
|
||||
BlockPosition pos = new BlockPosition(this.x * 16 + x, y, this.z * 16 + z);
|
||||
if (heightNumber == 0) {
|
||||
return Blocks.getBlockInstance(Blocks.DIRT, pos);
|
||||
} else {
|
||||
return Blocks.getBlockInstance(Blocks.AIR, pos);
|
||||
}
|
||||
//ToDo
|
||||
//return chunks.get(heightNumber).getWorldBlock(x, (byte) (y - (heightNumber * 16)), z);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ public class World {
|
||||
}
|
||||
|
||||
public ChunkColumn getChunkColumn(ChunkColumnLocation loc) {
|
||||
return chunks.get(loc);
|
||||
return new ChunkColumn(loc.getX(), loc.getZ());
|
||||
//ToDo
|
||||
//return chunks.get(loc);
|
||||
}
|
||||
}
|
||||
|
@ -3,5 +3,6 @@ package de.bixilon.minosoft.game.datatypes;
|
||||
/**
|
||||
* Basically raw chunk stuff. This is not a block like dirt (it can be). Can be dirt, a flower, fire, torch, sapling, fluid (water/lava), nether wart, banner, ...
|
||||
*/
|
||||
public class WorldBlock {
|
||||
public interface WorldBlock {
|
||||
BlockPosition getBlockPosition();
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
package de.bixilon.minosoft.game.datatypes.blocks;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.BlockPosition;
|
||||
|
||||
public class Air implements Block {
|
||||
final BlockPosition position;
|
||||
|
||||
public Air(BlockPosition position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPosition getBlockPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLegacyId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLegacyIdentifier() {
|
||||
return "minecraft:air";
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package de.bixilon.minosoft.game.datatypes.blocks;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.WorldBlock;
|
||||
|
||||
public interface Block extends WorldBlock {
|
||||
|
||||
String getLegacyIdentifier();
|
||||
|
||||
int getLegacyId();
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package de.bixilon.minosoft.game.datatypes.blocks;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.BlockPosition;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public enum Blocks {
|
||||
DIRT(Dirt.class),
|
||||
AIR(Air.class);
|
||||
|
||||
private final Class<? extends Block> clazz;
|
||||
|
||||
Blocks(Class<? extends Block> clazz) {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public static Block getBlockInstance(Class<? extends Block> clazz, BlockPosition pos) {
|
||||
try {
|
||||
return clazz.getConstructor(BlockPosition.class).newInstance(pos);
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Invalid block constructor!");
|
||||
}
|
||||
}
|
||||
|
||||
public static Block getBlockInstance(Blocks b, BlockPosition pos) {
|
||||
return getBlockInstance(b.getClazz(), pos);
|
||||
}
|
||||
|
||||
public Class<? extends Block> getClazz() {
|
||||
return clazz;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package de.bixilon.minosoft.game.datatypes.blocks;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.BlockPosition;
|
||||
|
||||
public class Dirt implements Block {
|
||||
final BlockPosition position;
|
||||
|
||||
public Dirt(BlockPosition position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPosition getBlockPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLegacyId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLegacyIdentifier() {
|
||||
return "minecraft:dirt";
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user