diff options
author | Tycho Bickerstaff <work.tycho@gmail.com> | 2013-12-10 17:53:46 +0100 |
---|---|---|
committer | Tycho Bickerstaff <work.tycho@gmail.com> | 2013-12-10 17:53:46 +0100 |
commit | 5d2311bcff631bcb9849754318b3469af6f7e4fe (patch) | |
tree | 79cb23ac444cb09a4b7b69858651d453dc6ac1a8 /src | |
parent | moved deafult action into deafult clause at src/Generating/DistortedHeightmap.cpp line 741 (diff) | |
parent | Merge pull request #412 from mc-server/fixes (diff) | |
download | cuberite-5d2311bcff631bcb9849754318b3469af6f7e4fe.tar cuberite-5d2311bcff631bcb9849754318b3469af6f7e4fe.tar.gz cuberite-5d2311bcff631bcb9849754318b3469af6f7e4fe.tar.bz2 cuberite-5d2311bcff631bcb9849754318b3469af6f7e4fe.tar.lz cuberite-5d2311bcff631bcb9849754318b3469af6f7e4fe.tar.xz cuberite-5d2311bcff631bcb9849754318b3469af6f7e4fe.tar.zst cuberite-5d2311bcff631bcb9849754318b3469af6f7e4fe.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Blocks/BlockHandler.cpp | 5 | ||||
-rw-r--r-- | src/Simulator/FloodyFluidSimulator.cpp | 18 | ||||
-rw-r--r-- | src/Simulator/RedstoneSimulator.cpp | 69 | ||||
-rw-r--r-- | src/Simulator/RedstoneSimulator.h | 9 | ||||
-rw-r--r-- | src/World.cpp | 8 |
5 files changed, 96 insertions, 13 deletions
diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp index 99559ed02..fde6bd803 100644 --- a/src/Blocks/BlockHandler.cpp +++ b/src/Blocks/BlockHandler.cpp @@ -376,9 +376,8 @@ void cBlockHandler::DropBlock(cWorld * a_World, cEntity * a_Digger, int a_BlockX MicroZ = a_BlockZ + 0.5; // Add random offset second (this causes pickups to spawn inside blocks most times, it's a little buggy) - //MicroX += (int)(r1.randInt(16) + r1.randInt(16) - 16); - //MicroY += (int)(r1.randInt(16) + r1.randInt(16) - 16); - //MicroZ += (int)(r1.randInt(16) + r1.randInt(16) - 16); + MicroX += r1.rand(1) - 0.5; + MicroZ += r1.rand(1) - 0.5; a_World->SpawnItemPickups(Pickups, MicroX, MicroY, MicroZ); } diff --git a/src/Simulator/FloodyFluidSimulator.cpp b/src/Simulator/FloodyFluidSimulator.cpp index d204a1f8b..58e5d614b 100644 --- a/src/Simulator/FloodyFluidSimulator.cpp +++ b/src/Simulator/FloodyFluidSimulator.cpp @@ -224,7 +224,14 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i ItemTypeToString(NewBlock).c_str() ); a_NearChunk->UnboundedRelSetBlock(a_RelX, a_RelY, a_RelZ, NewBlock, 0); - m_World.BroadcastSoundEffect("random.fizz", a_RelX * 8, a_RelY * 8, a_RelZ * 8, 0.5f, 1.5f); + + int BaseX = a_NearChunk->GetPosX() * cChunkDef::Width; + int BaseZ = a_NearChunk->GetPosZ() * cChunkDef::Width; + + BaseX += a_RelX; + BaseZ += a_RelZ; + + a_NearChunk->BroadcastSoundEffect("random.fizz", BaseX * 8, a_RelY * 8, BaseZ * 8, 0.5f, 1.5f); return; } } @@ -238,7 +245,14 @@ void cFloodyFluidSimulator::SpreadToNeighbor(cChunk * a_NearChunk, int a_RelX, i a_RelX, a_RelY, a_RelZ, ItemTypeToString(NewBlock).c_str() ); a_NearChunk->UnboundedRelSetBlock(a_RelX, a_RelY, a_RelZ, NewBlock, 0); - m_World.BroadcastSoundEffect("random.fizz", a_RelX * 8, a_RelY * 8, a_RelZ * 8, 0.5f, 1.5f); + + int BaseX = a_NearChunk->GetPosX() * cChunkDef::Width; + int BaseZ = a_NearChunk->GetPosZ() * cChunkDef::Width; + + BaseX += a_RelX; + BaseZ += a_RelZ; + + a_NearChunk->BroadcastSoundEffect("random.fizz", BaseX * 8, a_RelY * 8, BaseZ * 8, 0.5f, 1.5f); return; } } diff --git a/src/Simulator/RedstoneSimulator.cpp b/src/Simulator/RedstoneSimulator.cpp index 63e4f04a8..9328b9fcb 100644 --- a/src/Simulator/RedstoneSimulator.cpp +++ b/src/Simulator/RedstoneSimulator.cpp @@ -285,7 +285,7 @@ void cRedstoneSimulator::HandleRedstoneTorch(int a_BlockX, int a_BlockY, int a_B if (AreCoordsPowered(X, Y, Z)) { // There was a match, torch goes off - m_World.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_OFF, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)); + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_OFF, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)); return; } @@ -335,7 +335,7 @@ void cRedstoneSimulator::HandleRedstoneTorch(int a_BlockX, int a_BlockY, int a_B } // Block torch on not powered, can be turned on again! - m_World.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_ON, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)); + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_TORCH_ON, m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ)); } } @@ -420,6 +420,7 @@ void cRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_BlockY, int a_Bl } else { + NIBBLETYPE MetaToSet = 0; NIBBLETYPE MyMeta = m_World.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); int TimesMetaSmaller = 0, TimesFoundAWire = 0; @@ -439,7 +440,7 @@ void cRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_BlockY, int a_Bl // >= to fix a bug where wires bordering each other with the same power level will appear (in terms of meta) to power each other, when they aren't actually in the powered list if (SurroundMeta >= MyMeta) { - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, SurroundMeta - 1); + MetaToSet = SurroundMeta - 1; // To improve performance } } @@ -459,6 +460,10 @@ void cRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_BlockY, int a_Bl m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 0); return; // No need to process block power sets because self not powered } + else + { + m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, MetaToSet); + } SetBlockPowered(a_BlockX, a_BlockY - 1, a_BlockZ, a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE); // Power block beneath } @@ -538,6 +543,37 @@ void cRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_BlockY, int { if (!IsOn) { + bool ShouldCreate = true; + // If repeater is not on already (and is POWERED), see if it is in repeater list, or has reached delay time + for (RepeatersDelayList::iterator itr = m_RepeatersDelayList.begin(); itr != m_RepeatersDelayList.end(); itr++) + { + if (itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + { + if (itr->a_DelayTicks <= itr->a_ElapsedTicks) // Shouldn't need <=; just in case something happens + { + m_RepeatersDelayList.erase(itr); + ShouldCreate = false; + break; // Delay time reached, break straight out, and into the powering code + } + else + { + itr->a_ElapsedTicks++; // Increment elapsed ticks and quit + return; + } + } + } + + if (ShouldCreate) + { + // Self not in list, add self to list + sRepeatersDelayList RC; + RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); + RC.a_DelayTicks = ((a_Meta & 0xC) >> 0x2) + 1; // Gets the top two bits (delay time), shifts them into the lower two bits, and adds one (meta 0 = 1 tick; 1 = 2 etc.) + RC.a_ElapsedTicks = 0; + m_RepeatersDelayList.push_back(RC); + return; + } + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_ON, a_Meta); // Only set if not on; SetBlock otherwise server doesn't set it in time for SimulateChunk's invalidation } switch (a_Meta & 0x3) // We only want the direction (bottom) bits @@ -572,7 +608,32 @@ void cRedstoneSimulator::HandleRedstoneRepeater(int a_BlockX, int a_BlockY, int { if (IsOn) { - m_World.FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_OFF, a_Meta); + // If repeater is not off already (and is NOT POWERED), see if it is in repeater list, or has reached delay time + for (RepeatersDelayList::iterator itr = m_RepeatersDelayList.begin(); itr != m_RepeatersDelayList.end(); itr++) + { + if (itr->a_BlockPos.Equals(Vector3i(a_BlockX, a_BlockY, a_BlockZ))) + { + if (itr->a_DelayTicks <= itr->a_ElapsedTicks) // Shouldn't need <=; just in case something happens + { + m_RepeatersDelayList.erase(itr); + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_REPEATER_OFF, a_Meta); + return; + } + else + { + itr->a_ElapsedTicks++; // Increment elapsed ticks and quit + return; + } + } + } + + // Self not in list, add self to list + sRepeatersDelayList RC; + RC.a_BlockPos = Vector3i(a_BlockX, a_BlockY, a_BlockZ); + RC.a_DelayTicks = ((a_Meta & 0xC) >> 0x2) + 1; + RC.a_ElapsedTicks = 0; + m_RepeatersDelayList.push_back(RC); + return; } } } diff --git a/src/Simulator/RedstoneSimulator.h b/src/Simulator/RedstoneSimulator.h index e094150e8..1d85c0634 100644 --- a/src/Simulator/RedstoneSimulator.h +++ b/src/Simulator/RedstoneSimulator.h @@ -56,14 +56,23 @@ private: Vector3i a_BlockPos; bool WasLastStatePowered; }; + + struct sRepeatersDelayList + { + Vector3i a_BlockPos; + short a_DelayTicks; + short a_ElapsedTicks; + }; typedef std::vector <sPoweredBlocks> PoweredBlocksList; typedef std::vector <sLinkedPoweredBlocks> LinkedBlocksList; typedef std::vector <sSimulatedPlayerToggleableList> SimulatedPlayerToggleableList; + typedef std::vector <sRepeatersDelayList> RepeatersDelayList; PoweredBlocksList m_PoweredBlocks; LinkedBlocksList m_LinkedPoweredBlocks; SimulatedPlayerToggleableList m_SimulatedPlayerToggleableBlocks; + RepeatersDelayList m_RepeatersDelayList; virtual void AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) override; diff --git a/src/World.cpp b/src/World.cpp index eecd02027..564905d33 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1588,7 +1588,7 @@ bool cWorld::WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBlock void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double a_BlockY, double a_BlockZ, double a_FlyAwaySpeed, bool IsPlayerCreated) { MTRand r1; - a_FlyAwaySpeed /= 1000; // Pre-divide, so that we don't have to divide each time inside the loop + a_FlyAwaySpeed /= 100; // Pre-divide, so that we don't have to divide each time inside the loop for (cItems::const_iterator itr = a_Pickups.begin(); itr != a_Pickups.end(); ++itr) { if (!IsValidItem(itr->m_ItemType)) @@ -1597,9 +1597,9 @@ void cWorld::SpawnItemPickups(const cItems & a_Pickups, double a_BlockX, double continue; } - float SpeedX = (float)(a_FlyAwaySpeed * (r1.randInt(1000) - 500)); - float SpeedY = (float)(a_FlyAwaySpeed * (r1.randInt(1000) - 500)); - float SpeedZ = (float)(a_FlyAwaySpeed * (r1.randInt(1000) - 500)); + float SpeedX = (float)(a_FlyAwaySpeed * (r1.randInt(10) - 5)); + float SpeedY = (float)(a_FlyAwaySpeed * r1.randInt(50)); + float SpeedZ = (float)(a_FlyAwaySpeed * (r1.randInt(10) - 5)); cPickup * Pickup = new cPickup( a_BlockX, a_BlockY, a_BlockZ, |