mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-10 16:01:50 -04:00
minimal internal restructuring (world now a object of player), Chunk::setBlock function, correct chunk data storage, save data of join packet
This commit is contained in:
parent
d98c6f511e
commit
ac516fa59c
@ -19,15 +19,10 @@ public class Chunk {
|
||||
throw new IllegalArgumentException(String.format("Invalid chunk location %s %s %s", x, y, z));
|
||||
}
|
||||
byte section = (byte) (y / 16);
|
||||
if (section == 0) {
|
||||
return Block.COBBLESTONE;
|
||||
} else if (section == 1) {
|
||||
return Block.DIRT;
|
||||
} else {
|
||||
return Block.AIR;
|
||||
}
|
||||
//ToDo
|
||||
//return chunks.get(section).getBlock(x, y % 16,z);
|
||||
return chunks.get(section).getBlock(x, y % 16, z);
|
||||
}
|
||||
|
||||
public void setBlock(int x, int y, int z, Block block) {
|
||||
chunks.get(y / 16).setBlock(x, y % 16, z, block);
|
||||
}
|
||||
}
|
||||
|
@ -21,4 +21,8 @@ public class ChunkNibble {
|
||||
public Block getBlock(int x, int y, int z) {
|
||||
return getBlock(new ChunkNibbleLocation(x, y, z));
|
||||
}
|
||||
|
||||
public void setBlock(int x, int y, int z, Block block) {
|
||||
blocks.replace(new ChunkNibbleLocation(x, y, z), block);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package de.bixilon.minosoft.game.datatypes;
|
||||
import de.bixilon.minosoft.game.datatypes.blocks.Block;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Collection of ChunkColumns
|
||||
@ -10,6 +11,7 @@ import java.util.HashMap;
|
||||
public class World {
|
||||
public final HashMap<ChunkLocation, Chunk> chunks;
|
||||
final String name;
|
||||
boolean hardcore;
|
||||
|
||||
public World(String name) {
|
||||
this.name = name;
|
||||
@ -32,4 +34,35 @@ public class World {
|
||||
}
|
||||
return Block.AIR;
|
||||
}
|
||||
|
||||
public void setBlock(BlockPosition pos, Block block) {
|
||||
if (getChunk(pos.getChunkLocation()) != null) {
|
||||
getChunk(pos.getChunkLocation()).setBlock(pos.getX() % 16, pos.getX(), pos.getZ() % 16, block);
|
||||
} else {
|
||||
//throw new IllegalAccessException("Chunk is not loaded!");
|
||||
// ToDo
|
||||
}
|
||||
}
|
||||
|
||||
public void unloadChunk(ChunkLocation location) {
|
||||
chunks.remove(location);
|
||||
}
|
||||
|
||||
public void setChunk(ChunkLocation location, Chunk chunk) {
|
||||
chunks.replace(location, chunk);
|
||||
}
|
||||
|
||||
public void setChunks(HashMap<ChunkLocation, Chunk> chunkMap) {
|
||||
for (Map.Entry<ChunkLocation, Chunk> set : chunkMap.entrySet()) {
|
||||
chunks.replace(set.getKey(), set.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isHardcore() {
|
||||
return hardcore;
|
||||
}
|
||||
|
||||
public void setHardcore(boolean hardcore) {
|
||||
this.hardcore = hardcore;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package de.bixilon.minosoft.objects;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.GameMode;
|
||||
import de.bixilon.minosoft.game.datatypes.World;
|
||||
import de.bixilon.minosoft.game.datatypes.player.Location;
|
||||
|
||||
import java.util.UUID;
|
||||
@ -10,6 +12,9 @@ public class Player {
|
||||
short food;
|
||||
float saturation;
|
||||
Location spawnLocation;
|
||||
int entityId;
|
||||
GameMode gameMode;
|
||||
World world = new World("world");
|
||||
|
||||
public Player(Account acc) {
|
||||
this.acc = acc;
|
||||
@ -48,6 +53,10 @@ public class Player {
|
||||
this.saturation = saturation;
|
||||
}
|
||||
|
||||
public float getSaturation() {
|
||||
return saturation;
|
||||
}
|
||||
|
||||
public Location getSpawnLocation() {
|
||||
return spawnLocation;
|
||||
}
|
||||
@ -55,4 +64,24 @@ public class Player {
|
||||
public void setSpawnLocation(Location spawnLocation) {
|
||||
this.spawnLocation = spawnLocation;
|
||||
}
|
||||
|
||||
public GameMode getGameMode() {
|
||||
return gameMode;
|
||||
}
|
||||
|
||||
public void setGameMode(GameMode gameMode) {
|
||||
this.gameMode = gameMode;
|
||||
}
|
||||
|
||||
public int getEntityId() {
|
||||
return entityId;
|
||||
}
|
||||
|
||||
public void setEntityId(int entityId) {
|
||||
this.entityId = entityId;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package de.bixilon.minosoft.protocol.network;
|
||||
|
||||
import de.bixilon.minosoft.Config;
|
||||
import de.bixilon.minosoft.game.datatypes.World;
|
||||
import de.bixilon.minosoft.logging.Log;
|
||||
import de.bixilon.minosoft.objects.Account;
|
||||
import de.bixilon.minosoft.objects.Player;
|
||||
@ -25,7 +24,6 @@ public class Connection {
|
||||
private final PacketHandler handler;
|
||||
private final ArrayList<ClientboundPacket> handlingQueue;
|
||||
private Player player = new Player(new Account(Config.username, Config.password));
|
||||
private World world = new World("world");
|
||||
private ConnectionState state = ConnectionState.DISCONNECTED;
|
||||
|
||||
private boolean onlyPing;
|
||||
@ -135,8 +133,4 @@ public class Connection {
|
||||
});
|
||||
handleThread.start();
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return this.world;
|
||||
}
|
||||
}
|
||||
|
@ -43,11 +43,39 @@ public class PacketJoinGame implements ClientboundPacket {
|
||||
|
||||
@Override
|
||||
public void log() {
|
||||
Log.protocol(String.format("Receiving join game packet (entityId=%s, gameMode=%s, dimension=%s, difficulty=%s)", entityId, gameMode.name(), dimension.name(), difficulty.name()));
|
||||
Log.protocol(String.format("Receiving join game packet (entityId=%s, gameMode=%s, dimension=%s, difficulty=%s, hardcore=%s)", entityId, gameMode.name(), dimension.name(), difficulty.name(), hardcore));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(PacketHandler h) {
|
||||
h.handle(this);
|
||||
}
|
||||
|
||||
public boolean isHardcore() {
|
||||
return hardcore;
|
||||
}
|
||||
|
||||
public int getEntityId() {
|
||||
return entityId;
|
||||
}
|
||||
|
||||
public GameMode getGameMode() {
|
||||
return gameMode;
|
||||
}
|
||||
|
||||
public int getMaxPlayers() {
|
||||
return maxPlayers;
|
||||
}
|
||||
|
||||
public LevelType getLevelType() {
|
||||
return levelType;
|
||||
}
|
||||
|
||||
public Difficulty getDifficulty() {
|
||||
return difficulty;
|
||||
}
|
||||
|
||||
public Dimension getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import de.bixilon.minosoft.protocol.protocol.InPacketBuffer;
|
||||
import de.bixilon.minosoft.protocol.protocol.PacketHandler;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||
|
||||
public class PacketPluginMessageReceived implements ClientboundPacket {
|
||||
public class PacketPluginMessageReceiving implements ClientboundPacket {
|
||||
String channel;
|
||||
byte[] data;
|
||||
|
@ -6,12 +6,12 @@ import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer;
|
||||
import de.bixilon.minosoft.protocol.protocol.Packets;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||
|
||||
public class PacketPluginMessageSended implements ServerboundPacket {
|
||||
public class PacketPluginMessageSending implements ServerboundPacket {
|
||||
|
||||
public final String channel;
|
||||
public final byte[] data;
|
||||
|
||||
public PacketPluginMessageSended(String channel, byte[] data) {
|
||||
public PacketPluginMessageSending(String channel, byte[] data) {
|
||||
this.channel = channel;
|
||||
this.data = data;
|
||||
}
|
@ -10,7 +10,7 @@ import de.bixilon.minosoft.protocol.packets.clientbound.status.PacketStatusPong;
|
||||
import de.bixilon.minosoft.protocol.packets.clientbound.status.PacketStatusResponse;
|
||||
import de.bixilon.minosoft.protocol.packets.serverbound.login.PacketEncryptionResponse;
|
||||
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketKeepAliveResponse;
|
||||
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketPluginMessageSended;
|
||||
import de.bixilon.minosoft.protocol.packets.serverbound.play.PacketPluginMessageSending;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
import java.math.BigInteger;
|
||||
@ -51,6 +51,9 @@ public class PacketHandler {
|
||||
}
|
||||
|
||||
public void handle(PacketJoinGame pkg) {
|
||||
connection.getPlayer().setGameMode(pkg.getGameMode());
|
||||
connection.getPlayer().setEntityId(pkg.getEntityId());
|
||||
connection.getPlayer().getWorld().setHardcore(pkg.isHardcore());
|
||||
}
|
||||
|
||||
public void handle(PacketLoginDisconnect pkg) {
|
||||
@ -69,7 +72,7 @@ public class PacketHandler {
|
||||
}
|
||||
|
||||
public void handle(PacketChunkBulk pkg) {
|
||||
//ToDo
|
||||
connection.getPlayer().getWorld().setChunks(pkg.getChunkMap());
|
||||
}
|
||||
|
||||
public void handle(PacketUpdateHealth pkg) {
|
||||
@ -78,14 +81,14 @@ public class PacketHandler {
|
||||
connection.getPlayer().setSaturation(pkg.getSaturation());
|
||||
}
|
||||
|
||||
public void handle(PacketPluginMessageReceived pkg) {
|
||||
public void handle(PacketPluginMessageReceiving pkg) {
|
||||
if (pkg.getChannel().equals("MC|Brand")) {
|
||||
// server brand received
|
||||
Log.info(String.format("Server is running %s on version %s", new String(pkg.getData()), connection.getVersion().getName()));
|
||||
|
||||
// send back own brand
|
||||
// ToDo option to toggle for minosoft or original minecraft
|
||||
connection.sendPacket(new PacketPluginMessageSended("MC|Brand", "Minosoft".getBytes()));
|
||||
connection.sendPacket(new PacketPluginMessageSending("MC|Brand", "Minosoft".getBytes()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public interface Protocol {
|
||||
packetClassMapping.put(Packets.Clientbound.PLAY_KEEP_ALIVE, PacketKeepAlive.class);
|
||||
packetClassMapping.put(Packets.Clientbound.PLAY_CHUNK_BULK, PacketChunkBulk.class);
|
||||
packetClassMapping.put(Packets.Clientbound.PLAY_UPDATE_HEALTH, PacketUpdateHealth.class);
|
||||
packetClassMapping.put(Packets.Clientbound.PLAY_PLUGIN_MESSAGE, PacketPluginMessageReceived.class);
|
||||
packetClassMapping.put(Packets.Clientbound.PLAY_PLUGIN_MESSAGE, PacketPluginMessageReceiving.class);
|
||||
packetClassMapping.put(Packets.Clientbound.PLAY_SPAWN_POSITION, PacketSpawnLocation.class);
|
||||
packetClassMapping.put(Packets.Clientbound.PLAY_CHAT_MESSAGE, PacketChatMessage.class);
|
||||
packetClassMapping.put(Packets.Clientbound.PLAY_DISCONNECT, PacketDisconnect.class);
|
||||
|
Loading…
x
Reference in New Issue
Block a user