mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-09 07:20:04 -04:00
wip world data types (chunk, ...)
This commit is contained in:
parent
dfefd5c50f
commit
faab6664c6
@ -1,4 +1,4 @@
|
||||
package de.bixilon.minosoft.objects;
|
||||
package de.bixilon.minosoft.game.datatypes;
|
||||
|
||||
public class BlockPosition {
|
||||
int x;
|
||||
@ -27,6 +27,9 @@ public class BlockPosition {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (super.equals(obj)) {
|
||||
return true;
|
||||
}
|
||||
BlockPosition pos = (BlockPosition) obj;
|
||||
return pos.getX() == getX() && pos.getY() == getY() && pos.getZ() == getZ();
|
||||
}
|
23
src/main/java/de/bixilon/minosoft/game/datatypes/Chunk.java
Normal file
23
src/main/java/de/bixilon/minosoft/game/datatypes/Chunk.java
Normal file
@ -0,0 +1,23 @@
|
||||
package de.bixilon.minosoft.game.datatypes;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Collection of 16x16x16 blocks
|
||||
*/
|
||||
public class Chunk {
|
||||
private final HashMap<ChunkLocation, WorldBlock> blocks;
|
||||
|
||||
public Chunk() {
|
||||
blocks = new HashMap<>();
|
||||
}
|
||||
|
||||
public WorldBlock getWorldBlock(ChunkLocation loc) {
|
||||
//ToDo will return air if null
|
||||
return blocks.get(loc);
|
||||
}
|
||||
|
||||
public WorldBlock getWorldBlock(byte x, byte y, byte z) {
|
||||
return getWorldBlock(new ChunkLocation(x, y, z));
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package de.bixilon.minosoft.game.datatypes;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Collection of 16 chunks
|
||||
*/
|
||||
public class ChunkColumn {
|
||||
private final HashMap<Byte, Chunk> chunks;
|
||||
|
||||
public ChunkColumn(int x, int z) {
|
||||
chunks = new HashMap<>();
|
||||
}
|
||||
|
||||
public WorldBlock getWorldBlock(byte x, short y, byte z) {
|
||||
if (x > 16 || y > 255 || z > 16 || x < 0 || y < 0 || z < 0) {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package de.bixilon.minosoft.game.datatypes;
|
||||
|
||||
/**
|
||||
* Chunk X and Z location (block position / 16, rounded down)
|
||||
*/
|
||||
public class ChunkColumnLocation {
|
||||
int x;
|
||||
int z;
|
||||
|
||||
public ChunkColumnLocation(int x, int z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (super.equals(obj)) {
|
||||
return true;
|
||||
}
|
||||
ChunkColumnLocation that = (ChunkColumnLocation) obj;
|
||||
return getX() == that.getX() && getZ() == that.getZ();
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package de.bixilon.minosoft.game.datatypes;
|
||||
|
||||
/**
|
||||
* Chunk X, Y and Z location (max 16x16x16)
|
||||
*/
|
||||
public class ChunkLocation {
|
||||
byte x;
|
||||
byte y;
|
||||
byte z;
|
||||
|
||||
public ChunkLocation(byte x, byte y, byte z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public byte getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public byte getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public byte getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (super.equals(obj)) {
|
||||
return true;
|
||||
}
|
||||
ChunkLocation that = (ChunkLocation) obj;
|
||||
return getX() == that.getX() && getY() == that.getY() && getZ() == that.getZ();
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package de.bixilon.minosoft.objects;
|
||||
package de.bixilon.minosoft.game.datatypes;
|
||||
|
||||
public enum Difficulty {
|
||||
PEACEFUL(0),
|
@ -1,4 +1,4 @@
|
||||
package de.bixilon.minosoft.objects;
|
||||
package de.bixilon.minosoft.game.datatypes;
|
||||
|
||||
public enum Dimension {
|
||||
NETHER(-1),
|
@ -1,4 +1,4 @@
|
||||
package de.bixilon.minosoft.objects;
|
||||
package de.bixilon.minosoft.game.datatypes;
|
||||
|
||||
public enum GameMode {
|
||||
SURVIVAL(0),
|
@ -1,4 +1,4 @@
|
||||
package de.bixilon.minosoft.objects;
|
||||
package de.bixilon.minosoft.game.datatypes;
|
||||
|
||||
public enum LevelType {
|
||||
DEFAULT("default"),
|
24
src/main/java/de/bixilon/minosoft/game/datatypes/World.java
Normal file
24
src/main/java/de/bixilon/minosoft/game/datatypes/World.java
Normal file
@ -0,0 +1,24 @@
|
||||
package de.bixilon.minosoft.game.datatypes;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Collection of ChunkColumns
|
||||
*/
|
||||
public class World {
|
||||
public final HashMap<ChunkColumnLocation, ChunkColumn> chunks;
|
||||
final String name;
|
||||
|
||||
public World(String name) {
|
||||
this.name = name;
|
||||
chunks = new HashMap<>();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public ChunkColumn getChunkColumn(ChunkColumnLocation loc) {
|
||||
return chunks.get(loc);
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
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 {
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package de.bixilon.minosoft.protocol.packets.clientbound.play;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.Difficulty;
|
||||
import de.bixilon.minosoft.game.datatypes.Dimension;
|
||||
import de.bixilon.minosoft.game.datatypes.GameMode;
|
||||
import de.bixilon.minosoft.game.datatypes.LevelType;
|
||||
import de.bixilon.minosoft.logging.Log;
|
||||
import de.bixilon.minosoft.objects.Difficulty;
|
||||
import de.bixilon.minosoft.objects.Dimension;
|
||||
import de.bixilon.minosoft.objects.GameMode;
|
||||
import de.bixilon.minosoft.objects.LevelType;
|
||||
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
||||
import de.bixilon.minosoft.protocol.protocol.InPacketBuffer;
|
||||
import de.bixilon.minosoft.protocol.protocol.PacketHandler;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package de.bixilon.minosoft.protocol.protocol;
|
||||
|
||||
import de.bixilon.minosoft.objects.BlockPosition;
|
||||
import de.bixilon.minosoft.game.datatypes.BlockPosition;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package de.bixilon.minosoft.protocol.protocol;
|
||||
|
||||
import de.bixilon.minosoft.objects.BlockPosition;
|
||||
import de.bixilon.minosoft.game.datatypes.BlockPosition;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
Loading…
x
Reference in New Issue
Block a user