summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/Chunk.cpp29
-rw-r--r--source/MobSpawner.cpp26
-rw-r--r--source/MobSpawner.h4
3 files changed, 37 insertions, 22 deletions
diff --git a/source/Chunk.cpp b/source/Chunk.cpp
index 21401163b..944cf82d9 100644
--- a/source/Chunk.cpp
+++ b/source/Chunk.cpp
@@ -539,14 +539,29 @@ void cChunk::SpawnMobs(cMobSpawner& a_MobSpawner)
// MG TODO: fix the "light" thing, I'm pretty sure that UnboundedRelGetBlock s not returning the right thing
// MG TODO : check that "Level" really means Y
- cEntity* newMob = a_MobSpawner.TryToSpawnHere(BlockType, BlockMeta, BlockType_below, BlockMeta_below, BlockType_above, BlockMeta_above, Biome, Try_Y, MaxNbOfSuccess);
- if (newMob)
+ NIBBLETYPE SkyLight = GetSkyLight(Try_X, Try_Y+1, Try_Z);
+ if (!SkyLight)
+ SkyLight = GetSkyLight(Try_X, Try_Y, Try_Z);
+ if (!SkyLight)
+ SkyLight = GetSkyLight(Try_X, Try_Y - 1, Try_Z);
+
+ NIBBLETYPE BlockLight = GetBlockLight(Try_X, Try_Y+1, Try_Z);
+ if (!BlockLight)
+ BlockLight = GetBlockLight(Try_X, Try_Y, Try_Z);
+ if (!BlockLight)
+ BlockLight = GetBlockLight(Try_X, Try_Y - 1, Try_Z);
+
+ if (IsLightValid())
{
- int WorldX, WorldY, WorldZ;
- PositionToWorldPosition(Try_X, Try_Y, Try_Z, WorldX, WorldY, WorldZ);
- newMob->SetPosition(WorldX, WorldY, WorldZ);
- LOGD("Spawning %s #%i at %d,%d,%d",newMob->GetClass(),newMob->GetUniqueID(),WorldX, WorldY, WorldZ);
- NumberOfSuccess++;
+ cEntity* newMob = a_MobSpawner.TryToSpawnHere(BlockType, BlockMeta, BlockType_below, BlockMeta_below, BlockType_above, BlockMeta_above, SkyLight, BlockLight, Biome, Try_Y, MaxNbOfSuccess);
+ if (newMob)
+ {
+ int WorldX, WorldY, WorldZ;
+ PositionToWorldPosition(Try_X, Try_Y, Try_Z, WorldX, WorldY, WorldZ);
+ newMob->SetPosition(WorldX, WorldY, WorldZ);
+ LOGD("Spawning %s #%i at %d,%d,%d",newMob->GetClass(),newMob->GetUniqueID(),WorldX, WorldY, WorldZ);
+ NumberOfSuccess++;
+ }
}
}
diff --git a/source/MobSpawner.cpp b/source/MobSpawner.cpp
index 1b3796f70..8f21e18f5 100644
--- a/source/MobSpawner.cpp
+++ b/source/MobSpawner.cpp
@@ -124,7 +124,7 @@ cMonster::eType cMobSpawner::ChooseMobType(EMCSBiome a_Biome)
-bool cMobSpawner::CanSpawnHere(cMonster::eType a_MobType, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, BLOCKTYPE a_BlockType_below, NIBBLETYPE a_BlockMeta_below, BLOCKTYPE a_BlockType_above, NIBBLETYPE a_BlockMeta_above, EMCSBiome a_Biome, int a_Level)
+bool cMobSpawner::CanSpawnHere(cMonster::eType a_MobType, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, BLOCKTYPE a_BlockType_below, NIBBLETYPE a_BlockMeta_below, BLOCKTYPE a_BlockType_above, NIBBLETYPE a_BlockMeta_above, NIBBLETYPE a_Skylight, NIBBLETYPE a_Blocklight, EMCSBiome a_Biome, int a_Level)
{
bool toReturn = false;
std::set<cMonster::eType>::iterator itr = m_AllowedTypes.find(a_MobType);
@@ -154,31 +154,31 @@ bool cMobSpawner::CanSpawnHere(cMonster::eType a_MobType, BLOCKTYPE a_BlockType,
if (a_MobType == cMonster::mtChicken || a_MobType == cMonster::mtPig || a_MobType == cMonster::mtCow || a_MobType == cMonster::mtSheep)
{
toReturn = (
- a_BlockType_below == E_BLOCK_GRASS /*&& // MG TODO
- a_LightLevel >= 9 */
+ (a_BlockType_below == E_BLOCK_GRASS) &&
+ (a_Skylight >= 9 )
);
}
else if (a_MobType == cMonster::mtOcelot)
{
toReturn = (
- a_Level >= 62 &&
+ (a_Level >= 62) &&
(
- a_BlockType_below == E_BLOCK_GRASS ||
- a_BlockType_below == E_BLOCK_LEAVES
+ (a_BlockType_below == E_BLOCK_GRASS) ||
+ (a_BlockType_below == E_BLOCK_LEAVES)
) &&
- m_Random.NextInt(3,a_Biome) != 0
+ (m_Random.NextInt(3,a_Biome) != 0)
);
}
else if (a_MobType == cMonster::mtCreeper || a_MobType == cMonster::mtSkeleton || a_MobType == cMonster::mtZombie || a_MobType == cMonster::mtSpider || a_MobType == cMonster::mtEnderman || a_MobType == cMonster::mtZombiePigman)
{
- toReturn = true /*a_LightLevel <= 7 MG TODO*/;
- /*if (a_SunLight) MG TODO
+ toReturn = (a_Skylight <= 7) && (a_Blocklight <= 7);
+ if (a_Skylight)
{
if (m_Random.NextInt(2,a_Biome) != 0)
{
toReturn = false;
}
- }*/
+ }
}
else if (a_MobType == cMonster::mtSlime)
{
@@ -192,7 +192,7 @@ bool cMobSpawner::CanSpawnHere(cMonster::eType a_MobType, BLOCKTYPE a_BlockType,
else
{
LOGD("MG TODO : check I've got a Rule to write for type %d",a_MobType);
- toReturn = true;
+ toReturn = false;
}
}
}
@@ -204,7 +204,7 @@ bool cMobSpawner::CanSpawnHere(cMonster::eType a_MobType, BLOCKTYPE a_BlockType,
-cMonster* cMobSpawner::TryToSpawnHere(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, BLOCKTYPE a_BlockType_below, NIBBLETYPE a_BlockMeta_below, BLOCKTYPE a_BlockType_above, NIBBLETYPE a_BlockMeta_above, EMCSBiome a_Biome, int a_Level, int& a_MaxPackSize)
+cMonster* cMobSpawner::TryToSpawnHere(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, BLOCKTYPE a_BlockType_below, NIBBLETYPE a_BlockMeta_below, BLOCKTYPE a_BlockType_above, NIBBLETYPE a_BlockMeta_above, NIBBLETYPE a_Skylight, NIBBLETYPE a_Blocklight, EMCSBiome a_Biome, int a_Level, int& a_MaxPackSize)
{
cMonster* toReturn = NULL;
if (m_NewPack)
@@ -226,7 +226,7 @@ cMonster* cMobSpawner::TryToSpawnHere(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockM
}
- if (CanSpawnHere(m_MobType, a_BlockType, a_BlockMeta, a_BlockType_below, a_BlockMeta_below, a_BlockType_above, a_BlockMeta_above, a_Biome, a_Level))
+ if (CanSpawnHere(m_MobType, a_BlockType, a_BlockMeta, a_BlockType_below, a_BlockMeta_below, a_BlockType_above, a_BlockMeta_above, a_Skylight, a_Blocklight, a_Biome, a_Level))
{
cMonster * newMob = cMonster::NewMonsterFromType(m_MobType);
if (newMob)
diff --git a/source/MobSpawner.h b/source/MobSpawner.h
index ba2a18f2e..e5b7e9b6b 100644
--- a/source/MobSpawner.h
+++ b/source/MobSpawner.h
@@ -38,7 +38,7 @@ public :
// if this is the first of a Pack : determine the type of monster
// BlockType & BlockMeta are used to decide what kind of Mob can Spawn here
// MaxPackSize is set to the maximal size for a pack this type of mob
- cMonster * TryToSpawnHere(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, BLOCKTYPE a_BlockType_below, NIBBLETYPE a_BlockMeta_below, BLOCKTYPE a_BlockType_above, NIBBLETYPE a_BlockMeta_above, EMCSBiome a_Biome, int a_Level, int& a_MaxPackSize);
+ cMonster * TryToSpawnHere(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, BLOCKTYPE a_BlockType_below, NIBBLETYPE a_BlockMeta_below, BLOCKTYPE a_BlockType_above, NIBBLETYPE a_BlockMeta_above, NIBBLETYPE a_Skylight, NIBBLETYPE a_Blocklight, EMCSBiome a_Biome, int a_Level, int& a_MaxPackSize);
// mark the beginning of a new Pack
// all mobs of the same Pack are the same type
@@ -52,7 +52,7 @@ public :
protected :
// return true if specified type of mob can spawn on specified block
- bool CanSpawnHere(cMonster::eType a_MobType, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, BLOCKTYPE a_BlockType_below, NIBBLETYPE a_BlockMeta_below, BLOCKTYPE a_BlockType_above, NIBBLETYPE a_BlockMeta_above, EMCSBiome a_Biome, int a_Level);
+ bool CanSpawnHere(cMonster::eType a_MobType, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, BLOCKTYPE a_BlockType_below, NIBBLETYPE a_BlockMeta_below, BLOCKTYPE a_BlockType_above, NIBBLETYPE a_BlockMeta_above, NIBBLETYPE a_Skylight, NIBBLETYPE a_Blocklight, EMCSBiome a_Biome, int a_Level);
// return a random type that can spawn on specified biome.
// returns E_ENTITY_TYPE_DONOTUSE if none is possible