From 1cca9b13b3d320ff767cfc552413265b2ef6e0d6 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Wed, 6 Jun 2012 20:18:50 +0000 Subject: Item-dropping code rewritten and centralized - now there's only one place to modify if we want to split or merge same-item drops: cWorld:SpawnItemPickups(). Also, mined blocks can now drop more items, and they recognize if they're being mined by the correct tool. git-svn-id: http://mc-server.googlecode.com/svn/trunk@561 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cWorld.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-) (limited to 'source/cWorld.cpp') diff --git a/source/cWorld.cpp b/source/cWorld.cpp index 91b7b69bc..5cb9c5f0d 100644 --- a/source/cWorld.cpp +++ b/source/cWorld.cpp @@ -938,6 +938,48 @@ char cWorld::GetBlockSkyLight( int a_X, int a_Y, int a_Z ) +void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed) +{ + MTRand r1; + a_FlyAwaySpeed /= 1000; // Pre-divide, so that we can don't have to divide each time inside the loop + for (cItems::const_iterator itr = a_Pickups.begin(); itr != a_Pickups.end(); ++itr) + { + float SpeedX = (float)(a_FlyAwaySpeed * (r1.randInt(1000) - 500)); + float SpeedY = (float)(a_FlyAwaySpeed * r1.randInt(1000)); + float SpeedZ = (float)(a_FlyAwaySpeed * (r1.randInt(1000) - 500)); + cPickup * Pickup = new cPickup( + (int)(a_BlockX * 32) + r1.randInt(16) + r1.randInt(16), + (int)(a_BlockY * 32) + r1.randInt(16) + r1.randInt(16), + (int)(a_BlockZ * 32) + r1.randInt(16) + r1.randInt(16), + *itr, SpeedX, SpeedY, SpeedZ + ); + Pickup->Initialize(this); + } +} + + + + + +void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_SpeedX, double a_SpeedY, double a_SpeedZ) +{ + MTRand r1; + for (cItems::const_iterator itr = a_Pickups.begin(); itr != a_Pickups.end(); ++itr) + { + cPickup * Pickup = new cPickup( + (int)(a_BlockX * 32) + r1.randInt(16) + r1.randInt(16), + (int)(a_BlockY * 32) + r1.randInt(16) + r1.randInt(16), + (int)(a_BlockZ * 32) + r1.randInt(16) + r1.randInt(16), + *itr, (float)a_SpeedX, (float)a_SpeedY, (float)a_SpeedZ + ); + Pickup->Initialize(this); + } +} + + + + + void cWorld::ReplaceBlocks(const sSetBlockVector & a_Blocks, BLOCKTYPE a_FilterBlockType) { m_ChunkMap->ReplaceBlocks(a_Blocks, a_FilterBlockType); @@ -956,14 +998,9 @@ bool cWorld::GetBlocks(sSetBlockVector & a_Blocks, bool a_ContinueOnFailure) -bool cWorld::DigBlock( int a_X, int a_Y, int a_Z, cItem & a_PickupItem ) +bool cWorld::DigBlock( int a_X, int a_Y, int a_Z) { - bool res = m_ChunkMap->DigBlock(a_X, a_Y, a_Z, a_PickupItem); - if (res) - { - GetSimulatorManager()->WakeUp(a_X, a_Y, a_Z); - } - return res; + return m_ChunkMap->DigBlock(a_X, a_Y, a_Z); } -- cgit v1.2.3