forked from Kolyah35/minecraft-pe-0.6.1
Compare commits
23 Commits
dedicated-
...
dedicated-
| Author | SHA1 | Date | |
|---|---|---|---|
| 26e5376030 | |||
| d3d9b1a238 | |||
| f0df3fe257 | |||
| 3ebed84cdb | |||
| b73f7f121d | |||
|
|
5e19ef778e | ||
| 5bc19c4ab2 | |||
| dfb3bf1da7 | |||
| 263118f2e0 | |||
| 1d0264a9c5 | |||
| 43f0d1f75f | |||
| 70308d4151 | |||
| 830549791a | |||
| 27b22d8108 | |||
| 4047fd71e1 | |||
| 30dd344208 | |||
| 7e9de7a461 | |||
| 2465292473 | |||
| 26b2c196fa | |||
| 18793a6e05 | |||
|
|
3e48c7fabd | ||
| de72a9a3b7 | |||
| 0645905fc6 |
@@ -149,7 +149,6 @@ file(GLOB SERVER_SOURCES
|
|||||||
|
|
||||||
"src/platform/CThread.cpp"
|
"src/platform/CThread.cpp"
|
||||||
"src/platform/HttpClient.cpp"
|
"src/platform/HttpClient.cpp"
|
||||||
"src/platform/PngLoader.cpp"
|
|
||||||
"src/platform/time.cpp"
|
"src/platform/time.cpp"
|
||||||
|
|
||||||
"src/platform/input/Controller.cpp"
|
"src/platform/input/Controller.cpp"
|
||||||
@@ -302,18 +301,16 @@ if (${PLATFORM} STREQUAL "Desktop")
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Server
|
# Server
|
||||||
if(UNIX)
|
add_executable("${PROJECT_NAME}-server" ${SERVER_SOURCES})
|
||||||
add_executable("${PROJECT_NAME}-server" ${SERVER_SOURCES})
|
|
||||||
|
|
||||||
target_compile_definitions("${PROJECT_NAME}-server" PUBLIC "STANDALONE_SERVER" "SERVER_PROFILER")
|
target_compile_definitions("${PROJECT_NAME}-server" PUBLIC "STANDALONE_SERVER" "SERVER_PROFILER")
|
||||||
|
|
||||||
target_include_directories("${PROJECT_NAME}-server" PUBLIC
|
target_include_directories("${PROJECT_NAME}-server" PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/src/"
|
"${CMAKE_SOURCE_DIR}/src/"
|
||||||
"project/lib_projects/raknet/jni/RaknetSources"
|
"project/lib_projects/raknet/jni/RaknetSources"
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries("${PROJECT_NAME}-server" ${CMAKE_THREAD_LIBS_INIT})
|
target_link_libraries("${PROJECT_NAME}-server" ${CMAKE_THREAD_LIBS_INIT})
|
||||||
endif()
|
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} ${CLIENT_SOURCES})
|
add_executable(${PROJECT_NAME} ${CLIENT_SOURCES})
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ LOCAL_SRC_FILES := ../../../src/main.cpp \
|
|||||||
../../../src/client/renderer/Textures.cpp \
|
../../../src/client/renderer/Textures.cpp \
|
||||||
../../../src/client/renderer/TileRenderer.cpp \
|
../../../src/client/renderer/TileRenderer.cpp \
|
||||||
../../../src/client/renderer/gles.cpp \
|
../../../src/client/renderer/gles.cpp \
|
||||||
|
../../../src/world/level/LevelConstants.cpp \
|
||||||
../../../src/client/renderer/culling/Frustum.cpp \
|
../../../src/client/renderer/culling/Frustum.cpp \
|
||||||
../../../src/client/renderer/entity/ArrowRenderer.cpp \
|
../../../src/client/renderer/entity/ArrowRenderer.cpp \
|
||||||
../../../src/client/renderer/entity/ChickenRenderer.cpp \
|
../../../src/client/renderer/entity/ChickenRenderer.cpp \
|
||||||
@@ -139,6 +140,12 @@ LOCAL_SRC_FILES := ../../../src/main.cpp \
|
|||||||
../../../src/network/Packet.cpp \
|
../../../src/network/Packet.cpp \
|
||||||
../../../src/network/RakNetInstance.cpp \
|
../../../src/network/RakNetInstance.cpp \
|
||||||
../../../src/network/ServerSideNetworkHandler.cpp \
|
../../../src/network/ServerSideNetworkHandler.cpp \
|
||||||
|
../../../src/commands/Command.cpp \
|
||||||
|
../../../src/commands/CommandHelp.cpp \
|
||||||
|
../../../src/commands/CommandKick.cpp \
|
||||||
|
../../../src/commands/CommandBan.cpp \
|
||||||
|
../../../src/commands/CommandManager.cpp \
|
||||||
|
../../../src/commands/CommandOp.cpp \
|
||||||
../../../src/server/ServerLevel.cpp \
|
../../../src/server/ServerLevel.cpp \
|
||||||
../../../src/server/ServerPlayer.cpp \
|
../../../src/server/ServerPlayer.cpp \
|
||||||
../../../src/util/DataIO.cpp \
|
../../../src/util/DataIO.cpp \
|
||||||
|
|||||||
@@ -228,6 +228,7 @@ LOCAL_SRC_FILES := ../../../src/main.cpp \
|
|||||||
../../../src/world/level/tile/entity/TileEntity.cpp \
|
../../../src/world/level/tile/entity/TileEntity.cpp \
|
||||||
../../../src/world/level/tile/entity/FurnaceTileEntity.cpp \
|
../../../src/world/level/tile/entity/FurnaceTileEntity.cpp \
|
||||||
../../../src/world/phys/HitResult.cpp
|
../../../src/world/phys/HitResult.cpp
|
||||||
|
../../../src/world/level/LevelConstants.cpp
|
||||||
|
|
||||||
LOCAL_CFLAGS := -Wno-psabi $(LOCAL_CFLAGS)
|
LOCAL_CFLAGS := -Wno-psabi $(LOCAL_CFLAGS)
|
||||||
|
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ void NinecraftApp::teardown()
|
|||||||
Recipes ::teardownRecipes();
|
Recipes ::teardownRecipes();
|
||||||
TileEntity::teardownTileEntities();
|
TileEntity::teardownTileEntities();
|
||||||
#endif
|
#endif
|
||||||
#ifdef WIN32
|
#if defined(WIN32) && !defined(STANDALONE_SERVER)
|
||||||
ItemRenderer::teardown_static();
|
ItemRenderer::teardown_static();
|
||||||
if (EntityTileRenderer::instance != NULL) {
|
if (EntityTileRenderer::instance != NULL) {
|
||||||
delete EntityTileRenderer::instance;
|
delete EntityTileRenderer::instance;
|
||||||
|
|||||||
@@ -258,9 +258,10 @@ void Minecraft::selectLevel( const std::string& levelId, const std::string& leve
|
|||||||
|
|
||||||
void Minecraft::setLevel(Level* level, const std::string& message /* ="" */, LocalPlayer* forceInsertPlayer /* = NULL */) {
|
void Minecraft::setLevel(Level* level, const std::string& message /* ="" */, LocalPlayer* forceInsertPlayer /* = NULL */) {
|
||||||
cameraTargetPlayer = NULL;
|
cameraTargetPlayer = NULL;
|
||||||
LOGI("Seed is %ld\n", level->getSeed());
|
|
||||||
|
|
||||||
if (level != NULL) {
|
if (level != NULL) {
|
||||||
|
LOGI("Seed is %ld\n", level->getSeed());
|
||||||
|
|
||||||
level->raknetInstance = raknetInstance;
|
level->raknetInstance = raknetInstance;
|
||||||
gameMode->initLevel(level);
|
gameMode->initLevel(level);
|
||||||
|
|
||||||
@@ -278,7 +279,10 @@ void Minecraft::setLevel(Level* level, const std::string& message /* ="" */, Loc
|
|||||||
}
|
}
|
||||||
this->level = level;
|
this->level = level;
|
||||||
// So uhhh
|
// So uhhh
|
||||||
level->ops.emplace(options.getStringValue(OPTIONS_USERNAME));
|
std::string op = options.getStringValue(OPTIONS_USERNAME);
|
||||||
|
std::transform(op.begin(), op.end(), op.begin(), ::tolower);
|
||||||
|
|
||||||
|
level->ops.emplace(op);
|
||||||
_hasSignaledGeneratingLevelFinished = false;
|
_hasSignaledGeneratingLevelFinished = false;
|
||||||
#ifdef STANDALONE_SERVER
|
#ifdef STANDALONE_SERVER
|
||||||
const bool threadedLevelCreation = false;
|
const bool threadedLevelCreation = false;
|
||||||
@@ -362,10 +366,10 @@ void Minecraft::prepareLevel(const std::string& title) {
|
|||||||
if (!level->isNew())
|
if (!level->isNew())
|
||||||
level->setUpdateLights(false);
|
level->setUpdateLights(false);
|
||||||
|
|
||||||
int Max = CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH;
|
int Max = LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_CACHE_WIDTH;
|
||||||
int pp = 0;
|
int pp = 0;
|
||||||
for (int x = 8; x < (CHUNK_CACHE_WIDTH * CHUNK_WIDTH); x += CHUNK_WIDTH) {
|
for (int x = 8; x < (LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_WIDTH); x += LevelConstants::CHUNK_WIDTH) {
|
||||||
for (int z = 8; z < (CHUNK_CACHE_WIDTH * CHUNK_WIDTH); z += CHUNK_WIDTH) {
|
for (int z = 8; z < (LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_WIDTH); z += LevelConstants::CHUNK_WIDTH) {
|
||||||
progressStagePercentage = 100 * pp++ / Max;
|
progressStagePercentage = 100 * pp++ / Max;
|
||||||
//printf("level generation progress %d\n", progressStagePercentage);
|
//printf("level generation progress %d\n", progressStagePercentage);
|
||||||
B.start();
|
B.start();
|
||||||
@@ -382,9 +386,9 @@ void Minecraft::prepareLevel(const std::string& title) {
|
|||||||
level->setUpdateLights(true);
|
level->setUpdateLights(true);
|
||||||
|
|
||||||
C.start();
|
C.start();
|
||||||
for (int x = 0; x < CHUNK_CACHE_WIDTH; x++)
|
for (int x = 0; x < LevelConstants::CHUNK_CACHE_WIDTH; x++)
|
||||||
{
|
{
|
||||||
for (int z = 0; z < CHUNK_CACHE_WIDTH; z++)
|
for (int z = 0; z < LevelConstants::CHUNK_CACHE_WIDTH; z++)
|
||||||
{
|
{
|
||||||
LevelChunk* chunk = level->getChunk(x, z);
|
LevelChunk* chunk = level->getChunk(x, z);
|
||||||
if (chunk && !chunk->createdFromSave)
|
if (chunk && !chunk->createdFromSave)
|
||||||
@@ -732,19 +736,19 @@ void Minecraft::tickInput() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: replace it with client /give command :face_vomiting:
|
// TODO: replace it with client /give command :face_vomiting:
|
||||||
if (key == Keyboard::KEY_F4) {
|
// if (key == Keyboard::KEY_F4) {
|
||||||
player->inventory->add(new ItemInstance(Tile::redBrick));
|
// player->inventory->add(new ItemInstance(Tile::redBrick));
|
||||||
player->inventory->add(new ItemInstance(Item::ironIngot, 64));
|
// player->inventory->add(new ItemInstance(Item::ironIngot, 64));
|
||||||
player->inventory->add(new ItemInstance(Item::ironIngot, 34));
|
// player->inventory->add(new ItemInstance(Item::ironIngot, 34));
|
||||||
player->inventory->add(new ItemInstance(Tile::stonecutterBench));
|
// player->inventory->add(new ItemInstance(Tile::stonecutterBench));
|
||||||
player->inventory->add(new ItemInstance(Tile::workBench));
|
// player->inventory->add(new ItemInstance(Tile::workBench));
|
||||||
player->inventory->add(new ItemInstance(Tile::furnace));
|
// player->inventory->add(new ItemInstance(Tile::furnace));
|
||||||
player->inventory->add(new ItemInstance(Tile::wood, 54));
|
// player->inventory->add(new ItemInstance(Tile::wood, 54));
|
||||||
player->inventory->add(new ItemInstance(Item::stick, 14));
|
// player->inventory->add(new ItemInstance(Item::stick, 14));
|
||||||
player->inventory->add(new ItemInstance(Item::coal, 31));
|
// player->inventory->add(new ItemInstance(Item::coal, 31));
|
||||||
player->inventory->add(new ItemInstance(Tile::sand, 6));
|
// player->inventory->add(new ItemInstance(Tile::sand, 6));
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (key == Keyboard::KEY_F5) {
|
if (key == Keyboard::KEY_F5) {
|
||||||
options.toggle(OPTIONS_THIRD_PERSON_VIEW);
|
options.toggle(OPTIONS_THIRD_PERSON_VIEW);
|
||||||
@@ -1134,6 +1138,7 @@ bool Minecraft::supportNonTouchScreen() {
|
|||||||
}
|
}
|
||||||
void Minecraft::init()
|
void Minecraft::init()
|
||||||
{
|
{
|
||||||
|
LevelChunk::ChunkBlockCount = LevelConstants::CHUNK_BLOCK_COUNT;
|
||||||
#ifndef STANDALONE_SERVER
|
#ifndef STANDALONE_SERVER
|
||||||
checkGlError("Init enter");
|
checkGlError("Init enter");
|
||||||
|
|
||||||
@@ -1322,12 +1327,9 @@ bool Minecraft::joinMultiplayerFromString( const std::string& server )
|
|||||||
} else {
|
} else {
|
||||||
ip = server;
|
ip = server;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%s \n", port.c_str());
|
|
||||||
|
|
||||||
if (isLookingForMultiplayer && netCallback) {
|
if (isLookingForMultiplayer && netCallback) {
|
||||||
isLookingForMultiplayer = false;
|
isLookingForMultiplayer = false;
|
||||||
printf("test");
|
|
||||||
int portNum = atoi(port.c_str());
|
int portNum = atoi(port.c_str());
|
||||||
return raknetInstance->connect(ip.c_str(), portNum);
|
return raknetInstance->connect(ip.c_str(), portNum);
|
||||||
}
|
}
|
||||||
@@ -1606,6 +1608,6 @@ void Minecraft::addMessage(const std::string& msg) {
|
|||||||
#ifndef STANDALONE_SERVER
|
#ifndef STANDALONE_SERVER
|
||||||
gui.addMessage(msg);
|
gui.addMessage(msg);
|
||||||
#else
|
#else
|
||||||
LOGI("%s", msg.c_str());
|
LOGI("%s \n", msg.c_str());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ LevelRenderer::LevelRenderer( Minecraft* mc)
|
|||||||
destroyProgress(0)
|
destroyProgress(0)
|
||||||
{
|
{
|
||||||
#ifdef OPENGL_ES
|
#ifdef OPENGL_ES
|
||||||
int maxChunksWidth = 2 * LEVEL_WIDTH / CHUNK_SIZE + 1;
|
int maxChunksWidth = 2 * LevelConstants::LEVEL_WIDTH / CHUNK_SIZE + 1;
|
||||||
numListsOrBuffers = maxChunksWidth * maxChunksWidth * (128/CHUNK_SIZE) * 3;
|
numListsOrBuffers = maxChunksWidth * maxChunksWidth * (128/CHUNK_SIZE) * 3;
|
||||||
chunkBuffers = new GLuint[numListsOrBuffers];
|
chunkBuffers = new GLuint[numListsOrBuffers];
|
||||||
glGenBuffers2(numListsOrBuffers, chunkBuffers);
|
glGenBuffers2(numListsOrBuffers, chunkBuffers);
|
||||||
@@ -1077,53 +1077,54 @@ void LevelRenderer::playSound(const std::string& name, float x, float y, float z
|
|||||||
float dd = 16;
|
float dd = 16;
|
||||||
|
|
||||||
if (volume > 1) dd *= volume;
|
if (volume > 1) dd *= volume;
|
||||||
if (mc->cameraTargetPlayer->distanceToSqr(x, y, z) < dd * dd) {
|
if (mc->cameraTargetPlayer != NULL && mc->cameraTargetPlayer->distanceToSqr(x, y, z) < dd * dd) {
|
||||||
mc->soundEngine->play(name, x, y, z, volume, pitch);
|
mc->soundEngine->play(name, x, y, z, volume, pitch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LevelRenderer::addParticle(const std::string& name, float x, float y, float z, float xa, float ya, float za, int data) {
|
void LevelRenderer::addParticle(const std::string& name, float x, float y, float z, float xa, float ya, float za, int data) {
|
||||||
|
if (mc->cameraTargetPlayer != NULL) {
|
||||||
|
float xd = mc->cameraTargetPlayer->x - x;
|
||||||
|
float yd = mc->cameraTargetPlayer->y - y;
|
||||||
|
float zd = mc->cameraTargetPlayer->z - z;
|
||||||
|
float distanceSquared = xd * xd + yd * yd + zd * zd;
|
||||||
|
|
||||||
float xd = mc->cameraTargetPlayer->x - x;
|
//Particle* p = NULL;
|
||||||
float yd = mc->cameraTargetPlayer->y - y;
|
//if (name == "hugeexplosion") p = new HugeExplosionSeedParticle(level, x, y, z, xa, ya, za);
|
||||||
float zd = mc->cameraTargetPlayer->z - z;
|
//else if (name == "largeexplode") p = new HugeExplosionParticle(textures, level, x, y, z, xa, ya, za);
|
||||||
float distanceSquared = xd * xd + yd * yd + zd * zd;
|
|
||||||
|
|
||||||
//Particle* p = NULL;
|
//if (p) {
|
||||||
//if (name == "hugeexplosion") p = new HugeExplosionSeedParticle(level, x, y, z, xa, ya, za);
|
// if (distanceSquared < 32 * 32) {
|
||||||
//else if (name == "largeexplode") p = new HugeExplosionParticle(textures, level, x, y, z, xa, ya, za);
|
// mc->particleEngine->add(p);
|
||||||
|
// } else { delete p; }
|
||||||
|
// return;
|
||||||
|
//}
|
||||||
|
|
||||||
//if (p) {
|
const float particleDistance = 16;
|
||||||
// if (distanceSquared < 32 * 32) {
|
if (distanceSquared > particleDistance * particleDistance) return;
|
||||||
// mc->particleEngine->add(p);
|
|
||||||
// } else { delete p; }
|
|
||||||
// return;
|
|
||||||
//}
|
|
||||||
|
|
||||||
const float particleDistance = 16;
|
//static Stopwatch sw;
|
||||||
if (distanceSquared > particleDistance * particleDistance) return;
|
//sw.start();
|
||||||
|
|
||||||
//static Stopwatch sw;
|
if (name == "bubble") mc->particleEngine->add(new BubbleParticle(level, x, y, z, xa, ya, za));
|
||||||
//sw.start();
|
else if (name == "crit") mc->particleEngine->add(new CritParticle2(level, x, y, z, xa, ya, za));
|
||||||
|
else if (name == "smoke") mc->particleEngine->add(new SmokeParticle(level, x, y, z, xa, ya, za));
|
||||||
|
//else if (name == "note") mc->particleEngine->add(new NoteParticle(level, x, y, z, xa, ya, za));
|
||||||
|
else if (name == "explode") mc->particleEngine->add(new ExplodeParticle(level, x, y, z, xa, ya, za));
|
||||||
|
else if (name == "flame") mc->particleEngine->add(new FlameParticle(level, x, y, z, xa, ya, za));
|
||||||
|
else if (name == "lava") mc->particleEngine->add(new LavaParticle(level, x, y, z));
|
||||||
|
//else if (name == "splash") mc->particleEngine->add(new SplashParticle(level, x, y, z, xa, ya, za));
|
||||||
|
else if (name == "largesmoke") mc->particleEngine->add(new SmokeParticle(level, x, y, z, xa, ya, za, 2.5f));
|
||||||
|
else if (name == "reddust") mc->particleEngine->add(new RedDustParticle(level, x, y, z, xa, ya, za));
|
||||||
|
else if (name == "iconcrack") mc->particleEngine->add(new BreakingItemParticle(level, x, y, z, xa, ya, za, Item::items[data]));
|
||||||
|
else if (name == "snowballpoof") mc->particleEngine->add(new BreakingItemParticle(level, x, y, z, Item::snowBall));
|
||||||
|
//else if (name == "snowballpoof") mc->particleEngine->add(new BreakingItemParticle(level, x, y, z, Item::snowBall));
|
||||||
|
//else if (name == "slime") mc->particleEngine->add(new BreakingItemParticle(level, x, y, z, Item::slimeBall));
|
||||||
|
//else if (name == "heart") mc->particleEngine->add(new HeartParticle(level, x, y, z, xa, ya, za));
|
||||||
|
|
||||||
if (name == "bubble") mc->particleEngine->add(new BubbleParticle(level, x, y, z, xa, ya, za));
|
//sw.stop();
|
||||||
else if (name == "crit") mc->particleEngine->add(new CritParticle2(level, x, y, z, xa, ya, za));
|
//sw.printEvery(50, "add-particle-string");
|
||||||
else if (name == "smoke") mc->particleEngine->add(new SmokeParticle(level, x, y, z, xa, ya, za));
|
}
|
||||||
//else if (name == "note") mc->particleEngine->add(new NoteParticle(level, x, y, z, xa, ya, za));
|
|
||||||
else if (name == "explode") mc->particleEngine->add(new ExplodeParticle(level, x, y, z, xa, ya, za));
|
|
||||||
else if (name == "flame") mc->particleEngine->add(new FlameParticle(level, x, y, z, xa, ya, za));
|
|
||||||
else if (name == "lava") mc->particleEngine->add(new LavaParticle(level, x, y, z));
|
|
||||||
//else if (name == "splash") mc->particleEngine->add(new SplashParticle(level, x, y, z, xa, ya, za));
|
|
||||||
else if (name == "largesmoke") mc->particleEngine->add(new SmokeParticle(level, x, y, z, xa, ya, za, 2.5f));
|
|
||||||
else if (name == "reddust") mc->particleEngine->add(new RedDustParticle(level, x, y, z, xa, ya, za));
|
|
||||||
else if (name == "iconcrack") mc->particleEngine->add(new BreakingItemParticle(level, x, y, z, xa, ya, za, Item::items[data]));
|
|
||||||
else if (name == "snowballpoof") mc->particleEngine->add(new BreakingItemParticle(level, x, y, z, Item::snowBall));
|
|
||||||
//else if (name == "snowballpoof") mc->particleEngine->add(new BreakingItemParticle(level, x, y, z, Item::snowBall));
|
|
||||||
//else if (name == "slime") mc->particleEngine->add(new BreakingItemParticle(level, x, y, z, Item::slimeBall));
|
|
||||||
//else if (name == "heart") mc->particleEngine->add(new HeartParticle(level, x, y, z, xa, ya, za));
|
|
||||||
|
|
||||||
//sw.stop();
|
|
||||||
//sw.printEvery(50, "add-particle-string");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -3,5 +3,8 @@
|
|||||||
#include <client/Minecraft.h>
|
#include <client/Minecraft.h>
|
||||||
|
|
||||||
bool Command::isPlayerOp(Minecraft& mc, Player& player) {
|
bool Command::isPlayerOp(Minecraft& mc, Player& player) {
|
||||||
return mc.level->ops.find(player.name) != mc.level->ops.end();
|
std::string nicknameLower = player.name;
|
||||||
|
std::transform(nicknameLower.begin(), nicknameLower.end(), nicknameLower.begin(), ::tolower);
|
||||||
|
|
||||||
|
return mc.level->ops.find(nicknameLower) != mc.level->ops.end();
|
||||||
}
|
}
|
||||||
52
src/commands/CommandBan.cpp
Normal file
52
src/commands/CommandBan.cpp
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#include "CommandBan.hpp"
|
||||||
|
#include "commands/Command.hpp"
|
||||||
|
#include "network/RakNetInstance.h"
|
||||||
|
#include "raknet/RakPeerInterface.h"
|
||||||
|
#include "world/level/Level.h"
|
||||||
|
#include <algorithm>
|
||||||
|
#include <client/Minecraft.h>
|
||||||
|
|
||||||
|
CommandBan::CommandBan() : Command("ban") {}
|
||||||
|
|
||||||
|
std::string CommandBan::execute(Minecraft& mc, Player& player, const std::vector<std::string>& args) {
|
||||||
|
if (!isPlayerOp(mc, player)) {
|
||||||
|
return "You aren't enough priveleged to run this command";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.empty()) {
|
||||||
|
return help(mc);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string nicknameLower = args[0];
|
||||||
|
std::transform(nicknameLower.begin(), nicknameLower.end(), nicknameLower.begin(), ::tolower);
|
||||||
|
|
||||||
|
auto it = std::find_if(mc.level->players.begin(), mc.level->players.end(), [args, nicknameLower] (auto& it) -> bool {
|
||||||
|
std::string lower = it->name;
|
||||||
|
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
|
||||||
|
|
||||||
|
return lower == nicknameLower;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (*it == (Player*)mc.player) {
|
||||||
|
return "ban: you can't ban urself lol";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (it != mc.level->players.end()) {
|
||||||
|
mc.level->removePlayer(*it);
|
||||||
|
(*it)->remove();
|
||||||
|
mc.raknetInstance->getPeer()->CloseConnection((*it)->owner, true);
|
||||||
|
} else {
|
||||||
|
for (auto& banned : mc.level->bannedPpl) {
|
||||||
|
if (nicknameLower == banned) {
|
||||||
|
return args[0] + "already banned!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mc.level->bannedPpl.insert(nicknameLower);
|
||||||
|
return "ban: successfully banned player " + args[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CommandBan::help(Minecraft& mc) {
|
||||||
|
return "Usage: /ban <player>";
|
||||||
|
}
|
||||||
9
src/commands/CommandBan.hpp
Normal file
9
src/commands/CommandBan.hpp
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include "Command.hpp"
|
||||||
|
|
||||||
|
class CommandBan : public Command {
|
||||||
|
public:
|
||||||
|
CommandBan();
|
||||||
|
|
||||||
|
std::string execute(Minecraft& mc, Player& player, const std::vector<std::string>& args);
|
||||||
|
std::string help(Minecraft& mc);
|
||||||
|
};
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
#include "CommandKick.hpp"
|
#include "CommandKick.hpp"
|
||||||
#include "commands/Command.hpp"
|
#include "commands/Command.hpp"
|
||||||
#include "network/RakNetInstance.h"
|
#include "network/RakNetInstance.h"
|
||||||
#include "raknet/RakPeer.h"
|
#include "raknet/RakPeerInterface.h"
|
||||||
#include "world/level/Level.h"
|
#include "world/level/Level.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <client/Minecraft.h>
|
#include <client/Minecraft.h>
|
||||||
|
|
||||||
|
|
||||||
CommandKick::CommandKick() : Command("kick") {}
|
CommandKick::CommandKick() : Command("kick") {}
|
||||||
|
|
||||||
std::string CommandKick::execute(Minecraft& mc, Player& player, const std::vector<std::string>& args) {
|
std::string CommandKick::execute(Minecraft& mc, Player& player, const std::vector<std::string>& args) {
|
||||||
@@ -18,8 +17,14 @@ std::string CommandKick::execute(Minecraft& mc, Player& player, const std::vecto
|
|||||||
return help(mc);
|
return help(mc);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it = std::find_if(mc.level->players.begin(), mc.level->players.end(), [args] (auto& it) -> bool {
|
std::string nicknameLower = args[0];
|
||||||
return it->name == args[0];
|
std::transform(nicknameLower.begin(), nicknameLower.end(), nicknameLower.begin(), ::tolower);
|
||||||
|
|
||||||
|
auto it = std::find_if(mc.level->players.begin(), mc.level->players.end(), [args, nicknameLower] (auto& it) -> bool {
|
||||||
|
std::string lower = it->name;
|
||||||
|
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
|
||||||
|
|
||||||
|
return lower == nicknameLower;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (it == mc.level->players.end()) {
|
if (it == mc.level->players.end()) {
|
||||||
@@ -33,7 +38,7 @@ std::string CommandKick::execute(Minecraft& mc, Player& player, const std::vecto
|
|||||||
mc.level->removePlayer(*it);
|
mc.level->removePlayer(*it);
|
||||||
(*it)->remove();
|
(*it)->remove();
|
||||||
mc.raknetInstance->getPeer()->CloseConnection((*it)->owner, true);
|
mc.raknetInstance->getPeer()->CloseConnection((*it)->owner, true);
|
||||||
mc.addMessage("kick: successfully kicked player " + args[0]);
|
return "kick: successfully kicked player " + args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string CommandKick::help(Minecraft& mc) {
|
std::string CommandKick::help(Minecraft& mc) {
|
||||||
|
|||||||
@@ -7,12 +7,11 @@
|
|||||||
#include "commands/CommandHelp.hpp"
|
#include "commands/CommandHelp.hpp"
|
||||||
#include "commands/CommandKick.hpp"
|
#include "commands/CommandKick.hpp"
|
||||||
#include "commands/CommandOp.hpp"
|
#include "commands/CommandOp.hpp"
|
||||||
|
#include "commands/CommandBan.hpp"
|
||||||
#include "network/packet/ChatPacket.h"
|
#include "network/packet/ChatPacket.h"
|
||||||
#include "network/RakNetInstance.h"
|
#include "network/RakNetInstance.h"
|
||||||
#include "world/level/Level.h"
|
#include "world/level/Level.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CommandManager::CommandManager() {
|
CommandManager::CommandManager() {
|
||||||
registerAllCommands();
|
registerAllCommands();
|
||||||
}
|
}
|
||||||
@@ -21,6 +20,7 @@ void CommandManager::registerAllCommands() {
|
|||||||
m_commands.push_back(new CommandHelp());
|
m_commands.push_back(new CommandHelp());
|
||||||
m_commands.push_back(new CommandKick());
|
m_commands.push_back(new CommandKick());
|
||||||
m_commands.push_back(new CommandOp());
|
m_commands.push_back(new CommandOp());
|
||||||
|
m_commands.push_back(new CommandBan());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> CommandManager::getListAllCommands() {
|
std::vector<std::string> CommandManager::getListAllCommands() {
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
#include "CommandOp.hpp"
|
#include "CommandOp.hpp"
|
||||||
#include "commands/Command.hpp"
|
#include "commands/Command.hpp"
|
||||||
#include "network/RakNetInstance.h"
|
|
||||||
#include "raknet/RakPeer.h"
|
|
||||||
#include "world/level/Level.h"
|
#include "world/level/Level.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <client/Minecraft.h>
|
#include <client/Minecraft.h>
|
||||||
|
|
||||||
|
|
||||||
CommandOp::CommandOp() : Command("op") {}
|
CommandOp::CommandOp() : Command("op") {}
|
||||||
|
|
||||||
std::string CommandOp::execute(Minecraft& mc, Player& player, const std::vector<std::string>& args) {
|
std::string CommandOp::execute(Minecraft& mc, Player& player, const std::vector<std::string>& args) {
|
||||||
@@ -18,15 +15,14 @@ std::string CommandOp::execute(Minecraft& mc, Player& player, const std::vector<
|
|||||||
return help(mc);
|
return help(mc);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it = std::find_if(mc.level->players.begin(), mc.level->players.end(), [args] (auto& it) -> bool {
|
std::string nicknameLower = args[0];
|
||||||
return it->name == args[0];
|
std::transform(nicknameLower.begin(), nicknameLower.end(), nicknameLower.begin(), ::tolower);
|
||||||
});
|
|
||||||
|
if (mc.level->ops.find(nicknameLower) != mc.level->ops.end()) {
|
||||||
if (mc.level->ops.find(args[0]) != mc.level->ops.end()) {
|
|
||||||
return "op: player " + args[0] + " already opped";
|
return "op: player " + args[0] + " already opped";
|
||||||
}
|
}
|
||||||
|
|
||||||
mc.level->ops.emplace((*it)->name);
|
mc.level->ops.emplace(nicknameLower);
|
||||||
return "op: successfully opped player " + args[0];
|
return "op: successfully opped player " + args[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,20 @@
|
|||||||
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "NinecraftApp.h"
|
#include "NinecraftApp.h"
|
||||||
#include "AppPlatform.h"
|
#include "AppPlatform.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#ifdef __linux__
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "world/level/LevelSettings.h"
|
#include "world/level/LevelSettings.h"
|
||||||
#include "world/level/Level.h"
|
#include "world/level/Level.h"
|
||||||
#include "server/ArgumentsSettings.h"
|
#include "server/ArgumentsSettings.h"
|
||||||
#include "platform/time.h"
|
#include "platform/time.h"
|
||||||
#include "SharedConstants.h"
|
#include "SharedConstants.h"
|
||||||
|
#include "world/level/LevelConstants.h"
|
||||||
|
|
||||||
#define MAIN_CLASS NinecraftApp
|
#define MAIN_CLASS NinecraftApp
|
||||||
static App* g_app = 0;
|
static App* g_app = 0;
|
||||||
@@ -27,45 +31,175 @@ void signal_callback_handler(int signum) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int numArguments, char* pszArgs[]) {
|
std::string findStringInConfig(std::string line, std::string config) {
|
||||||
ArgumentsSettings aSettings(numArguments, pszArgs);
|
auto valuePos = config.find(line);
|
||||||
if(aSettings.getShowHelp()) {
|
|
||||||
// TODO: Map with args and print it with std::cout and for loop
|
|
||||||
// TODO: World size setting
|
|
||||||
|
|
||||||
ArgumentsSettings defaultSettings(0, NULL);
|
if (line.empty()) {
|
||||||
|
throw std::runtime_error("Key cannot be empty");
|
||||||
|
}
|
||||||
|
|
||||||
printf("Minecraft Pockect Edition Server %s\n", Common::getGameVersionString("").c_str());
|
if (valuePos == std::string::npos) {
|
||||||
printf("-------------------------------------------------------\n");
|
throw std::runtime_error("Cannot find value");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string valueStr = "";
|
||||||
|
|
||||||
printf("--cachepath - Path to where the server can store temp stuff (not sure if this is used) [default: \"%s\"]\n", defaultSettings.getCachePath().c_str());
|
valuePos += 1 + line.size();
|
||||||
printf("--externalpath - The path to the place where the server should store the levels. [default: \"%s\"]\n", defaultSettings.getExternalPath().c_str());
|
|
||||||
printf("--levelname - The name of the server [default: \"%s\"]\n", defaultSettings.getLevelName().c_str());
|
|
||||||
printf("--gamemode - The name of the gamemode [default: \"%s\"]\n", defaultSettings.getGamemode().c_str());
|
|
||||||
printf("--leveldir - The name of the server [default: \"%s\"]\n", defaultSettings.getLevelDir().c_str());
|
|
||||||
printf("--help - Shows this message.\n");
|
|
||||||
printf("--port - The port to run the server on. [default: %d]\n", defaultSettings.getPort());
|
|
||||||
printf("--serverkey - The key that the server should use for API calls. [default: \"%s\"]\n", defaultSettings.getServerKey().c_str());
|
|
||||||
|
|
||||||
printf("-------------------------------------------------------\n");
|
while (true) {
|
||||||
|
auto sym = config.at(valuePos);
|
||||||
|
|
||||||
return 0;
|
if (sym == '\n') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (valuePos == config.size()) {
|
||||||
|
throw std::runtime_error("Cannot find end of the line");
|
||||||
|
}
|
||||||
|
|
||||||
|
valueStr += sym;
|
||||||
|
valuePos++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return valueStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int numArguments, char* pszArgs[]) {
|
||||||
|
std::ifstream serverProperties("server.properties");
|
||||||
|
|
||||||
|
int port = 0;
|
||||||
|
int gamemode = 0;
|
||||||
|
int worldSize = 0;
|
||||||
|
|
||||||
|
std::string levelDir = "";
|
||||||
|
std::string cachePath = "";
|
||||||
|
std::string externalPath = "";
|
||||||
|
std::string levelName = "";
|
||||||
|
|
||||||
|
if (serverProperties.is_open()) {
|
||||||
|
std::string propString;
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
while (std::getline(serverProperties, line)) {
|
||||||
|
propString += line;
|
||||||
|
propString += "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (propString.empty()) {
|
||||||
|
throw std::runtime_error("Config cannot be empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
port = std::stoi(findStringInConfig("port", propString));
|
||||||
|
worldSize = std::stoi(findStringInConfig("world-size", propString));
|
||||||
|
|
||||||
|
if (worldSize < 16 || worldSize > 32) {
|
||||||
|
throw std::runtime_error("Incorrect world size.");
|
||||||
|
}
|
||||||
|
|
||||||
|
LevelConstants::CHUNK_CACHE_WIDTH = worldSize;
|
||||||
|
LevelConstants::LEVEL_WIDTH = LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_WIDTH;
|
||||||
|
LevelConstants::LEVEL_DEPTH = LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_DEPTH;
|
||||||
|
|
||||||
|
cachePath = findStringInConfig("level-cachepath", propString);
|
||||||
|
externalPath = findStringInConfig("level-externalpath", propString);
|
||||||
|
levelName = findStringInConfig("level-name", propString);
|
||||||
|
levelDir = findStringInConfig("level-dir", propString);
|
||||||
|
|
||||||
|
std::string gamemodeStr = findStringInConfig("gamemode", propString);
|
||||||
|
|
||||||
|
if (gamemodeStr == "survival") {
|
||||||
|
gamemode = GameType::Survival;
|
||||||
|
} else if (gamemodeStr == "creative") {
|
||||||
|
gamemode = GameType::Creative;
|
||||||
|
} else {
|
||||||
|
gamemode = GameType::Survival;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%d %s %s %d %d\n", port, cachePath.c_str(), externalPath.c_str(), gamemode, LevelConstants::CHUNK_CACHE_WIDTH);
|
||||||
|
} else {
|
||||||
|
std::ofstream defaultProperties("server.properties");
|
||||||
|
|
||||||
|
if (defaultProperties.is_open()) {
|
||||||
|
ArgumentsSettings defaultSettings(0, NULL);
|
||||||
|
|
||||||
|
std::stringstream buffer;
|
||||||
|
|
||||||
|
buffer << "// MCPE Server properties" << std::endl;
|
||||||
|
buffer << "port=" << defaultSettings.getPort() << std::endl;
|
||||||
|
buffer << "level-dir=" << defaultSettings.getLevelDir() << std::endl;
|
||||||
|
buffer << "level-cachepath=" << defaultSettings.getCachePath() << std::endl;
|
||||||
|
buffer << "level-externalpath=" << defaultSettings.getExternalPath() << std::endl;
|
||||||
|
buffer << "gamemode=survival" << std::endl;
|
||||||
|
buffer << "level-name=" << defaultSettings.getLevelName() << std::endl;
|
||||||
|
buffer << "world-size=16" << std::endl;
|
||||||
|
|
||||||
|
defaultProperties << buffer.str();
|
||||||
|
|
||||||
|
printf("%s \n", buffer.str().c_str());
|
||||||
|
|
||||||
|
printf("Edit a config file first!\n");
|
||||||
|
|
||||||
|
defaultProperties.close();
|
||||||
|
exit(0);
|
||||||
|
} else {
|
||||||
|
throw std::runtime_error("Cannot create default config.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
printf("Level Name: %s\n", aSettings.getLevelName().c_str());
|
|
||||||
|
printf("Level Name: %s\n", levelName.c_str());
|
||||||
|
|
||||||
AppContext appContext;
|
AppContext appContext;
|
||||||
appContext.platform = new AppPlatform();
|
appContext.platform = new AppPlatform();
|
||||||
App* app = new MAIN_CLASS();
|
App* app = new MAIN_CLASS();
|
||||||
signal(SIGINT, signal_callback_handler);
|
signal(SIGINT, signal_callback_handler);
|
||||||
g_app = app;
|
g_app = app;
|
||||||
((MAIN_CLASS*)g_app)->externalStoragePath = aSettings.getExternalPath();
|
((MAIN_CLASS*)g_app)->externalStoragePath = externalPath;
|
||||||
((MAIN_CLASS*)g_app)->externalCacheStoragePath = aSettings.getCachePath();
|
((MAIN_CLASS*)g_app)->externalCacheStoragePath = cachePath;
|
||||||
|
|
||||||
g_app->init(appContext);
|
g_app->init(appContext);
|
||||||
LevelSettings settings(getEpochTimeS(), GameType::Creative);
|
LevelSettings settings(getEpochTimeS(), gamemode);
|
||||||
float startTime = getTimeS();
|
float startTime = getTimeS();
|
||||||
((MAIN_CLASS*)g_app)->selectLevel(aSettings.getLevelDir(), aSettings.getLevelName(), settings);
|
((MAIN_CLASS*)g_app)->selectLevel(levelDir, levelName, settings);
|
||||||
((MAIN_CLASS*)g_app)->hostMultiplayer(aSettings.getPort());
|
((MAIN_CLASS*)g_app)->hostMultiplayer(port);
|
||||||
|
|
||||||
|
// Reading ops
|
||||||
|
std::ifstream ops("ops.txt");
|
||||||
|
|
||||||
|
if (ops.is_open()) {
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
while (std::getline(ops, line)) {
|
||||||
|
if (!line.empty()) {
|
||||||
|
((MAIN_CLASS*)g_app)->level->ops.insert(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::ofstream opsDefault("ops.txt");
|
||||||
|
|
||||||
|
if (!opsDefault.is_open()) {
|
||||||
|
throw std::runtime_error("Cannot create ops list.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reading banned ppl
|
||||||
|
std::ifstream banned("banned-players.txt");
|
||||||
|
|
||||||
|
if (banned.is_open()) {
|
||||||
|
std::string line;
|
||||||
|
|
||||||
|
while (std::getline(banned, line)) {
|
||||||
|
if (!line.empty()) {
|
||||||
|
((MAIN_CLASS*)g_app)->level->bannedPpl.insert(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::ofstream bannedPpl("banned-players.txt");
|
||||||
|
|
||||||
|
if (!bannedPpl.is_open()) {
|
||||||
|
throw std::runtime_error("Cannot create banned players list.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << "Level has been generated in " << getTimeS() - startTime << std::endl;
|
std::cout << "Level has been generated in " << getTimeS() - startTime << std::endl;
|
||||||
((MAIN_CLASS*)g_app)->level->saveLevelData();
|
((MAIN_CLASS*)g_app)->level->saveLevelData();
|
||||||
@@ -76,7 +210,31 @@ int main(int numArguments, char* pszArgs[]) {
|
|||||||
//pthread_yield();
|
//pthread_yield();
|
||||||
sleepMs(20);
|
sleepMs(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ofstream opsWrite("ops.txt");
|
||||||
|
|
||||||
|
if (opsWrite.is_open()) {
|
||||||
|
for (auto& op : ((MAIN_CLASS*)g_app)->level->ops) {
|
||||||
|
opsWrite << op << std::endl;
|
||||||
|
}
|
||||||
|
opsWrite.close();
|
||||||
|
} else {
|
||||||
|
throw std::runtime_error("Cannot open ops list.");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ofstream bannedWrite("banned-players.txt");
|
||||||
|
|
||||||
|
if (bannedWrite.is_open()) {
|
||||||
|
for (auto& banned : ((MAIN_CLASS*)g_app)->level->bannedPpl) {
|
||||||
|
bannedWrite << banned << std::endl;
|
||||||
|
}
|
||||||
|
bannedWrite.close();
|
||||||
|
} else {
|
||||||
|
throw std::runtime_error("Cannot open banned players list.");
|
||||||
|
}
|
||||||
|
|
||||||
((MAIN_CLASS*)g_app)->level->saveLevelData();
|
((MAIN_CLASS*)g_app)->level->saveLevelData();
|
||||||
|
|
||||||
delete app;
|
delete app;
|
||||||
appContext.platform->finish();
|
appContext.platform->finish();
|
||||||
delete appContext.platform;
|
delete appContext.platform;
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
#include "../client/Minecraft.h"
|
#include "../client/Minecraft.h"
|
||||||
#include "../client/gamemode/GameMode.h"
|
#include "../client/gamemode/GameMode.h"
|
||||||
#include "world/item/ItemInstance.h"
|
#include "world/item/ItemInstance.h"
|
||||||
|
#include "world/level/LevelConstants.h"
|
||||||
|
#include <cstddef>
|
||||||
#ifndef STANDALONE_SERVER
|
#ifndef STANDALONE_SERVER
|
||||||
#include "../client/gui/screens/DisconnectionScreen.h"
|
#include "../client/gui/screens/DisconnectionScreen.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -44,6 +46,9 @@ ClientSideNetworkHandler::ClientSideNetworkHandler(Minecraft* minecraft, IRakNet
|
|||||||
requestNextChunkPosition(0),
|
requestNextChunkPosition(0),
|
||||||
requestNextChunkIndex(0)
|
requestNextChunkIndex(0)
|
||||||
{
|
{
|
||||||
|
NumRequestChunks = LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_CACHE_WIDTH;
|
||||||
|
requestNextChunkIndexList.resize(NumRequestChunks);
|
||||||
|
chunksLoaded.resize(NumRequestChunks);
|
||||||
rakPeer = raknetInstance->getPeer();
|
rakPeer = raknetInstance->getPeer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +66,7 @@ void ClientSideNetworkHandler::requestNextChunk()
|
|||||||
|
|
||||||
//LOGI("requesting chunks @ (%d, %d)\n", chunk.x, chunk.y);
|
//LOGI("requesting chunks @ (%d, %d)\n", chunk.x, chunk.y);
|
||||||
|
|
||||||
//raknetInstance->send(new RequestChunkPacket(requestNextChunkPosition % CHUNK_CACHE_WIDTH, requestNextChunkPosition / CHUNK_CACHE_WIDTH));
|
//raknetInstance->send(new RequestChunkPacket(requestNextChunkPosition % LevelConstants::CHUNK_CACHE_WIDTH, requestNextChunkPosition / LevelConstants::CHUNK_CACHE_WIDTH));
|
||||||
requestNextChunkIndex++;
|
requestNextChunkIndex++;
|
||||||
requestNextChunkPosition++;
|
requestNextChunkPosition++;
|
||||||
}
|
}
|
||||||
@@ -69,16 +74,16 @@ void ClientSideNetworkHandler::requestNextChunk()
|
|||||||
|
|
||||||
bool ClientSideNetworkHandler::areAllChunksLoaded()
|
bool ClientSideNetworkHandler::areAllChunksLoaded()
|
||||||
{
|
{
|
||||||
return (requestNextChunkPosition >= (CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH));
|
return (requestNextChunkPosition >= (LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_CACHE_WIDTH));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ClientSideNetworkHandler::isChunkLoaded(int x, int z)
|
bool ClientSideNetworkHandler::isChunkLoaded(int x, int z)
|
||||||
{
|
{
|
||||||
if (x < 0 || x >= CHUNK_CACHE_WIDTH || z < 0 || z >= CHUNK_CACHE_WIDTH) {
|
if (x < 0 || x >= LevelConstants::CHUNK_CACHE_WIDTH || z < 0 || z >= LevelConstants::CHUNK_CACHE_WIDTH) {
|
||||||
LOGE("Error: Tried to request chunk (%d, %d)\n", x, z);
|
LOGE("Error: Tried to request chunk (%d, %d)\n", x, z);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return chunksLoaded[x * CHUNK_CACHE_WIDTH + z];
|
return chunksLoaded[x * LevelConstants::CHUNK_CACHE_WIDTH + z];
|
||||||
//return areAllChunksLoaded();
|
//return areAllChunksLoaded();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,6 +104,10 @@ void ClientSideNetworkHandler::onUnableToConnect()
|
|||||||
|
|
||||||
void ClientSideNetworkHandler::onDisconnect(const RakNet::RakNetGUID& guid)
|
void ClientSideNetworkHandler::onDisconnect(const RakNet::RakNetGUID& guid)
|
||||||
{
|
{
|
||||||
|
LevelConstants::CHUNK_CACHE_WIDTH = 16;
|
||||||
|
LevelConstants::LEVEL_WIDTH = LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_WIDTH;
|
||||||
|
LevelConstants::LEVEL_DEPTH = LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_DEPTH;
|
||||||
|
|
||||||
// TODO: Good disconnecting
|
// TODO: Good disconnecting
|
||||||
LOGI("onDisconnect\n");
|
LOGI("onDisconnect\n");
|
||||||
if (level)
|
if (level)
|
||||||
@@ -111,9 +120,12 @@ void ClientSideNetworkHandler::onDisconnect(const RakNet::RakNetGUID& guid)
|
|||||||
level->removeEntity(p);
|
level->removeEntity(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
minecraft->setLevel(NULL);
|
||||||
#ifndef STANDALONE_SERVER
|
#ifndef STANDALONE_SERVER
|
||||||
minecraft->gui.addMessage("Disconnected from server");
|
minecraft->gui.addMessage("Disconnected from server");
|
||||||
|
// TODO: screen with error
|
||||||
|
minecraft->screenChooser.setScreen(SCREEN_STARTMENU);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,6 +151,12 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, LoginSta
|
|||||||
LOGI("Disconnect! Nickname is taken!\n");
|
LOGI("Disconnect! Nickname is taken!\n");
|
||||||
#ifndef STANDALONE_SERVER
|
#ifndef STANDALONE_SERVER
|
||||||
minecraft->setScreen(new DisconnectionScreen("Could not connect: Nickname is taken!"));
|
minecraft->setScreen(new DisconnectionScreen("Could not connect: Nickname is taken!"));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
if (packet->status == LoginStatus::Failed_Banned) {
|
||||||
|
LOGI("Disconnect! You're banned from this server!\n");
|
||||||
|
#ifndef STANDALONE_SERVER
|
||||||
|
minecraft->setScreen(new DisconnectionScreen("Could not connect: You're banned from this server!"));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -155,6 +173,19 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, StartGam
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// @todo @note i think its trash
|
||||||
|
// we can put it directly to selectLevel?
|
||||||
|
if (packet->chunkCacheWidth != 0) {
|
||||||
|
printf("lol \n");
|
||||||
|
LevelConstants::CHUNK_CACHE_WIDTH = packet->chunkCacheWidth;
|
||||||
|
LevelConstants::LEVEL_WIDTH = LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_WIDTH;
|
||||||
|
LevelConstants::LEVEL_DEPTH = LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_DEPTH;
|
||||||
|
LevelChunk::ChunkBlockCount = LevelConstants::CHUNK_BLOCK_COUNT;
|
||||||
|
}
|
||||||
|
NumRequestChunks = LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_CACHE_WIDTH;
|
||||||
|
requestNextChunkIndexList.resize(NumRequestChunks);
|
||||||
|
chunksLoaded.resize(NumRequestChunks);
|
||||||
|
|
||||||
const std::string& levelId = LevelStorageSource::TempLevelId;
|
const std::string& levelId = LevelStorageSource::TempLevelId;
|
||||||
LevelStorageSource* storageSource = minecraft->getLevelSource();
|
LevelStorageSource* storageSource = minecraft->getLevelSource();
|
||||||
storageSource->deleteLevel(levelId);
|
storageSource->deleteLevel(levelId);
|
||||||
@@ -333,7 +364,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, RemoveEn
|
|||||||
if (!level) return;
|
if (!level) return;
|
||||||
|
|
||||||
Entity* entity = level->getEntity(packet->entityId);
|
Entity* entity = level->getEntity(packet->entityId);
|
||||||
LOGI("RemoveEntityPacket %p %p, %d\n", entity, minecraft->player, entity?(int)(entity->isPlayer()): -1);
|
// LOGI("RemoveEntityPacket %p %p, %d\n", entity, minecraft->player, entity?(int)(entity->isPlayer()): -1);
|
||||||
if (!entity) return;
|
if (!entity) return;
|
||||||
|
|
||||||
level->removeEntity(entity);
|
level->removeEntity(entity);
|
||||||
@@ -533,19 +564,19 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, ChunkDat
|
|||||||
//unsigned char* blockIds = chunk->getBlockData();
|
//unsigned char* blockIds = chunk->getBlockData();
|
||||||
DataLayer& blockData = chunk->data;
|
DataLayer& blockData = chunk->data;
|
||||||
|
|
||||||
const int setSize = LEVEL_HEIGHT / 8;
|
const int setSize = LevelConstants::LEVEL_HEIGHT / 8;
|
||||||
const int setShift = 4; // power of LEVEL_HEIGHT / 8
|
const int setShift = 4; // power of LevelConstants::LEVEL_HEIGHT / 8
|
||||||
|
|
||||||
bool recalcHeight = false;
|
bool recalcHeight = false;
|
||||||
|
|
||||||
int x0 = 16, x1 = 0, z0 = 16, z1 = 0, y0 = LEVEL_HEIGHT, y1 = 0;
|
int x0 = 16, x1 = 0, z0 = 16, z1 = 0, y0 = LevelConstants::LEVEL_HEIGHT, y1 = 0;
|
||||||
int rx = packet->x << 4;
|
int rx = packet->x << 4;
|
||||||
int rz = packet->z << 4;
|
int rz = packet->z << 4;
|
||||||
|
|
||||||
unsigned char readBlockBuffer[setSize];
|
unsigned char* readBlockBuffer = new unsigned char[setSize];
|
||||||
unsigned char readDataBuffer[setSize / 2];
|
unsigned char* readDataBuffer = new unsigned char[setSize / 2];
|
||||||
|
|
||||||
for (int i = 0; i < CHUNK_COLUMNS; i++)
|
for (int i = 0; i < LevelConstants::CHUNK_COLUMNS; i++)
|
||||||
{
|
{
|
||||||
unsigned char updateBits = 0;
|
unsigned char updateBits = 0;
|
||||||
packet->chunkData.Read(updateBits);
|
packet->chunkData.Read(updateBits);
|
||||||
@@ -554,8 +585,8 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, ChunkDat
|
|||||||
{
|
{
|
||||||
recalcHeight = true;
|
recalcHeight = true;
|
||||||
|
|
||||||
int colX = (i % CHUNK_WIDTH);
|
int colX = (i % LevelConstants::CHUNK_WIDTH);
|
||||||
int colZ = (i / CHUNK_WIDTH);
|
int colZ = (i / LevelConstants::CHUNK_WIDTH);
|
||||||
int colDataPosition = colX << 11 | colZ << 7;
|
int colDataPosition = colX << 11 | colZ << 7;
|
||||||
|
|
||||||
for (int set = 0; set < 8; set++)
|
for (int set = 0; set < 8; set++)
|
||||||
@@ -589,30 +620,33 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, ChunkDat
|
|||||||
{
|
{
|
||||||
y0 = ((1 << set) << setShift);
|
y0 = ((1 << set) << setShift);
|
||||||
}
|
}
|
||||||
if (((1 << set) << setShift) + (LEVEL_HEIGHT / 8) - 1 > y1)
|
if (((1 << set) << setShift) + (LevelConstants::LEVEL_HEIGHT / 8) - 1 > y1)
|
||||||
{
|
{
|
||||||
y1 = ((1 << set) << setShift) + (LEVEL_HEIGHT / 8) - 1;
|
y1 = ((1 << set) << setShift) + (LevelConstants::LEVEL_HEIGHT / 8) - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((i % CHUNK_WIDTH) < x0)
|
if ((i % LevelConstants::CHUNK_WIDTH) < x0)
|
||||||
{
|
{
|
||||||
x0 = (i % CHUNK_WIDTH);
|
x0 = (i % LevelConstants::CHUNK_WIDTH);
|
||||||
}
|
}
|
||||||
if ((i % CHUNK_WIDTH) > x1)
|
if ((i % LevelConstants::CHUNK_WIDTH) > x1)
|
||||||
{
|
{
|
||||||
x1 = (i % CHUNK_WIDTH);
|
x1 = (i % LevelConstants::CHUNK_WIDTH);
|
||||||
}
|
}
|
||||||
if ((i / CHUNK_WIDTH) < z0)
|
if ((i / LevelConstants::CHUNK_WIDTH) < z0)
|
||||||
{
|
{
|
||||||
z0 = (i / CHUNK_WIDTH);
|
z0 = (i / LevelConstants::CHUNK_WIDTH);
|
||||||
}
|
}
|
||||||
if ((i / CHUNK_WIDTH) > z1)
|
if ((i / LevelConstants::CHUNK_WIDTH) > z1)
|
||||||
{
|
{
|
||||||
z1 = (i / CHUNK_WIDTH);
|
z1 = (i / LevelConstants::CHUNK_WIDTH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete[] readBlockBuffer;
|
||||||
|
delete[] readDataBuffer;
|
||||||
|
|
||||||
if (recalcHeight)
|
if (recalcHeight)
|
||||||
{
|
{
|
||||||
// chunk->recalcHeightmap();
|
// chunk->recalcHeightmap();
|
||||||
@@ -637,7 +671,7 @@ void ClientSideNetworkHandler::handle(const RakNet::RakNetGUID& source, ChunkDat
|
|||||||
//chunk->terrainPopulated = true;
|
//chunk->terrainPopulated = true;
|
||||||
chunk->unsaved = false;
|
chunk->unsaved = false;
|
||||||
|
|
||||||
chunksLoaded[packet->x * CHUNK_CACHE_WIDTH + packet->z] = true;
|
chunksLoaded[packet->x * LevelConstants::CHUNK_CACHE_WIDTH + packet->z] = true;
|
||||||
|
|
||||||
if (areAllChunksLoaded())
|
if (areAllChunksLoaded())
|
||||||
{
|
{
|
||||||
@@ -685,18 +719,18 @@ void ClientSideNetworkHandler::arrangeRequestChunkOrder() {
|
|||||||
clearChunksLoaded();
|
clearChunksLoaded();
|
||||||
|
|
||||||
// Default sort is around center of the world
|
// Default sort is around center of the world
|
||||||
int cx = CHUNK_CACHE_WIDTH / 2;
|
int cx = LevelConstants::CHUNK_CACHE_WIDTH / 2;
|
||||||
int cz = CHUNK_CACHE_WIDTH / 2;
|
int cz = LevelConstants::CHUNK_CACHE_WIDTH / 2;
|
||||||
|
|
||||||
// If player exists, let's sort around him
|
// If player exists, let's sort around him
|
||||||
Player* p = minecraft? minecraft->player : NULL;
|
Player* p = minecraft? minecraft->player : NULL;
|
||||||
if (p) {
|
if (p) {
|
||||||
cx = Mth::floor(p->x / (float)CHUNK_WIDTH);
|
cx = Mth::floor(p->x / (float)LevelConstants::CHUNK_WIDTH);
|
||||||
cz = Mth::floor(p->z / (float)CHUNK_DEPTH);
|
cz = Mth::floor(p->z / (float)LevelConstants::CHUNK_DEPTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
_ChunkSorter sorter(cx, cz);
|
_ChunkSorter sorter(cx, cz);
|
||||||
std::sort(requestNextChunkIndexList, requestNextChunkIndexList + NumRequestChunks, sorter);
|
std::sort(requestNextChunkIndexList.begin(), requestNextChunkIndexList.end(), sorter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientSideNetworkHandler::levelGenerated(Level* level)
|
void ClientSideNetworkHandler::levelGenerated(Level* level)
|
||||||
@@ -986,8 +1020,8 @@ void ClientSideNetworkHandler::clearChunksLoaded()
|
|||||||
{
|
{
|
||||||
// Init the chunk positions
|
// Init the chunk positions
|
||||||
for (int i = 0; i < NumRequestChunks; ++i) {
|
for (int i = 0; i < NumRequestChunks; ++i) {
|
||||||
requestNextChunkIndexList[i].x = i/CHUNK_WIDTH;
|
requestNextChunkIndexList[i].x = i / LevelConstants::CHUNK_WIDTH;
|
||||||
requestNextChunkIndexList[i].y = i%CHUNK_WIDTH;
|
requestNextChunkIndexList[i].y = i % LevelConstants::CHUNK_WIDTH;
|
||||||
chunksLoaded[i] = false;
|
chunksLoaded[i] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,11 +102,11 @@ private:
|
|||||||
BlockUpdateList bufferedBlockUpdates;
|
BlockUpdateList bufferedBlockUpdates;
|
||||||
int requestNextChunkPosition;
|
int requestNextChunkPosition;
|
||||||
|
|
||||||
static const int NumRequestChunks = CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH;
|
int NumRequestChunks;
|
||||||
|
|
||||||
int requestNextChunkIndex;
|
int requestNextChunkIndex;
|
||||||
IntPair requestNextChunkIndexList[NumRequestChunks];
|
std::vector<IntPair> requestNextChunkIndexList;
|
||||||
bool chunksLoaded[NumRequestChunks];
|
std::vector<bool> chunksLoaded;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#include "util/Mth.h"
|
#include "util/Mth.h"
|
||||||
#include "util/StringUtils.h"
|
#include "util/StringUtils.h"
|
||||||
#include "world/item/ItemInstance.h"
|
#include "world/item/ItemInstance.h"
|
||||||
|
#include "world/level/LevelConstants.h"
|
||||||
#include "world/level/storage/LevelStorage.h"
|
#include "world/level/storage/LevelStorage.h"
|
||||||
#include "world/phys/Vec3.h"
|
#include "world/phys/Vec3.h"
|
||||||
#include "world/item/crafting/Recipe.h"
|
#include "world/item/crafting/Recipe.h"
|
||||||
@@ -73,11 +74,11 @@ void ServerSideNetworkHandler::tileChanged(int x, int y, int z)
|
|||||||
|
|
||||||
Packet* ServerSideNetworkHandler::getAddPacketFromEntity( Entity* entity ) {
|
Packet* ServerSideNetworkHandler::getAddPacketFromEntity( Entity* entity ) {
|
||||||
if (entity->isMob() && !entity->isPlayer()) { //@fix: This code is duplicated. See if it can be unified.
|
if (entity->isMob() && !entity->isPlayer()) { //@fix: This code is duplicated. See if it can be unified.
|
||||||
if (minecraft->player) {
|
// if (minecraft->player) {
|
||||||
// I guess this should always be true, but it crashed somewhere in this
|
// I guess this should always be true, but it crashed somewhere in this
|
||||||
// function once and I only see this one as a potential problem
|
// function once and I only see this one as a potential problem
|
||||||
return new AddMobPacket((Mob*)entity);
|
return new AddMobPacket((Mob*)entity);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
else if (entity->isPlayer()) {
|
else if (entity->isPlayer()) {
|
||||||
|
|
||||||
@@ -158,7 +159,7 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, ChatPack
|
|||||||
{
|
{
|
||||||
auto player = getPlayer(source);
|
auto player = getPlayer(source);
|
||||||
|
|
||||||
if (player == nullptr) return; // TODO maybe kick?
|
if (player == nullptr) return; // @todo maybe kick?
|
||||||
|
|
||||||
if (packet->message[0] == '/') {
|
if (packet->message[0] == '/') {
|
||||||
// This is a command
|
// This is a command
|
||||||
@@ -219,14 +220,30 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, LoginPac
|
|||||||
//
|
//
|
||||||
bool oldClient = packet->clientNetworkVersion < SharedConstants::NetworkProtocolLowestSupportedVersion;
|
bool oldClient = packet->clientNetworkVersion < SharedConstants::NetworkProtocolLowestSupportedVersion;
|
||||||
bool oldServer = packet->clientNetworkLowestSupportedVersion > SharedConstants::NetworkProtocolVersion;
|
bool oldServer = packet->clientNetworkLowestSupportedVersion > SharedConstants::NetworkProtocolVersion;
|
||||||
if (oldClient || oldServer)
|
if (oldClient || oldServer || !packet->newProto)
|
||||||
loginStatus = oldClient? LoginStatus::Failed_ClientOld : LoginStatus::Failed_ServerOld;
|
loginStatus = oldClient || !packet->newProto? LoginStatus::Failed_ClientOld : LoginStatus::Failed_ServerOld;
|
||||||
|
|
||||||
|
std::string nicknameLower = packet->clientName.C_String();
|
||||||
|
std::transform(nicknameLower.begin(), nicknameLower.end(), nicknameLower.begin(), ::tolower);
|
||||||
|
|
||||||
|
printf("%s lower \n", nicknameLower.c_str());
|
||||||
for (int i = 0; i < level->players.size(); i++) {
|
for (int i = 0; i < level->players.size(); i++) {
|
||||||
ServerPlayer* player = (ServerPlayer*) level->players.at(i);
|
ServerPlayer* player = (ServerPlayer*) level->players.at(i);
|
||||||
|
|
||||||
if (player->name == packet->clientName.C_String()) {
|
std::string clientLower = player->name;
|
||||||
|
std::transform(clientLower.begin(), clientLower.end(), clientLower.begin(), ::tolower);
|
||||||
|
|
||||||
|
// @todo to lower case
|
||||||
|
if (nicknameLower == clientLower) {
|
||||||
loginStatus = packet->newProto ? LoginStatus::Failed_TakenNickname : LoginStatus::Failed_ClientOld;
|
loginStatus = packet->newProto ? LoginStatus::Failed_TakenNickname : LoginStatus::Failed_ClientOld;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& banned : level->bannedPpl) {
|
||||||
|
if (nicknameLower == banned) {
|
||||||
|
loginStatus = packet->newProto ? LoginStatus::Failed_Banned : LoginStatus::Failed_ClientOld;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,15 +289,11 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, LoginPac
|
|||||||
level->getLevelData()->getGeneratorVersion(),
|
level->getLevelData()->getGeneratorVersion(),
|
||||||
gameType,
|
gameType,
|
||||||
newPlayer->entityId,
|
newPlayer->entityId,
|
||||||
newPlayer->x, newPlayer->y - newPlayer->heightOffset, newPlayer->z
|
newPlayer->x, newPlayer->y - newPlayer->heightOffset, newPlayer->z,
|
||||||
|
LevelConstants::CHUNK_CACHE_WIDTH
|
||||||
).write(&bitStream);
|
).write(&bitStream);
|
||||||
|
|
||||||
rakPeer->Send(&bitStream, HIGH_PRIORITY, RELIABLE_ORDERED, 0, source, false);
|
rakPeer->Send(&bitStream, HIGH_PRIORITY, RELIABLE_ORDERED, 0, source, false);
|
||||||
|
|
||||||
if (!packet->newProto) {
|
|
||||||
MessagePacket packet("You're using outdated client. Some features disabled.");
|
|
||||||
raknetInstance->send(packet);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -420,24 +433,24 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, MovePlay
|
|||||||
{
|
{
|
||||||
if (!level) return;
|
if (!level) return;
|
||||||
|
|
||||||
//LOGI("MovePlayerPacket\n");
|
LOGI("MovePlayerPacket\n");
|
||||||
if (Entity* entity = level->getEntity(packet->entityId)) {
|
if (Entity* entity = level->getEntity(packet->entityId)) {
|
||||||
ServerPlayer* player = (ServerPlayer*) getPlayer(source);
|
ServerPlayer* player = (ServerPlayer*) getPlayer(source);
|
||||||
|
|
||||||
int timeElapsed = minecraft->getTicks() - player->getLastMoveTicks();
|
// int timeElapsed = minecraft->getTicks() - player->getLastMoveTicks();
|
||||||
|
|
||||||
if (timeElapsed > 0) {
|
// if (timeElapsed > 0) {
|
||||||
float dist = player->distanceTo(packet->x, player->y, packet->z);
|
// float dist = player->distanceTo(packet->x, player->y, packet->z);
|
||||||
float speed = dist / (minecraft->getTicks() - player->getLastMoveTicks());
|
// float speed = dist / (minecraft->getTicks() - player->getLastMoveTicks());
|
||||||
player->setLastMoveTicks(minecraft->getTicks());
|
// player->setLastMoveTicks(minecraft->getTicks());
|
||||||
|
|
||||||
float maxSpeed = (minecraft->isCreativeMode()) ? 1.65f : 1.f;
|
// float maxSpeed = (minecraft->isCreativeMode()) ? 1.65f : 1.f;
|
||||||
|
|
||||||
if (speed > maxSpeed) {
|
// if (speed > maxSpeed) {
|
||||||
MovePlayerPacket refuse(player->entityId, player->x, player->y, player->z, player->xRot, player->yRot);
|
// MovePlayerPacket refuse(player->entityId, player->x, player->y, player->z, player->xRot, player->yRot);
|
||||||
return raknetInstance->send(refuse);
|
// return raknetInstance->send(refuse);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
entity->xd = entity->yd = entity->zd = 0;
|
entity->xd = entity->yd = entity->zd = 0;
|
||||||
entity->lerpTo(packet->x, packet->y, packet->z, packet->yRot, packet->xRot, 3);
|
entity->lerpTo(packet->x, packet->y, packet->z, packet->yRot, packet->xRot, 3);
|
||||||
@@ -684,12 +697,9 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, WantCrea
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for (int i = 0; i < items.size(); i++) {
|
for (int i = 0; i < items.size(); i++) {
|
||||||
// RemoveItemPacket removePacket(packet->playerId, items.at(i).count, items.at(i).getAuxValue(), items.at(i).id);
|
p->inventory->removeResource(ItemInstance(items.at(i).id, items.at(i).count, items.at(i).getAuxValue()));
|
||||||
// raknetInstance->send(source, removePacket);
|
}
|
||||||
|
|
||||||
// p->inventory->removeResource(ItemInstance(items.at(i).id, items.at(i).count, items.at(i).getAuxValue()));
|
|
||||||
// }
|
|
||||||
// TakeItemPacket itemAdd(p->entityId, wantCreate.count, wantCreate.getAuxValue(), wantCreate.id);
|
// TakeItemPacket itemAdd(p->entityId, wantCreate.count, wantCreate.getAuxValue(), wantCreate.id);
|
||||||
// raknetInstance->send(source, itemAdd);
|
// raknetInstance->send(source, itemAdd);
|
||||||
|
|
||||||
@@ -955,19 +965,17 @@ void ServerSideNetworkHandler::handle(const RakNet::RakNetGUID& source, Containe
|
|||||||
|
|
||||||
void ServerSideNetworkHandler::handle( const RakNet::RakNetGUID& source, SetHealthPacket* packet )
|
void ServerSideNetworkHandler::handle( const RakNet::RakNetGUID& source, SetHealthPacket* packet )
|
||||||
{
|
{
|
||||||
LOGI("net idi nahui\n");
|
for (unsigned int i = 0; i < level->players.size(); ++i) {
|
||||||
|
Player* p = level->players[i];
|
||||||
// for (unsigned int i = 0; i < level->players.size(); ++i) {
|
if (p->owner == source) {
|
||||||
// Player* p = level->players[i];
|
if (packet->health <= -32) {
|
||||||
// if (p->owner == source) {
|
int diff = packet->health - SetHealthPacket::HEALTH_MODIFY_OFFSET;
|
||||||
// if (packet->health <= -32) {
|
if (diff > 0) p->hurt(NULL, diff);
|
||||||
// int diff = packet->health - SetHealthPacket::HEALTH_MODIFY_OFFSET;
|
else if (diff < 0) p->heal(-diff);
|
||||||
// if (diff > 0) p->hurt(NULL, diff);
|
}
|
||||||
// else if (diff < 0) p->heal(-diff);
|
break;
|
||||||
// }
|
}
|
||||||
// break;
|
}
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerSideNetworkHandler::handle( const RakNet::RakNetGUID& source, SignUpdatePacket* packet ) {
|
void ServerSideNetworkHandler::handle( const RakNet::RakNetGUID& source, SignUpdatePacket* packet ) {
|
||||||
|
|||||||
@@ -236,9 +236,9 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s)
|
|||||||
if (x0 < 0) x0 = 0;
|
if (x0 < 0) x0 = 0;
|
||||||
if (y0 < 0) y0 = 0;
|
if (y0 < 0) y0 = 0;
|
||||||
if (z0 < 0) z0 = 0;
|
if (z0 < 0) z0 = 0;
|
||||||
if (x1 >= LEVEL_WIDTH ) x1 = LEVEL_WIDTH - 1;
|
if (x1 >= LevelConstants::LEVEL_WIDTH ) x1 = LevelConstants::LEVEL_WIDTH - 1;
|
||||||
if (y1 >= LEVEL_HEIGHT) y1 = LEVEL_HEIGHT - 1;
|
if (y1 >= LevelConstants::LEVEL_HEIGHT) y1 = LevelConstants::LEVEL_HEIGHT - 1;
|
||||||
if (z1 >= LEVEL_DEPTH ) z1 = LEVEL_DEPTH - 1;
|
if (z1 >= LevelConstants::LEVEL_DEPTH ) z1 = LevelConstants::LEVEL_DEPTH - 1;
|
||||||
|
|
||||||
for (int y = y0; y <= y1; ++y)
|
for (int y = y0; y <= y1; ++y)
|
||||||
for (int z = z0; z <= z1; ++z)
|
for (int z = z0; z <= z1; ++z)
|
||||||
@@ -456,7 +456,7 @@ std::string CommandServer::parse(ConnectedClient& client, const std::string& s)
|
|||||||
sw.start();
|
sw.start();
|
||||||
|
|
||||||
// Save a cuboid around the player
|
// Save a cuboid around the player
|
||||||
const int CSize = CHUNK_CACHE_WIDTH;
|
const int CSize = LevelConstants::CHUNK_CACHE_WIDTH;
|
||||||
int cx = (int)e->x / CSize;
|
int cx = (int)e->x / CSize;
|
||||||
int cz = (int)e->z / CSize;
|
int cz = (int)e->z / CSize;
|
||||||
|
|
||||||
@@ -504,7 +504,7 @@ bool CommandServer::handleCheckpoint(bool doRestore ) {
|
|||||||
const int cz = restorePos.z;
|
const int cz = restorePos.z;
|
||||||
const int y0 = restorePos.y;
|
const int y0 = restorePos.y;
|
||||||
const int y1 = y0 + RestoreHeight;
|
const int y1 = y0 + RestoreHeight;
|
||||||
const int CSize = CHUNK_CACHE_WIDTH;
|
const int CSize = LevelConstants::CHUNK_CACHE_WIDTH;
|
||||||
const int numChunkBytes = RestoreHeight * CSize * CSize * 20 / 8;
|
const int numChunkBytes = RestoreHeight * CSize * CSize * 20 / 8;
|
||||||
|
|
||||||
if (!restoreBuffer) {
|
if (!restoreBuffer) {
|
||||||
|
|||||||
@@ -33,18 +33,18 @@ public:
|
|||||||
unsigned char* blockIds = chunk->getBlockData();
|
unsigned char* blockIds = chunk->getBlockData();
|
||||||
DataLayer& blockData = chunk->data;
|
DataLayer& blockData = chunk->data;
|
||||||
|
|
||||||
const int setSize = LEVEL_HEIGHT / 8;
|
const int setSize = LevelConstants::LEVEL_HEIGHT / 8;
|
||||||
const int setShift = 4; // power of LEVEL_HEIGHT / 8
|
const int setShift = 4; // power of LevelConstants::LEVEL_HEIGHT / 8
|
||||||
|
|
||||||
chunkData.Reset();
|
chunkData.Reset();
|
||||||
for (int i = 0; i < CHUNK_COLUMNS; i++)
|
for (int i = 0; i < LevelConstants::CHUNK_COLUMNS; i++)
|
||||||
{
|
{
|
||||||
unsigned char updateBits = chunk->updateMap[i];
|
unsigned char updateBits = chunk->updateMap[i];
|
||||||
chunkData.Write(updateBits);
|
chunkData.Write(updateBits);
|
||||||
|
|
||||||
if (updateBits > 0)
|
if (updateBits > 0)
|
||||||
{
|
{
|
||||||
int colDataPosition = (i % CHUNK_WIDTH) << 11 | (i / CHUNK_WIDTH) << 7;
|
int colDataPosition = (i % LevelConstants::CHUNK_WIDTH) << 11 | (i / LevelConstants::CHUNK_WIDTH) << 7;
|
||||||
|
|
||||||
for (int set = 0; set < 8; set++)
|
for (int set = 0; set < 8; set++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ namespace LoginStatus {
|
|||||||
const int Failed_ClientOld = 1;
|
const int Failed_ClientOld = 1;
|
||||||
const int Failed_ServerOld = 2;
|
const int Failed_ServerOld = 2;
|
||||||
const int Failed_TakenNickname = 3;
|
const int Failed_TakenNickname = 3;
|
||||||
|
const int Failed_Banned = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoginStatusPacket : public Packet {
|
class LoginStatusPacket : public Packet {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define NET_MINECRAFT_NETWORK_PACKET__StartGamePacket_H__
|
#define NET_MINECRAFT_NETWORK_PACKET__StartGamePacket_H__
|
||||||
|
|
||||||
#include "../Packet.h"
|
#include "../Packet.h"
|
||||||
|
#include "world/level/LevelConstants.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
class StartGamePacket : public Packet
|
class StartGamePacket : public Packet
|
||||||
@@ -14,18 +15,20 @@ public:
|
|||||||
int entityId;
|
int entityId;
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|
||||||
|
int chunkCacheWidth = 0;
|
||||||
StartGamePacket()
|
StartGamePacket()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
StartGamePacket(long seed, int levelGeneratorVersion, int gameType, int entityId, float x, float y, float z)
|
StartGamePacket(long seed, int levelGeneratorVersion, int gameType, int entityId, float x, float y, float z, int chunkCacheWidth)
|
||||||
: levelSeed((int32_t)seed),
|
: levelSeed((int32_t)seed),
|
||||||
levelGeneratorVersion(levelGeneratorVersion),
|
levelGeneratorVersion(levelGeneratorVersion),
|
||||||
gameType(gameType),
|
gameType(gameType),
|
||||||
entityId(entityId),
|
entityId(entityId),
|
||||||
x(x),
|
x(x),
|
||||||
y(y),
|
y(y),
|
||||||
z(z)
|
z(z),
|
||||||
|
chunkCacheWidth(chunkCacheWidth)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,6 +43,7 @@ public:
|
|||||||
bitStream->Write(x);
|
bitStream->Write(x);
|
||||||
bitStream->Write(y);
|
bitStream->Write(y);
|
||||||
bitStream->Write(z);
|
bitStream->Write(z);
|
||||||
|
bitStream->Write(LevelConstants::CHUNK_CACHE_WIDTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
void read(RakNet::BitStream* bitStream)
|
void read(RakNet::BitStream* bitStream)
|
||||||
@@ -51,6 +55,10 @@ public:
|
|||||||
bitStream->Read(x);
|
bitStream->Read(x);
|
||||||
bitStream->Read(y);
|
bitStream->Read(y);
|
||||||
bitStream->Read(z);
|
bitStream->Read(z);
|
||||||
|
|
||||||
|
if (bitStream->GetNumberOfUnreadBits() > 0) {
|
||||||
|
bitStream->Read(chunkCacheWidth);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
|
void handle(const RakNet::RakNetGUID& source, NetEventCallback* callback)
|
||||||
|
|||||||
@@ -871,8 +871,8 @@ bool Entity::load( CompoundTag* tag )
|
|||||||
|
|
||||||
// Add a small padding if standing next to the world edges
|
// Add a small padding if standing next to the world edges
|
||||||
const float padding = bbWidth * 0.5f + 0.001f;
|
const float padding = bbWidth * 0.5f + 0.001f;
|
||||||
xx = Mth::clamp(xx, padding, (float)LEVEL_WIDTH - padding);
|
xx = Mth::clamp(xx, padding, (float)LevelConstants::LEVEL_WIDTH - padding);
|
||||||
zz = Mth::clamp(zz, padding, (float)LEVEL_DEPTH - padding);
|
zz = Mth::clamp(zz, padding, (float)LevelConstants::LEVEL_DEPTH - padding);
|
||||||
|
|
||||||
xo = xOld = x = xx;
|
xo = xOld = x = xx;
|
||||||
yo = yOld = y = yy;
|
yo = yOld = y = yy;
|
||||||
|
|||||||
@@ -29,6 +29,9 @@
|
|||||||
#include "../Difficulty.h"
|
#include "../Difficulty.h"
|
||||||
#include "../../network/packet/ExplodePacket.h"
|
#include "../../network/packet/ExplodePacket.h"
|
||||||
|
|
||||||
|
const int Level::DEPTH = LevelConstants::LEVEL_HEIGHT;
|
||||||
|
const int Level::SEA_LEVEL = Level::DEPTH / 2 - 1;
|
||||||
|
|
||||||
Level::Level(LevelStorage* levelStorage, const std::string& levelName, const LevelSettings& settings, int generatorVersion, Dimension* fixedDimension /* = NULL */)
|
Level::Level(LevelStorage* levelStorage, const std::string& levelName, const LevelSettings& settings, int generatorVersion, Dimension* fixedDimension /* = NULL */)
|
||||||
: levelStorage(levelStorage),
|
: levelStorage(levelStorage),
|
||||||
isClientSide(false),
|
isClientSide(false),
|
||||||
@@ -278,8 +281,8 @@ void Level::tickTiles() {
|
|||||||
for (int i = 0; i < pollChunkOffsetsSize; i += 2) {
|
for (int i = 0; i < pollChunkOffsetsSize; i += 2) {
|
||||||
const int xp = xx + pollChunkOffsets[i];
|
const int xp = xx + pollChunkOffsets[i];
|
||||||
const int zp = zz + pollChunkOffsets[i+1];
|
const int zp = zz + pollChunkOffsets[i+1];
|
||||||
if (xp >= 0 && xp < CHUNK_CACHE_WIDTH &&
|
if (xp >= 0 && xp < LevelConstants::CHUNK_CACHE_WIDTH &&
|
||||||
zp >= 0 && zp < CHUNK_CACHE_WIDTH)
|
zp >= 0 && zp < LevelConstants::CHUNK_CACHE_WIDTH)
|
||||||
_chunksToPoll.insert(ChunkPos(xp, zp));
|
_chunksToPoll.insert(ChunkPos(xp, zp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -428,17 +431,17 @@ bool Level::findPath(Path* path, Entity* from, int xBest, int yBest, int zBest,
|
|||||||
/*protected*/
|
/*protected*/
|
||||||
void Level::setInitialSpawn() {
|
void Level::setInitialSpawn() {
|
||||||
isFindingSpawn = true;
|
isFindingSpawn = true;
|
||||||
int xSpawn = CHUNK_CACHE_WIDTH * CHUNK_WIDTH / 2; // (Level.MAX_LEVEL_SIZE - 100) * 0;
|
int xSpawn = LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_WIDTH / 2; // (Level.MAX_LEVEL_SIZE - 100) * 0;
|
||||||
int ySpawn = 64;
|
int ySpawn = 64;
|
||||||
int zSpawn = CHUNK_CACHE_WIDTH * CHUNK_DEPTH / 2; // (Level.MAX_LEVEL_SIZE - 100) * 0;
|
int zSpawn = LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_DEPTH / 2; // (Level.MAX_LEVEL_SIZE - 100) * 0;
|
||||||
while (!dimension->isValidSpawn(xSpawn, zSpawn)) {
|
while (!dimension->isValidSpawn(xSpawn, zSpawn)) {
|
||||||
xSpawn += random.nextInt(32) - random.nextInt(32);
|
xSpawn += random.nextInt(32) - random.nextInt(32);
|
||||||
zSpawn += random.nextInt(32) - random.nextInt(32);
|
zSpawn += random.nextInt(32) - random.nextInt(32);
|
||||||
|
|
||||||
if (xSpawn < 4) xSpawn += 32;
|
if (xSpawn < 4) xSpawn += 32;
|
||||||
if (xSpawn >= LEVEL_WIDTH-4) xSpawn -= 32;
|
if (xSpawn >= LevelConstants::LEVEL_WIDTH-4) xSpawn -= 32;
|
||||||
if (zSpawn < 4) zSpawn += 32;
|
if (zSpawn < 4) zSpawn += 32;
|
||||||
if (zSpawn >= LEVEL_DEPTH-4) zSpawn -= 32;
|
if (zSpawn >= LevelConstants::LEVEL_DEPTH-4) zSpawn -= 32;
|
||||||
}
|
}
|
||||||
levelData.setSpawn(xSpawn, ySpawn, zSpawn);
|
levelData.setSpawn(xSpawn, ySpawn, zSpawn);
|
||||||
isFindingSpawn = false;
|
isFindingSpawn = false;
|
||||||
@@ -456,9 +459,9 @@ void Level::validateSpawn() {
|
|||||||
zSpawn += random.nextInt(8) - random.nextInt(8);
|
zSpawn += random.nextInt(8) - random.nextInt(8);
|
||||||
|
|
||||||
if (xSpawn < 4) xSpawn += 8;
|
if (xSpawn < 4) xSpawn += 8;
|
||||||
if (xSpawn >= LEVEL_WIDTH-4) xSpawn -= 8;
|
if (xSpawn >= LevelConstants::LEVEL_WIDTH-4) xSpawn -= 8;
|
||||||
if (zSpawn < 4) zSpawn += 8;
|
if (zSpawn < 4) zSpawn += 8;
|
||||||
if (zSpawn >= LEVEL_DEPTH-4) zSpawn -= 8;
|
if (zSpawn >= LevelConstants::LEVEL_DEPTH-4) zSpawn -= 8;
|
||||||
}
|
}
|
||||||
levelData.setXSpawn(xSpawn);
|
levelData.setXSpawn(xSpawn);
|
||||||
levelData.setZSpawn(zSpawn);
|
levelData.setZSpawn(zSpawn);
|
||||||
@@ -944,7 +947,7 @@ HitResult Level::clip(const Vec3& A, const Vec3& b, bool liquid /*= false*/, boo
|
|||||||
if (solidOnly && tile != NULL && tile->getAABB(this, xTile0, yTile0, zTile0) == NULL) {
|
if (solidOnly && tile != NULL && tile->getAABB(this, xTile0, yTile0, zTile0) == NULL) {
|
||||||
// No collision
|
// No collision
|
||||||
} else if (t > 0 && tile->mayPick(data, liquid)) {
|
} else if (t > 0 && tile->mayPick(data, liquid)) {
|
||||||
if(xTile0 >= 0 && zTile0 >= 0 && xTile0 < LEVEL_WIDTH && zTile0 < LEVEL_WIDTH) {
|
if(xTile0 >= 0 && zTile0 >= 0 && xTile0 < LevelConstants::LEVEL_WIDTH && zTile0 < LevelConstants::LEVEL_WIDTH) {
|
||||||
HitResult r = tile->clip(this, xTile0, yTile0, zTile0, a, b);
|
HitResult r = tile->clip(this, xTile0, yTile0, zTile0, a, b);
|
||||||
if (r.isHit()) return r;
|
if (r.isHit()) return r;
|
||||||
}
|
}
|
||||||
@@ -2222,9 +2225,9 @@ void Level::setNightMode( bool isNightMode ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Level::inRange( int x, int y, int z ) {
|
bool Level::inRange( int x, int y, int z ) {
|
||||||
return x >= 0 && x < LEVEL_WIDTH
|
return x >= 0 && x < LevelConstants::LEVEL_WIDTH
|
||||||
&& y >= 0 && y < LEVEL_HEIGHT
|
&& y >= 0 && y < LevelConstants::LEVEL_HEIGHT
|
||||||
&& z >= 0 && z < LEVEL_DEPTH;
|
&& z >= 0 && z < LevelConstants::LEVEL_DEPTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -67,8 +67,8 @@ class Level: public LevelSource
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
static const int MAX_LEVEL_SIZE = 32000000;
|
static const int MAX_LEVEL_SIZE = 32000000;
|
||||||
static const short DEPTH = LEVEL_HEIGHT;
|
static const int DEPTH;
|
||||||
static const short SEA_LEVEL = DEPTH / 2 - 1;
|
static const int SEA_LEVEL;
|
||||||
|
|
||||||
static const int MAX_BRIGHTNESS = 15;
|
static const int MAX_BRIGHTNESS = 15;
|
||||||
static const int TICKS_PER_DAY = SharedConstants::TicksPerSecond * 60 * 16;// SharedConstants::TicksPerSecond * 60 * 12; // ORG:20*60*20
|
static const int TICKS_PER_DAY = SharedConstants::TicksPerSecond * 60 * 16;// SharedConstants::TicksPerSecond * 60 * 12; // ORG:20*60*20
|
||||||
@@ -309,7 +309,7 @@ public:
|
|||||||
Random random;
|
Random random;
|
||||||
|
|
||||||
std::set<std::string> ops;
|
std::set<std::string> ops;
|
||||||
|
std::set<std::string> bannedPpl;
|
||||||
protected:
|
protected:
|
||||||
bool isFindingSpawn;
|
bool isFindingSpawn;
|
||||||
|
|
||||||
|
|||||||
10
src/world/level/LevelConstants.cpp
Normal file
10
src/world/level/LevelConstants.cpp
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#include "LevelConstants.h"
|
||||||
|
|
||||||
|
int LevelConstants::LEVEL_HEIGHT = 128;
|
||||||
|
int LevelConstants::CHUNK_CACHE_WIDTH = 16; // in chunks
|
||||||
|
int LevelConstants::CHUNK_WIDTH = 16; // in blocks
|
||||||
|
int LevelConstants::CHUNK_DEPTH = 16;
|
||||||
|
int LevelConstants::LEVEL_WIDTH = LevelConstants::CHUNK_CACHE_WIDTH * CHUNK_WIDTH;
|
||||||
|
int LevelConstants::LEVEL_DEPTH = LevelConstants::CHUNK_CACHE_WIDTH * CHUNK_DEPTH;
|
||||||
|
int LevelConstants::CHUNK_COLUMNS = LevelConstants::CHUNK_WIDTH * LevelConstants::CHUNK_DEPTH;
|
||||||
|
int LevelConstants::CHUNK_BLOCK_COUNT = LevelConstants::CHUNK_COLUMNS * LevelConstants::LEVEL_HEIGHT;
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
#ifndef _MINECRAFT_WORLD_LEVELCONSTANTS_H_
|
#pragma once
|
||||||
#define _MINECRAFT_WORLD_LEVELCONSTANTS_H_
|
|
||||||
|
|
||||||
|
class LevelConstants {
|
||||||
const int LEVEL_HEIGHT = 128;
|
public:
|
||||||
const int CHUNK_CACHE_WIDTH = 16; // in chunks
|
static int CHUNK_CACHE_WIDTH; // in chunks
|
||||||
const int CHUNK_WIDTH = 16; // in blocks
|
static int LEVEL_WIDTH;
|
||||||
const int CHUNK_DEPTH = 16;
|
static int LEVEL_DEPTH;
|
||||||
const int LEVEL_WIDTH = CHUNK_CACHE_WIDTH * CHUNK_WIDTH;
|
static int LEVEL_HEIGHT;
|
||||||
const int LEVEL_DEPTH = CHUNK_CACHE_WIDTH * CHUNK_DEPTH;
|
|
||||||
const int CHUNK_COLUMNS = CHUNK_WIDTH * CHUNK_DEPTH;
|
static int CHUNK_WIDTH; // in blocks
|
||||||
const int CHUNK_BLOCK_COUNT = CHUNK_COLUMNS * LEVEL_HEIGHT;
|
static int CHUNK_DEPTH;
|
||||||
|
static int CHUNK_COLUMNS;
|
||||||
#endif
|
static int CHUNK_BLOCK_COUNT;
|
||||||
|
};
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
#include "../LevelConstants.h"
|
#include "../LevelConstants.h"
|
||||||
|
|
||||||
class ChunkCache: public ChunkSource {
|
class ChunkCache: public ChunkSource {
|
||||||
//static const int CHUNK_CACHE_WIDTH = CHUNK_CACHE_WIDTH; // WAS 32;
|
//static const int LevelConstants::CHUNK_CACHE_WIDTH = LevelConstants::CHUNK_CACHE_WIDTH; // WAS 32;
|
||||||
static const int MAX_SAVES = 2;
|
static const int MAX_SAVES = 2;
|
||||||
public:
|
public:
|
||||||
ChunkCache(Level* level_, ChunkStorage* storage_, ChunkSource* source_)
|
ChunkCache(Level* level_, ChunkStorage* storage_, ChunkSource* source_)
|
||||||
@@ -24,14 +24,17 @@ public:
|
|||||||
isChunkCache = true;
|
isChunkCache = true;
|
||||||
//emptyChunk = new EmptyLevelChunk(level_, emptyChunkBlocks, 0, 0);
|
//emptyChunk = new EmptyLevelChunk(level_, emptyChunkBlocks, 0, 0);
|
||||||
emptyChunk = new EmptyLevelChunk(level_, NULL, 0, 0);
|
emptyChunk = new EmptyLevelChunk(level_, NULL, 0, 0);
|
||||||
memset(chunks, 0, sizeof(LevelChunk*) * CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH);
|
|
||||||
|
chunks = new LevelChunk *[LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_CACHE_WIDTH];
|
||||||
|
memset(chunks, 0, sizeof(LevelChunk*) * LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_CACHE_WIDTH);
|
||||||
|
LOGI("Chunks allocated.");
|
||||||
}
|
}
|
||||||
|
|
||||||
~ChunkCache() {
|
~ChunkCache() {
|
||||||
delete source;
|
delete source;
|
||||||
delete emptyChunk;
|
delete emptyChunk;
|
||||||
|
|
||||||
for (int i = 0; i < CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH; i++)
|
for (int i = 0; i < LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_CACHE_WIDTH; i++)
|
||||||
{
|
{
|
||||||
if (chunks[i])
|
if (chunks[i])
|
||||||
{
|
{
|
||||||
@@ -42,7 +45,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool fits(int x, int z) {
|
bool fits(int x, int z) {
|
||||||
return (x >= 0 && z >= 0 && x < CHUNK_CACHE_WIDTH && z < CHUNK_CACHE_WIDTH);
|
return (x >= 0 && z >= 0 && x < LevelConstants::CHUNK_CACHE_WIDTH && z < LevelConstants::CHUNK_CACHE_WIDTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasChunk(int x, int z) {
|
bool hasChunk(int x, int z) {
|
||||||
@@ -52,9 +55,9 @@ public:
|
|||||||
if (x == xLast && z == zLast && last != NULL) {
|
if (x == xLast && z == zLast && last != NULL) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
int xs = x & (CHUNK_CACHE_WIDTH - 1);
|
int xs = x & (LevelConstants::CHUNK_CACHE_WIDTH - 1);
|
||||||
int zs = z & (CHUNK_CACHE_WIDTH - 1);
|
int zs = z & (LevelConstants::CHUNK_CACHE_WIDTH - 1);
|
||||||
int slot = xs + zs * CHUNK_CACHE_WIDTH;
|
int slot = xs + zs * LevelConstants::CHUNK_CACHE_WIDTH;
|
||||||
return chunks[slot] != NULL && (chunks[slot] == emptyChunk || chunks[slot]->isAt(x, z));
|
return chunks[slot] != NULL && (chunks[slot] == emptyChunk || chunks[slot]->isAt(x, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,9 +74,9 @@ public:
|
|||||||
}
|
}
|
||||||
if (!fits(x, z)) return emptyChunk;
|
if (!fits(x, z)) return emptyChunk;
|
||||||
//if (!level->isFindingSpawn && !fits(x, z)) return emptyChunk;
|
//if (!level->isFindingSpawn && !fits(x, z)) return emptyChunk;
|
||||||
int xs = x & (CHUNK_CACHE_WIDTH - 1);
|
int xs = x & (LevelConstants::CHUNK_CACHE_WIDTH - 1);
|
||||||
int zs = z & (CHUNK_CACHE_WIDTH - 1);
|
int zs = z & (LevelConstants::CHUNK_CACHE_WIDTH - 1);
|
||||||
int slot = xs + zs * CHUNK_CACHE_WIDTH;
|
int slot = xs + zs * LevelConstants::CHUNK_CACHE_WIDTH;
|
||||||
if (!hasChunk(x, z)) {
|
if (!hasChunk(x, z)) {
|
||||||
if (chunks[slot] != NULL) {
|
if (chunks[slot] != NULL) {
|
||||||
chunks[slot]->unload();
|
chunks[slot]->unload();
|
||||||
@@ -199,8 +202,8 @@ public:
|
|||||||
void saveAll(bool onlyUnsaved) {
|
void saveAll(bool onlyUnsaved) {
|
||||||
if (storage != NULL) {
|
if (storage != NULL) {
|
||||||
std::vector<LevelChunk*> chunks;
|
std::vector<LevelChunk*> chunks;
|
||||||
for (int z = 0; z < CHUNK_CACHE_WIDTH; ++z)
|
for (int z = 0; z < LevelConstants::CHUNK_CACHE_WIDTH; ++z)
|
||||||
for (int x = 0; x < CHUNK_CACHE_WIDTH; ++x) {
|
for (int x = 0; x < LevelConstants::CHUNK_CACHE_WIDTH; ++x) {
|
||||||
LevelChunk* chunk = level->getChunk(x, z);
|
LevelChunk* chunk = level->getChunk(x, z);
|
||||||
if (!onlyUnsaved || chunk->shouldSave(false))
|
if (!onlyUnsaved || chunk->shouldSave(false))
|
||||||
chunks.push_back( chunk );
|
chunks.push_back( chunk );
|
||||||
@@ -211,7 +214,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
LevelChunk* load(int x, int z) {
|
LevelChunk* load(int x, int z) {
|
||||||
if (storage == NULL) return emptyChunk;
|
if (storage == NULL) return emptyChunk;
|
||||||
if (x < 0 || x >= CHUNK_CACHE_WIDTH || z < 0 || z >= CHUNK_CACHE_WIDTH)
|
if (x < 0 || x >= LevelConstants::CHUNK_CACHE_WIDTH || z < 0 || z >= LevelConstants::CHUNK_CACHE_WIDTH)
|
||||||
{
|
{
|
||||||
return emptyChunk;
|
return emptyChunk;
|
||||||
}
|
}
|
||||||
@@ -254,7 +257,7 @@ private:
|
|||||||
LevelChunk* emptyChunk;
|
LevelChunk* emptyChunk;
|
||||||
ChunkSource* source;
|
ChunkSource* source;
|
||||||
ChunkStorage* storage;
|
ChunkStorage* storage;
|
||||||
LevelChunk* chunks[CHUNK_CACHE_WIDTH * CHUNK_CACHE_WIDTH];
|
LevelChunk** chunks;
|
||||||
Level* level;
|
Level* level;
|
||||||
|
|
||||||
LevelChunk* last;
|
LevelChunk* last;
|
||||||
|
|||||||
@@ -12,13 +12,14 @@
|
|||||||
|
|
||||||
/*static*/
|
/*static*/
|
||||||
bool LevelChunk::touchedSky = false;
|
bool LevelChunk::touchedSky = false;
|
||||||
|
int LevelChunk::ChunkBlockCount;
|
||||||
|
|
||||||
LevelChunk::LevelChunk( Level* level, int x, int z )
|
LevelChunk::LevelChunk( Level* level, int x, int z )
|
||||||
: level(level),
|
: level(level),
|
||||||
x(x),
|
x(x),
|
||||||
z(z),
|
z(z),
|
||||||
xt(x * CHUNK_WIDTH),
|
xt(x * LevelConstants::CHUNK_WIDTH),
|
||||||
zt(z * CHUNK_DEPTH)
|
zt(z * LevelConstants::CHUNK_DEPTH)
|
||||||
{
|
{
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
@@ -27,8 +28,8 @@ LevelChunk::LevelChunk( Level* level, unsigned char* blocks, int x, int z )
|
|||||||
: level(level),
|
: level(level),
|
||||||
x(x),
|
x(x),
|
||||||
z(z),
|
z(z),
|
||||||
xt(x * CHUNK_WIDTH),
|
xt(x * LevelConstants::CHUNK_WIDTH),
|
||||||
zt(z * CHUNK_DEPTH),
|
zt(z * LevelConstants::CHUNK_DEPTH),
|
||||||
blocks(blocks),
|
blocks(blocks),
|
||||||
data(ChunkBlockCount),
|
data(ChunkBlockCount),
|
||||||
skyLight(ChunkBlockCount),
|
skyLight(ChunkBlockCount),
|
||||||
@@ -45,6 +46,9 @@ LevelChunk::~LevelChunk()
|
|||||||
|
|
||||||
void LevelChunk::init()
|
void LevelChunk::init()
|
||||||
{
|
{
|
||||||
|
heightmap = new char[LevelConstants::CHUNK_COLUMNS];
|
||||||
|
updateMap = new unsigned char[LevelConstants::CHUNK_COLUMNS];
|
||||||
|
|
||||||
terrainPopulated = false;
|
terrainPopulated = false;
|
||||||
dontSave = false;
|
dontSave = false;
|
||||||
unsaved = false;
|
unsaved = false;
|
||||||
|
|||||||
@@ -106,9 +106,9 @@ private:
|
|||||||
void recalcHeight(int x, int yStart, int z);
|
void recalcHeight(int x, int yStart, int z);
|
||||||
public:
|
public:
|
||||||
static bool touchedSky;
|
static bool touchedSky;
|
||||||
static const int ChunkBlockCount = CHUNK_BLOCK_COUNT;
|
static int ChunkBlockCount;
|
||||||
static const int ChunkSize = ChunkBlockCount;
|
const int ChunkSize = ChunkBlockCount;
|
||||||
static const int UpdateMapBitShift = 4; // power of (LEVEL_HEIGHT / 8) == 16
|
static const int UpdateMapBitShift = 4; // power of (LevelConstants::LEVEL_HEIGHT / 8) == 16
|
||||||
|
|
||||||
int blocksLength; // ? needed or not? (i.e. are all chunks the same size?)
|
int blocksLength; // ? needed or not? (i.e. are all chunks the same size?)
|
||||||
|
|
||||||
@@ -118,12 +118,12 @@ public:
|
|||||||
DataLayer skyLight;
|
DataLayer skyLight;
|
||||||
DataLayer blockLight;
|
DataLayer blockLight;
|
||||||
|
|
||||||
char heightmap[CHUNK_COLUMNS];
|
char* heightmap; // [LevelConstants::CHUNK_COLUMNS]
|
||||||
unsigned char updateMap[CHUNK_COLUMNS]; // marks regions within block columns that have been modified
|
unsigned char* updateMap; // marks regions within block columns that have been modified [LevelConstants::CHUNK_COLUMNS]
|
||||||
int minHeight;
|
int minHeight;
|
||||||
|
|
||||||
const int x, z;
|
int x, z;
|
||||||
const int xt, zt;
|
int xt, zt;
|
||||||
|
|
||||||
bool terrainPopulated;
|
bool terrainPopulated;
|
||||||
bool unsaved;
|
bool unsaved;
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ RandomLevelSource::~RandomLevelSource() {
|
|||||||
/*public*/
|
/*public*/
|
||||||
void RandomLevelSource::prepareHeights(int xOffs, int zOffs, unsigned char* blocks, /*Biome*/void* biomes, float* temperatures) {
|
void RandomLevelSource::prepareHeights(int xOffs, int zOffs, unsigned char* blocks, /*Biome*/void* biomes, float* temperatures) {
|
||||||
|
|
||||||
int xChunks = 16 / CHUNK_WIDTH;
|
int xChunks = 16 / LevelConstants::CHUNK_WIDTH;
|
||||||
int waterHeight = Level::DEPTH - 64;
|
int waterHeight = Level::DEPTH - 64;
|
||||||
|
|
||||||
int xSize = xChunks + 1;
|
int xSize = xChunks + 1;
|
||||||
@@ -87,23 +87,23 @@ void RandomLevelSource::prepareHeights(int xOffs, int zOffs, unsigned char* bloc
|
|||||||
float s3a = (buffer[((xc + 1) * zSize + (zc + 1)) * ySize + (yc + 1)] - s3) * yStep;
|
float s3a = (buffer[((xc + 1) * zSize + (zc + 1)) * ySize + (yc + 1)] - s3) * yStep;
|
||||||
|
|
||||||
for (int y = 0; y < CHUNK_HEIGHT; y++) {
|
for (int y = 0; y < CHUNK_HEIGHT; y++) {
|
||||||
float xStep = 1 / (float) CHUNK_WIDTH;
|
float xStep = 1 / (float) LevelConstants::CHUNK_WIDTH;
|
||||||
|
|
||||||
float _s0 = s0;
|
float _s0 = s0;
|
||||||
float _s1 = s1;
|
float _s1 = s1;
|
||||||
float _s0a = (s2 - s0) * xStep;
|
float _s0a = (s2 - s0) * xStep;
|
||||||
float _s1a = (s3 - s1) * xStep;
|
float _s1a = (s3 - s1) * xStep;
|
||||||
|
|
||||||
for (int x = 0; x < CHUNK_WIDTH; x++) {
|
for (int x = 0; x < LevelConstants::CHUNK_WIDTH; x++) {
|
||||||
int offs = (x + xc * CHUNK_WIDTH) << 11 | (0 + zc * CHUNK_WIDTH) << 7 | (yc * CHUNK_HEIGHT + y);
|
int offs = (x + xc * LevelConstants::CHUNK_WIDTH) << 11 | (0 + zc * LevelConstants::CHUNK_WIDTH) << 7 | (yc * CHUNK_HEIGHT + y);
|
||||||
int step = 1 << 7;
|
int step = 1 << 7;
|
||||||
float zStep = 1 / (float) CHUNK_WIDTH;
|
float zStep = 1 / (float) LevelConstants::CHUNK_WIDTH;
|
||||||
|
|
||||||
float val = _s0;
|
float val = _s0;
|
||||||
float vala = (_s1 - _s0) * zStep;
|
float vala = (_s1 - _s0) * zStep;
|
||||||
for (int z = 0; z < CHUNK_WIDTH; z++) {
|
for (int z = 0; z < LevelConstants::CHUNK_WIDTH; z++) {
|
||||||
// + (zc * CHUNK_WIDTH + z)];
|
// + (zc * LevelConstants::CHUNK_WIDTH + z)];
|
||||||
float temp = temperatures[(xc * CHUNK_WIDTH + x) * 16 + (zc * CHUNK_WIDTH + z)];
|
float temp = temperatures[(xc * LevelConstants::CHUNK_WIDTH + x) * 16 + (zc * LevelConstants::CHUNK_WIDTH + z)];
|
||||||
int tileId = 0;
|
int tileId = 0;
|
||||||
if (yc * CHUNK_HEIGHT + y < waterHeight) {
|
if (yc * CHUNK_HEIGHT + y < waterHeight) {
|
||||||
if (temp < SNOW_CUTOFF && yc * CHUNK_HEIGHT + y >= waterHeight - 1) {
|
if (temp < SNOW_CUTOFF && yc * CHUNK_HEIGHT + y >= waterHeight - 1) {
|
||||||
|
|||||||
@@ -343,8 +343,8 @@ bool ExternalFileLevelStorage::readPlayerData(const std::string& filename, Level
|
|||||||
Vec3& pos = dest.playerData.pos;
|
Vec3& pos = dest.playerData.pos;
|
||||||
if (pos.x < 0.5f) pos.x = 0.5f;
|
if (pos.x < 0.5f) pos.x = 0.5f;
|
||||||
if (pos.z < 0.5f) pos.z = 0.5f;
|
if (pos.z < 0.5f) pos.z = 0.5f;
|
||||||
if (pos.x > (LEVEL_WIDTH - 0.5f)) pos.x = LEVEL_WIDTH - 0.5f;
|
if (pos.x > (LevelConstants::LEVEL_WIDTH - 0.5f)) pos.x = LevelConstants::LEVEL_WIDTH - 0.5f;
|
||||||
if (pos.z > (LEVEL_DEPTH - 0.5f)) pos.z = LEVEL_DEPTH - 0.5f;
|
if (pos.z > (LevelConstants::LEVEL_DEPTH - 0.5f)) pos.z = LevelConstants::LEVEL_DEPTH - 0.5f;
|
||||||
if (pos.y < 0) pos.y = 64;
|
if (pos.y < 0) pos.y = 64;
|
||||||
|
|
||||||
dest.playerDataVersion = version;
|
dest.playerDataVersion = version;
|
||||||
@@ -362,14 +362,14 @@ void ExternalFileLevelStorage::tick()
|
|||||||
LOGI("Saving level...\n");
|
LOGI("Saving level...\n");
|
||||||
|
|
||||||
// look for chunks that needs to be saved
|
// look for chunks that needs to be saved
|
||||||
for (int z = 0; z < CHUNK_CACHE_WIDTH; z++)
|
for (int z = 0; z < LevelConstants::CHUNK_CACHE_WIDTH; z++)
|
||||||
{
|
{
|
||||||
for (int x = 0; x < CHUNK_CACHE_WIDTH; x++)
|
for (int x = 0; x < LevelConstants::CHUNK_CACHE_WIDTH; x++)
|
||||||
{
|
{
|
||||||
LevelChunk* chunk = level->getChunk(x, z);
|
LevelChunk* chunk = level->getChunk(x, z);
|
||||||
if (chunk && chunk->unsaved)
|
if (chunk && chunk->unsaved)
|
||||||
{
|
{
|
||||||
int pos = x + z * CHUNK_CACHE_WIDTH;
|
int pos = x + z * LevelConstants::CHUNK_CACHE_WIDTH;
|
||||||
UnsavedChunkList::iterator prev = unsavedChunkList.begin();
|
UnsavedChunkList::iterator prev = unsavedChunkList.begin();
|
||||||
for ( ; prev != unsavedChunkList.end(); ++prev)
|
for ( ; prev != unsavedChunkList.end(); ++prev)
|
||||||
{
|
{
|
||||||
@@ -415,13 +415,13 @@ void ExternalFileLevelStorage::save(Level* level, LevelChunk* levelChunk)
|
|||||||
|
|
||||||
// Write chunk
|
// Write chunk
|
||||||
RakNet::BitStream chunkData;
|
RakNet::BitStream chunkData;
|
||||||
chunkData.Write((const char*)levelChunk->getBlockData(), CHUNK_BLOCK_COUNT);
|
chunkData.Write((const char*)levelChunk->getBlockData(), LevelConstants::CHUNK_BLOCK_COUNT);
|
||||||
chunkData.Write((const char*)levelChunk->data.data, CHUNK_BLOCK_COUNT / 2);
|
chunkData.Write((const char*)levelChunk->data.data, LevelConstants::CHUNK_BLOCK_COUNT / 2);
|
||||||
|
|
||||||
chunkData.Write((const char*)levelChunk->skyLight.data, CHUNK_BLOCK_COUNT / 2);
|
chunkData.Write((const char*)levelChunk->skyLight.data, LevelConstants::CHUNK_BLOCK_COUNT / 2);
|
||||||
chunkData.Write((const char*)levelChunk->blockLight.data, CHUNK_BLOCK_COUNT / 2);
|
chunkData.Write((const char*)levelChunk->blockLight.data, LevelConstants::CHUNK_BLOCK_COUNT / 2);
|
||||||
|
|
||||||
chunkData.Write((const char*)levelChunk->updateMap, CHUNK_COLUMNS);
|
chunkData.Write((const char*)levelChunk->updateMap, LevelConstants::CHUNK_COLUMNS);
|
||||||
|
|
||||||
regionFile->writeChunk(levelChunk->x, levelChunk->z, chunkData);
|
regionFile->writeChunk(levelChunk->x, levelChunk->z, chunkData);
|
||||||
|
|
||||||
@@ -453,16 +453,16 @@ LevelChunk* ExternalFileLevelStorage::load(Level* level, int x, int z)
|
|||||||
|
|
||||||
chunkData->ResetReadPointer();
|
chunkData->ResetReadPointer();
|
||||||
|
|
||||||
unsigned char* blockIds = new unsigned char[CHUNK_BLOCK_COUNT];
|
unsigned char* blockIds = new unsigned char[LevelConstants::CHUNK_BLOCK_COUNT];
|
||||||
chunkData->Read((char*)blockIds, CHUNK_BLOCK_COUNT);
|
chunkData->Read((char*)blockIds, LevelConstants::CHUNK_BLOCK_COUNT);
|
||||||
|
|
||||||
LevelChunk* levelChunk = new LevelChunk(level, blockIds, x, z);
|
LevelChunk* levelChunk = new LevelChunk(level, blockIds, x, z);
|
||||||
chunkData->Read((char*)levelChunk->data.data, CHUNK_BLOCK_COUNT / 2);
|
chunkData->Read((char*)levelChunk->data.data, LevelConstants::CHUNK_BLOCK_COUNT / 2);
|
||||||
if (loadedStorageVersion >= ChunkVersion_Light) {
|
if (loadedStorageVersion >= ChunkVersion_Light) {
|
||||||
chunkData->Read((char*)levelChunk->skyLight.data, CHUNK_BLOCK_COUNT / 2);
|
chunkData->Read((char*)levelChunk->skyLight.data, LevelConstants::CHUNK_BLOCK_COUNT / 2);
|
||||||
chunkData->Read((char*)levelChunk->blockLight.data, CHUNK_BLOCK_COUNT / 2);
|
chunkData->Read((char*)levelChunk->blockLight.data, LevelConstants::CHUNK_BLOCK_COUNT / 2);
|
||||||
}
|
}
|
||||||
chunkData->Read((char*)levelChunk->updateMap, CHUNK_COLUMNS);
|
chunkData->Read((char*)levelChunk->updateMap, LevelConstants::CHUNK_COLUMNS);
|
||||||
// This will be difficult to maintain.. Storage version could be per chunk
|
// This will be difficult to maintain.. Storage version could be per chunk
|
||||||
// too (but probably better to just read all -> write all, so that all
|
// too (but probably better to just read all -> write all, so that all
|
||||||
// chunks got same version anyway)
|
// chunks got same version anyway)
|
||||||
@@ -485,7 +485,7 @@ LevelChunk* ExternalFileLevelStorage::load(Level* level, int x, int z)
|
|||||||
//bool dbg = (x == 7 && z == 9);
|
//bool dbg = (x == 7 && z == 9);
|
||||||
|
|
||||||
//int t = 0;
|
//int t = 0;
|
||||||
//for (int i = 0; i < CHUNK_COLUMNS; ++i) {
|
//for (int i = 0; i < LevelConstants::CHUNK_COLUMNS; ++i) {
|
||||||
// char bits = levelChunk->updateMap[i];
|
// char bits = levelChunk->updateMap[i];
|
||||||
// t += (bits != 0);
|
// t += (bits != 0);
|
||||||
// int xx = x * 16 + i%16;
|
// int xx = x * 16 + i%16;
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ bool Mushroom::mayPlaceOn( int tile ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Mushroom::canSurvive( Level* level, int x, int y, int z ) {
|
bool Mushroom::canSurvive( Level* level, int x, int y, int z ) {
|
||||||
if (y < 0 || y >= LEVEL_HEIGHT/*Level::maxBuildHeight*/)
|
if (y < 0 || y >= LevelConstants::LEVEL_HEIGHT/*Level::maxBuildHeight*/)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int below = level->getTile(x, y - 1, z);
|
int below = level->getTile(x, y - 1, z);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ bool NetherReactor::canSpawnStartNetherReactor( Level* level, int x, int y, int
|
|||||||
if(!allPlayersCloseToReactor(level, x, y, z)) {
|
if(!allPlayersCloseToReactor(level, x, y, z)) {
|
||||||
player->displayClientMessage("All players need to be close to the reactor.");
|
player->displayClientMessage("All players need to be close to the reactor.");
|
||||||
return false;
|
return false;
|
||||||
} else if(y > LEVEL_HEIGHT - 28) {
|
} else if(y > LevelConstants::LEVEL_HEIGHT - 28) {
|
||||||
player->displayClientMessage("The nether reactor needs to be built lower down.");
|
player->displayClientMessage("The nether reactor needs to be built lower down.");
|
||||||
return false;
|
return false;
|
||||||
} else if(y < 2) {
|
} else if(y < 2) {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "../../item/StoneSlabTileItem.h"
|
#include "../../item/StoneSlabTileItem.h"
|
||||||
#include "../../item/SaplingTileItem.h"
|
#include "../../item/SaplingTileItem.h"
|
||||||
#include "../../item/ItemCategory.h"
|
#include "../../item/ItemCategory.h"
|
||||||
|
#include "world/level/LevelConstants.h"
|
||||||
|
|
||||||
const int Tile::RENDERLAYER_OPAQUE = 0;
|
const int Tile::RENDERLAYER_OPAQUE = 0;
|
||||||
const int Tile::RENDERLAYER_ALPHATEST = 1;
|
const int Tile::RENDERLAYER_ALPHATEST = 1;
|
||||||
@@ -512,10 +513,15 @@ bool Tile::shouldRenderFace( LevelSource* level, int x, int y, int z, int face )
|
|||||||
{
|
{
|
||||||
if (face == 0 && y == -1) return false;
|
if (face == 0 && y == -1) return false;
|
||||||
// For fixed size worlds //@todo: external constants rather than magic numbers
|
// For fixed size worlds //@todo: external constants rather than magic numbers
|
||||||
|
// @fixme @ahtung temp fix
|
||||||
|
|
||||||
|
auto xz = LevelConstants::CHUNK_CACHE_WIDTH == 16 ? 256 :
|
||||||
|
LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_CACHE_WIDTH / (LevelConstants::CHUNK_CACHE_WIDTH * LevelConstants::CHUNK_CACHE_WIDTH / 256 / 2);
|
||||||
|
|
||||||
if (face == 2 && z == -1) return false;
|
if (face == 2 && z == -1) return false;
|
||||||
if (face == 3 && z == 256) return false;
|
if (face == 3 && z == xz) return false;
|
||||||
if (face == 4 && x == -1) return false;
|
if (face == 4 && x == -1) return false;
|
||||||
if (face == 5 && x == 256) return false;
|
if (face == 5 && x == xz) return false;
|
||||||
// Common
|
// Common
|
||||||
if (face == 0 && yy0 > 0) return true;
|
if (face == 0 && yy0 > 0) return true;
|
||||||
if (face == 1 && yy1 < 1) return true;
|
if (face == 1 && yy1 < 1) return true;
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ Vec3 NetherReactorTileEntity::getSpawnPosition( float minDistance, float varible
|
|||||||
void NetherReactorTileEntity::spawnEnemy() {
|
void NetherReactorTileEntity::spawnEnemy() {
|
||||||
Mob* mob = MobFactory::CreateMob(MobTypes::PigZombie, level);
|
Mob* mob = MobFactory::CreateMob(MobTypes::PigZombie, level);
|
||||||
Vec3 enemyPosition = getSpawnPosition(3, 4, -1);
|
Vec3 enemyPosition = getSpawnPosition(3, 4, -1);
|
||||||
while(enemyPosition.x < 0 || enemyPosition.z < 0 || enemyPosition.x >= LEVEL_WIDTH || enemyPosition.z >= LEVEL_DEPTH) {
|
while(enemyPosition.x < 0 || enemyPosition.z < 0 || enemyPosition.x >= LevelConstants::LEVEL_WIDTH || enemyPosition.z >= LevelConstants::LEVEL_DEPTH) {
|
||||||
enemyPosition = getSpawnPosition(3, 4, -1);
|
enemyPosition = getSpawnPosition(3, 4, -1);
|
||||||
}
|
}
|
||||||
MobSpawner::addMob(level, mob, enemyPosition.x, enemyPosition.y, enemyPosition.z, 0, 0, true);
|
MobSpawner::addMob(level, mob, enemyPosition.x, enemyPosition.y, enemyPosition.z, 0, 0, true);
|
||||||
@@ -140,7 +140,7 @@ void NetherReactorTileEntity::spawnEnemy() {
|
|||||||
|
|
||||||
void NetherReactorTileEntity::spawnItem() {
|
void NetherReactorTileEntity::spawnItem() {
|
||||||
Vec3 itemPosition= getSpawnPosition(3, 4, -1);
|
Vec3 itemPosition= getSpawnPosition(3, 4, -1);
|
||||||
while(itemPosition.x < 0 || itemPosition.z < 0 || itemPosition.x >= LEVEL_WIDTH || itemPosition.z >= LEVEL_DEPTH) {
|
while(itemPosition.x < 0 || itemPosition.z < 0 || itemPosition.x >= LevelConstants::LEVEL_WIDTH || itemPosition.z >= LevelConstants::LEVEL_DEPTH) {
|
||||||
itemPosition = getSpawnPosition(3, 4, -1);
|
itemPosition = getSpawnPosition(3, 4, -1);
|
||||||
}
|
}
|
||||||
ItemEntity* item = new ItemEntity(level, itemPosition.x, itemPosition.y, itemPosition.z, getSpawnItem());
|
ItemEntity* item = new ItemEntity(level, itemPosition.x, itemPosition.y, itemPosition.z, getSpawnItem());
|
||||||
|
|||||||
Reference in New Issue
Block a user