|
@@ -478,6 +478,7 @@ void Chunk::initializeLightning()
|
|
Framework::Either<Block*, int> Chunk::zBlockAt(
|
|
Framework::Either<Block*, int> Chunk::zBlockAt(
|
|
Framework::Vec3<int> location) const
|
|
Framework::Vec3<int> location) const
|
|
{
|
|
{
|
|
|
|
+ if (location.z < 0 || location.z >= WORLD_HEIGHT) return 0;
|
|
int index = Chunk::index(location);
|
|
int index = Chunk::index(location);
|
|
assert(index < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT);
|
|
assert(index < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT);
|
|
if (blocks[index])
|
|
if (blocks[index])
|
|
@@ -670,13 +671,37 @@ void Chunk::putBlockTypeAt(Framework::Vec3<int> location, int type)
|
|
void Chunk::sendBlockInfo(Framework::Vec3<int> location)
|
|
void Chunk::sendBlockInfo(Framework::Vec3<int> location)
|
|
{
|
|
{
|
|
int index = Chunk::index(location);
|
|
int index = Chunk::index(location);
|
|
- char* msg = new char[9];
|
|
|
|
|
|
+ char* msg = new char[14];
|
|
msg[0] = 0; // set block
|
|
msg[0] = 0; // set block
|
|
- *(int*)(msg + 1) = index;
|
|
|
|
- *(int*)(msg + 5) = blockIds[index];
|
|
|
|
|
|
+ *(unsigned short*)(msg + 1) = blockIds[index];
|
|
|
|
+ *(int*)(msg + 3) = index;
|
|
|
|
+ char state = 0;
|
|
|
|
+ const BlockType* type = Game::INSTANCE->zBlockType(blockIds[index]);
|
|
|
|
+ if (type->isFluid())
|
|
|
|
+ {
|
|
|
|
+ state |= 1;
|
|
|
|
+ }
|
|
|
|
+ if ((blocks[index] && blocks[index]->isPassable())
|
|
|
|
+ || (type->zDefault()->isPassable()))
|
|
|
|
+ {
|
|
|
|
+ state |= 2;
|
|
|
|
+ }
|
|
|
|
+ msg[7] = state;
|
|
|
|
+ if ((state | 1) == state)
|
|
|
|
+ {
|
|
|
|
+ FluidBlock* fluidBlock = dynamic_cast<FluidBlock*>(blocks[index]);
|
|
|
|
+ msg[8] = fluidBlock ? fluidBlock->getFlowOptions() : 0;
|
|
|
|
+ msg[9] = fluidBlock ? fluidBlock->getDistanceToSource() : 0;
|
|
|
|
+ }
|
|
|
|
+ if ((state | 2) == state)
|
|
|
|
+ {
|
|
|
|
+ *(float*)(msg + 10) = blocks[index]
|
|
|
|
+ ? blocks[index]->getSpeedModifier()
|
|
|
|
+ : type->zDefault()->getSpeedModifier();
|
|
|
|
+ }
|
|
NetworkMessage* message = new NetworkMessage();
|
|
NetworkMessage* message = new NetworkMessage();
|
|
message->addressChunck(this);
|
|
message->addressChunck(this);
|
|
- message->setMessage(msg, 9);
|
|
|
|
|
|
+ message->setMessage(msg, 14);
|
|
notifyObservers(message);
|
|
notifyObservers(message);
|
|
if (blocks[index])
|
|
if (blocks[index])
|
|
{
|
|
{
|
|
@@ -874,26 +899,42 @@ void Chunk::sendToClient(Framework::StreamWriter* zWriter)
|
|
for (int z = 0; z < WORLD_HEIGHT; z++)
|
|
for (int z = 0; z < WORLD_HEIGHT; z++)
|
|
{
|
|
{
|
|
int index = Chunk::index({x, y, z});
|
|
int index = Chunk::index({x, y, z});
|
|
- if (isVisible(index)
|
|
|
|
- && Game::INSTANCE->zBlockType(blockIds[index])
|
|
|
|
- ->doesNeedClientInstance())
|
|
|
|
|
|
+ const BlockType* type
|
|
|
|
+ = Game::INSTANCE->zBlockType(blockIds[index]);
|
|
|
|
+ if (isVisible(index) && type->doesNeedClientInstance())
|
|
{
|
|
{
|
|
- unsigned short blockType = blocks[index]
|
|
|
|
- ? (unsigned short)blocks[index]
|
|
|
|
- ->zBlockType()
|
|
|
|
- ->getId()
|
|
|
|
- : blockIds[index];
|
|
|
|
- zWriter->schreibe((char*)&blockType, 2);
|
|
|
|
|
|
+ zWriter->schreibe((char*)&blockIds[index], 2);
|
|
zWriter->schreibe((char*)&index, 4);
|
|
zWriter->schreibe((char*)&index, 4);
|
|
- if (Game::INSTANCE->zBlockType(blockIds[index])->isFluid())
|
|
|
|
|
|
+ char state = 0;
|
|
|
|
+ if (type->isFluid())
|
|
|
|
+ {
|
|
|
|
+ state |= 1;
|
|
|
|
+ }
|
|
|
|
+ if ((blocks[index] && blocks[index]->isPassable())
|
|
|
|
+ || (type->zDefault()->isPassable()))
|
|
|
|
+ {
|
|
|
|
+ state |= 2;
|
|
|
|
+ }
|
|
|
|
+ zWriter->schreibe((char*)&state, 1);
|
|
|
|
+ if ((state | 1) == state)
|
|
{
|
|
{
|
|
FluidBlock* fluidBlock
|
|
FluidBlock* fluidBlock
|
|
= dynamic_cast<FluidBlock*>(blocks[index]);
|
|
= dynamic_cast<FluidBlock*>(blocks[index]);
|
|
- char data = fluidBlock->getFlowOptions();
|
|
|
|
|
|
+ char data
|
|
|
|
+ = fluidBlock ? fluidBlock->getFlowOptions() : 0;
|
|
zWriter->schreibe(&data, 1);
|
|
zWriter->schreibe(&data, 1);
|
|
- data = fluidBlock->getDistanceToSource();
|
|
|
|
|
|
+ data = fluidBlock ? fluidBlock->getDistanceToSource()
|
|
|
|
+ : 0;
|
|
zWriter->schreibe(&data, 1);
|
|
zWriter->schreibe(&data, 1);
|
|
}
|
|
}
|
|
|
|
+ if ((state | 2) == state)
|
|
|
|
+ {
|
|
|
|
+ float speedModifier
|
|
|
|
+ = blocks[index]
|
|
|
|
+ ? blocks[index]->getSpeedModifier()
|
|
|
|
+ : type->zDefault()->getSpeedModifier();
|
|
|
|
+ zWriter->schreibe((char*)&speedModifier, 4);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|