|
@@ -5,6 +5,9 @@
|
|
|
#include "BlockChangedUpdate.h"
|
|
|
#include "PlaceBlockUpdate.h"
|
|
|
#include "BlockRemovedUpdate.h"
|
|
|
+#include "ItemEntity.h"
|
|
|
+#include "AddEntityUpdate.h"
|
|
|
+
|
|
|
|
|
|
Block::Block( const BlockType* zType, ItemType* zTool, Framework::Vec3<int> pos, bool hasInventory )
|
|
|
: Inventory( pos, hasInventory )
|
|
@@ -32,6 +35,19 @@ Block::Block( const BlockType* zType, ItemType* zTool, Framework::Vec3<int> pos,
|
|
|
Block::~Block()
|
|
|
{}
|
|
|
|
|
|
+void Block::onDestroy()
|
|
|
+{
|
|
|
+ Item* blockItem = zType->getItemFromBlock( this );
|
|
|
+ if( blockItem )
|
|
|
+ {
|
|
|
+ ItemEntity* itemEntity = new ItemEntity( location + Framework::Vec3<float>( 0.5f, 0.5f, 0.5f ), dimensionId, Game::INSTANCE->getNextEntityId() );
|
|
|
+ ItemStack* stack = new ItemStack( blockItem, 1, blockItem->getMaxStackSize() );
|
|
|
+ itemEntity->unsaveAddItem( stack, NO_DIRECTION );
|
|
|
+ stack->release();
|
|
|
+ Game::INSTANCE->requestWorldUpdate( new AddEntityUpdate( itemEntity, dimensionId ) );
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void Block::tick( TickQueue* zQueue )
|
|
|
{
|
|
|
if( wasTicked )
|
|
@@ -192,7 +208,7 @@ void Block::setHP( float hp )
|
|
|
}
|
|
|
}
|
|
|
Game::INSTANCE->requestWorldUpdate( new BlockRemovedUpdate( getPos(), dimensionId ) );
|
|
|
- // TODO: generate item stacks and drop them
|
|
|
+ onDestroy();
|
|
|
}
|
|
|
else
|
|
|
requestTransmission();
|