|
@@ -3,6 +3,8 @@
|
|
#include "NoBlock.h"
|
|
#include "NoBlock.h"
|
|
#include "Game.h"
|
|
#include "Game.h"
|
|
#include "BlockChangedUpdate.h"
|
|
#include "BlockChangedUpdate.h"
|
|
|
|
+#include "PlaceBlockUpdate.h"
|
|
|
|
+#include "BlockRemovedUpdate.h"
|
|
|
|
|
|
Block::Block( const BlockType* zType, ItemType* zTool, Framework::Vec3<int> pos, bool hasInventory )
|
|
Block::Block( const BlockType* zType, ItemType* zTool, Framework::Vec3<int> pos, bool hasInventory )
|
|
: Inventory( pos, hasInventory )
|
|
: Inventory( pos, hasInventory )
|
|
@@ -22,7 +24,7 @@ Block::Block( const BlockType* zType, ItemType* zTool, Framework::Vec3<int> pos,
|
|
maxTickTimeout = -1;
|
|
maxTickTimeout = -1;
|
|
tickSource = 0;
|
|
tickSource = 0;
|
|
currentTickTimeout = 0;
|
|
currentTickTimeout = 0;
|
|
- dimansionId = 0;
|
|
|
|
|
|
+ dimensionId = 0;
|
|
interactable = 0;
|
|
interactable = 0;
|
|
memset( zNeighbours, 0, sizeof( Block* ) * 6 );
|
|
memset( zNeighbours, 0, sizeof( Block* ) * 6 );
|
|
}
|
|
}
|
|
@@ -94,7 +96,7 @@ void Block::setNeighbourType( Direction dir, int type )
|
|
|
|
|
|
void Block::setDimensionId( int id )
|
|
void Block::setDimensionId( int id )
|
|
{
|
|
{
|
|
- dimansionId = id;
|
|
|
|
|
|
+ dimensionId = id;
|
|
}
|
|
}
|
|
|
|
|
|
void api( Framework::StreamReader* zRequest, NetworkResponse* zResponse )
|
|
void api( Framework::StreamReader* zRequest, NetworkResponse* zResponse )
|
|
@@ -154,12 +156,12 @@ float Block::getSpeedModifier() const
|
|
|
|
|
|
const Framework::Vec3<int> Block::getPos() const
|
|
const Framework::Vec3<int> Block::getPos() const
|
|
{
|
|
{
|
|
- return location;
|
|
|
|
|
|
+ return (Framework::Vec3<int>)location;
|
|
}
|
|
}
|
|
|
|
|
|
int Block::getDimensionId() const
|
|
int Block::getDimensionId() const
|
|
{
|
|
{
|
|
- return dimansionId;
|
|
|
|
|
|
+ return dimensionId;
|
|
}
|
|
}
|
|
|
|
|
|
bool Block::isVisible() const
|
|
bool Block::isVisible() const
|
|
@@ -177,8 +179,23 @@ bool Block::isVisible() const
|
|
|
|
|
|
void Block::setHP( float hp )
|
|
void Block::setHP( float hp )
|
|
{
|
|
{
|
|
- this->hp = MAX( 0, hp );
|
|
|
|
- requestTransmission();
|
|
|
|
|
|
+ bool isDead = this->hp == 0.f;
|
|
|
|
+ this->hp = MAX( 0.f, hp );
|
|
|
|
+ if( !isDead && this->hp == 0.f )
|
|
|
|
+ {
|
|
|
|
+ for( int i = 0; i < 6; i++ )
|
|
|
|
+ {
|
|
|
|
+ if( neighbourTypes[ i ] == NoBlockBlockType::ID )
|
|
|
|
+ {
|
|
|
|
+ Framework::Vec3<int> pos = getPos() + getDirection( getDirectionFromIndex( i ) );
|
|
|
|
+ Game::INSTANCE->requestWorldUpdate( new PlaceBlockUpdate( Game::INSTANCE->zGenerator()->generateSingleBlock( pos, dimensionId ), pos, dimensionId ) );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Game::INSTANCE->requestWorldUpdate( new BlockRemovedUpdate( getPos(), dimensionId ) );
|
|
|
|
+ // TODO: generate item stacks and drop them
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ requestTransmission();
|
|
}
|
|
}
|
|
|
|
|
|
void Block::onAfterTransmission()
|
|
void Block::onAfterTransmission()
|
|
@@ -191,7 +208,7 @@ void Block::requestTransmission()
|
|
if( !transmissionRequested )
|
|
if( !transmissionRequested )
|
|
{
|
|
{
|
|
transmissionRequested = 1;
|
|
transmissionRequested = 1;
|
|
- Game::INSTANCE->requestWorldUpdate( new BlockChangedUpdate( (Framework::Vec3<int>)location, getDimensionId() ) );
|
|
|
|
|
|
+ Game::INSTANCE->requestWorldUpdate( new BlockChangedUpdate( getPos(), getDimensionId() ) );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|