summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Barney <samjbarney@gmail.com>2015-07-06 23:41:08 +0200
committerSamuel Barney <samjbarney@gmail.com>2015-07-06 23:41:08 +0200
commit2faff189d41959bdc6ed8a70a2a29cb6915302f3 (patch)
treedd5ebf1c35a179719f97012dc3c6bd267fd72db5
parentMerge pull request #2224 from cuberite/ChunkQueueCollapsing (diff)
downloadcuberite-2faff189d41959bdc6ed8a70a2a29cb6915302f3.tar
cuberite-2faff189d41959bdc6ed8a70a2a29cb6915302f3.tar.gz
cuberite-2faff189d41959bdc6ed8a70a2a29cb6915302f3.tar.bz2
cuberite-2faff189d41959bdc6ed8a70a2a29cb6915302f3.tar.lz
cuberite-2faff189d41959bdc6ed8a70a2a29cb6915302f3.tar.xz
cuberite-2faff189d41959bdc6ed8a70a2a29cb6915302f3.tar.zst
cuberite-2faff189d41959bdc6ed8a70a2a29cb6915302f3.zip
-rw-r--r--src/World.cpp98
1 files changed, 85 insertions, 13 deletions
diff --git a/src/World.cpp b/src/World.cpp
index a1e392fd1..83a8b6c10 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -59,6 +59,7 @@
#include "Broadcaster.h"
#include "SpawnPrepare.h"
+#include "FastRandom.h"
@@ -1465,6 +1466,7 @@ void cWorld::GrowTreeImage(const sSetBlockVector & a_Blocks)
bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsByBonemeal)
{
+ cFastRandom random;
BLOCKTYPE BlockType;
NIBBLETYPE BlockMeta;
GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta);
@@ -1478,10 +1480,19 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy
}
if (BlockMeta < 7)
{
- FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, 7);
+ if (!a_IsByBonemeal)
+ {
+ ++BlockMeta;
+ }
+ else
+ {
+ BlockMeta += random.NextInt(4) + 2;
+ BlockMeta = std::min(BlockMeta, static_cast<NIBBLETYPE>(7));
+ }
+ FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta);
BroadcastSoundParticleEffect(2005, a_BlockX, a_BlockY, a_BlockZ, 0);
}
- return true;
+ return BlockMeta == 7;
}
case E_BLOCK_COCOA_POD:
@@ -1495,7 +1506,7 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy
FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, (NIBBLETYPE) (GrowState << 2 | TypeMeta));
BroadcastSoundParticleEffect(2005, a_BlockX, a_BlockY, a_BlockZ, 0);
}
- return true;
+ return GrowState == 2;
}
case E_BLOCK_CROPS:
@@ -1506,10 +1517,19 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy
}
if (BlockMeta < 7)
{
- FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, 7);
+ if (!a_IsByBonemeal)
+ {
+ ++BlockMeta;
+ }
+ else
+ {
+ BlockMeta += random.NextInt(4) + 2;
+ BlockMeta = std::min(BlockMeta, static_cast<NIBBLETYPE>(7));
+ }
+ FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta);
BroadcastSoundParticleEffect(2005, a_BlockX, a_BlockY, a_BlockZ, 0);
}
- return true;
+ return BlockMeta == 7;
}
case E_BLOCK_MELON_STEM:
@@ -1520,7 +1540,17 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy
{
return false;
}
- FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, 7);
+
+ if (!a_IsByBonemeal)
+ {
+ ++BlockMeta;
+ }
+ else
+ {
+ BlockMeta += random.NextInt(4) + 2;
+ BlockMeta = std::min(BlockMeta, static_cast<NIBBLETYPE>(7));
+ }
+ FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta);
BroadcastSoundParticleEffect(2005, a_BlockX, a_BlockY, a_BlockZ, 0);
}
else
@@ -1531,7 +1561,7 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy
}
GrowMelonPumpkin(a_BlockX, a_BlockY, a_BlockZ, BlockType);
}
- return true;
+ return BlockMeta == 7;
}
case E_BLOCK_POTATOES:
@@ -1542,10 +1572,19 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy
}
if (BlockMeta < 7)
{
- FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, 7);
+ if (!a_IsByBonemeal)
+ {
+ ++BlockMeta;
+ }
+ else
+ {
+ BlockMeta += random.NextInt(4) + 2;
+ BlockMeta = std::min(BlockMeta, static_cast<NIBBLETYPE>(7));
+ }
+ FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta);
BroadcastSoundParticleEffect(2005, a_BlockX, a_BlockY, a_BlockZ, 0);
}
- return true;
+ return BlockMeta == 7;
}
case E_BLOCK_PUMPKIN_STEM:
@@ -1556,7 +1595,17 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy
{
return false;
}
- FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, 7);
+
+ if (!a_IsByBonemeal)
+ {
+ ++BlockMeta;
+ }
+ else
+ {
+ BlockMeta += random.NextInt(4) + 2;
+ BlockMeta = std::min(BlockMeta, static_cast<NIBBLETYPE>(7));
+ }
+ FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, BlockMeta);
BroadcastSoundParticleEffect(2005, a_BlockX, a_BlockY, a_BlockZ, 0);
}
else
@@ -1567,7 +1616,7 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy
}
GrowMelonPumpkin(a_BlockX, a_BlockY, a_BlockZ, BlockType);
}
- return true;
+ return BlockMeta == 7;
}
case E_BLOCK_SAPLING:
@@ -1576,8 +1625,31 @@ bool cWorld::GrowRipePlant(int a_BlockX, int a_BlockY, int a_BlockZ, bool a_IsBy
{
return false;
}
- GrowTreeFromSapling(a_BlockX, a_BlockY, a_BlockZ, BlockMeta);
- return true;
+ NIBBLETYPE TypeMeta = BlockMeta & 0x07;
+ int GrowState = BlockMeta >> 3;
+
+ if (GrowState < 1)
+ {
+ // Non-bonemeal forces a growth, while bonemeal only has a chance of growing it
+ if (!a_IsByBonemeal)
+ {
+ ++GrowState;
+ }
+ else if (random.NextInt(99) < 45)
+ {
+ ++GrowState;
+ }
+
+ FastSetBlock(a_BlockX, a_BlockY, a_BlockZ, BlockType, static_cast<NIBBLETYPE>(GrowState << 3 | TypeMeta));
+ BroadcastSoundParticleEffect(2005, a_BlockX, a_BlockY, a_BlockZ, 0);
+ }
+ else if (random.NextInt(99) < 45)
+ {
+
+ GrowTreeFromSapling(a_BlockX, a_BlockY, a_BlockZ, BlockMeta);
+ return true;
+ }
+ return false;
}
case E_BLOCK_GRASS: