Fixed non-natural spawning near player (egg, breeding, etc.)
This commit is contained in:
parent
5ca2f4fd0c
commit
ac2c79f797
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "MobSpawner.h"
|
#include "MobSpawner.h"
|
||||||
#include "Mobs/IncludeAllMonsters.h"
|
#include "Mobs/IncludeAllMonsters.h"
|
||||||
|
#include "World.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -128,201 +129,210 @@ eMonsterType cMobSpawner::ChooseMobType(EMCSBiome a_Biome)
|
|||||||
|
|
||||||
bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, eMonsterType a_MobType, EMCSBiome a_Biome)
|
bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_RelZ, eMonsterType a_MobType, EMCSBiome a_Biome)
|
||||||
{
|
{
|
||||||
cFastRandom Random;
|
if (a_Chunk == nullptr)
|
||||||
BLOCKTYPE TargetBlock = E_BLOCK_AIR;
|
|
||||||
if (a_Chunk->UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, TargetBlock))
|
|
||||||
{
|
{
|
||||||
if ((a_RelY >= cChunkDef::Height - 1) || (a_RelY <= 0))
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
cFastRandom Random;
|
||||||
|
BLOCKTYPE TargetBlock = a_Chunk->GetBlock(a_RelX, a_RelY, a_RelZ);
|
||||||
|
|
||||||
|
cPlayer * a_Closest_Player = a_Chunk->GetWorld()->FindClosestPlayer(a_Chunk->PositionToWorldPosition(a_RelX, a_RelY, a_RelZ), 24);
|
||||||
|
if (a_Closest_Player != nullptr) // Too close to a player, bail out
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((a_RelY >= cChunkDef::Height - 1) || (a_RelY <= 0))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
NIBBLETYPE BlockLight = a_Chunk->GetBlockLight(a_RelX, a_RelY, a_RelZ);
|
||||||
|
NIBBLETYPE SkyLight = a_Chunk->GetSkyLight(a_RelX, a_RelY, a_RelZ);
|
||||||
|
BLOCKTYPE BlockAbove = a_Chunk->GetBlock(a_RelX, a_RelY + 1, a_RelZ);
|
||||||
|
BLOCKTYPE BlockBelow = a_Chunk->GetBlock(a_RelX, a_RelY - 1, a_RelZ);
|
||||||
|
|
||||||
|
SkyLight = a_Chunk->GetTimeAlteredLight(SkyLight);
|
||||||
|
|
||||||
|
switch (a_MobType)
|
||||||
|
{
|
||||||
|
case mtGuardian:
|
||||||
{
|
{
|
||||||
return false;
|
return IsBlockWater(TargetBlock) && (a_RelY >= 45) && (a_RelY <= 62);
|
||||||
}
|
}
|
||||||
|
|
||||||
NIBBLETYPE BlockLight = a_Chunk->GetBlockLight(a_RelX, a_RelY, a_RelZ);
|
case mtSquid:
|
||||||
NIBBLETYPE SkyLight = a_Chunk->GetSkyLight(a_RelX, a_RelY, a_RelZ);
|
|
||||||
BLOCKTYPE BlockAbove = a_Chunk->GetBlock(a_RelX, a_RelY + 1, a_RelZ);
|
|
||||||
BLOCKTYPE BlockBelow = a_Chunk->GetBlock(a_RelX, a_RelY - 1, a_RelZ);
|
|
||||||
|
|
||||||
SkyLight = a_Chunk->GetTimeAlteredLight(SkyLight);
|
|
||||||
|
|
||||||
switch (a_MobType)
|
|
||||||
{
|
{
|
||||||
case mtGuardian:
|
return IsBlockWater(TargetBlock) && (a_RelY >= 45) && (a_RelY <= 62);
|
||||||
{
|
}
|
||||||
return IsBlockWater(TargetBlock) && (a_RelY >= 45) && (a_RelY <= 62);
|
|
||||||
}
|
|
||||||
|
|
||||||
case mtSquid:
|
case mtBat:
|
||||||
{
|
{
|
||||||
return IsBlockWater(TargetBlock) && (a_RelY >= 45) && (a_RelY <= 62);
|
return (a_RelY <= 63) && (BlockLight <= 4) && (SkyLight <= 4) && (TargetBlock == E_BLOCK_AIR) && !cBlockInfo::IsTransparent(BlockAbove);
|
||||||
}
|
}
|
||||||
|
|
||||||
case mtBat:
|
case mtChicken:
|
||||||
{
|
case mtCow:
|
||||||
return (a_RelY <= 63) && (BlockLight <= 4) && (SkyLight <= 4) && (TargetBlock == E_BLOCK_AIR) && !cBlockInfo::IsTransparent(BlockAbove);
|
case mtPig:
|
||||||
}
|
case mtHorse:
|
||||||
|
case mtRabbit:
|
||||||
|
case mtSheep:
|
||||||
|
{
|
||||||
|
return (
|
||||||
|
(TargetBlock == E_BLOCK_AIR) &&
|
||||||
|
(BlockAbove == E_BLOCK_AIR) &&
|
||||||
|
(!cBlockInfo::IsTransparent(BlockBelow)) &&
|
||||||
|
(BlockBelow == E_BLOCK_GRASS) &&
|
||||||
|
(SkyLight >= 9)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
case mtChicken:
|
case mtOcelot:
|
||||||
case mtCow:
|
{
|
||||||
case mtPig:
|
return (
|
||||||
case mtHorse:
|
(TargetBlock == E_BLOCK_AIR) &&
|
||||||
case mtRabbit:
|
(BlockAbove == E_BLOCK_AIR) &&
|
||||||
case mtSheep:
|
(
|
||||||
{
|
(BlockBelow == E_BLOCK_GRASS) || (BlockBelow == E_BLOCK_LEAVES) || (BlockBelow == E_BLOCK_NEW_LEAVES)
|
||||||
return (
|
) &&
|
||||||
(TargetBlock == E_BLOCK_AIR) &&
|
(a_RelY >= 62) &&
|
||||||
(BlockAbove == E_BLOCK_AIR) &&
|
(Random.NextInt(3) != 0)
|
||||||
(!cBlockInfo::IsTransparent(BlockBelow)) &&
|
);
|
||||||
(BlockBelow == E_BLOCK_GRASS) &&
|
}
|
||||||
(SkyLight >= 9)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
case mtOcelot:
|
case mtEnderman:
|
||||||
|
{
|
||||||
|
if (a_RelY < 250)
|
||||||
{
|
{
|
||||||
return (
|
BLOCKTYPE BlockTop = a_Chunk->GetBlock(a_RelX, a_RelY + 2, a_RelZ);
|
||||||
(TargetBlock == E_BLOCK_AIR) &&
|
if (BlockTop == E_BLOCK_AIR)
|
||||||
(BlockAbove == E_BLOCK_AIR) &&
|
|
||||||
(
|
|
||||||
(BlockBelow == E_BLOCK_GRASS) || (BlockBelow == E_BLOCK_LEAVES) || (BlockBelow == E_BLOCK_NEW_LEAVES)
|
|
||||||
) &&
|
|
||||||
(a_RelY >= 62) &&
|
|
||||||
(Random.NextInt(3) != 0)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
case mtEnderman:
|
|
||||||
{
|
|
||||||
if (a_RelY < 250)
|
|
||||||
{
|
{
|
||||||
BLOCKTYPE BlockTop = a_Chunk->GetBlock(a_RelX, a_RelY + 2, a_RelZ);
|
BlockTop = a_Chunk->GetBlock(a_RelX, a_RelY + 3, a_RelZ);
|
||||||
if (BlockTop == E_BLOCK_AIR)
|
return (
|
||||||
{
|
(TargetBlock == E_BLOCK_AIR) &&
|
||||||
BlockTop = a_Chunk->GetBlock(a_RelX, a_RelY + 3, a_RelZ);
|
(BlockAbove == E_BLOCK_AIR) &&
|
||||||
return (
|
(BlockTop == E_BLOCK_AIR) &&
|
||||||
(TargetBlock == E_BLOCK_AIR) &&
|
(!cBlockInfo::IsTransparent(BlockBelow)) &&
|
||||||
(BlockAbove == E_BLOCK_AIR) &&
|
(SkyLight <= 7) &&
|
||||||
(BlockTop == E_BLOCK_AIR) &&
|
(BlockLight <= 7)
|
||||||
(!cBlockInfo::IsTransparent(BlockBelow)) &&
|
);
|
||||||
(SkyLight <= 7) &&
|
|
||||||
(BlockLight <= 7)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case mtSpider:
|
case mtSpider:
|
||||||
|
{
|
||||||
|
bool CanSpawn = true;
|
||||||
|
bool HasFloor = false;
|
||||||
|
for (int x = 0; x < 2; ++x)
|
||||||
{
|
{
|
||||||
bool CanSpawn = true;
|
for (int z = 0; z < 2; ++z)
|
||||||
bool HasFloor = false;
|
|
||||||
for (int x = 0; x < 2; ++x)
|
|
||||||
{
|
{
|
||||||
for (int z = 0; z < 2; ++z)
|
CanSpawn = a_Chunk->UnboundedRelGetBlockType(a_RelX + x, a_RelY, a_RelZ + z, TargetBlock);
|
||||||
|
CanSpawn = CanSpawn && (TargetBlock == E_BLOCK_AIR);
|
||||||
|
if (!CanSpawn)
|
||||||
{
|
{
|
||||||
CanSpawn = a_Chunk->UnboundedRelGetBlockType(a_RelX + x, a_RelY, a_RelZ + z, TargetBlock);
|
return false;
|
||||||
CanSpawn = CanSpawn && (TargetBlock == E_BLOCK_AIR);
|
|
||||||
if (!CanSpawn)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
HasFloor = (
|
|
||||||
HasFloor ||
|
|
||||||
(
|
|
||||||
a_Chunk->UnboundedRelGetBlockType(a_RelX + x, a_RelY - 1, a_RelZ + z, TargetBlock) &&
|
|
||||||
!cBlockInfo::IsTransparent(TargetBlock)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
HasFloor = (
|
||||||
|
HasFloor ||
|
||||||
|
(
|
||||||
|
a_Chunk->UnboundedRelGetBlockType(a_RelX + x, a_RelY - 1, a_RelZ + z, TargetBlock) &&
|
||||||
|
!cBlockInfo::IsTransparent(TargetBlock)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return CanSpawn && HasFloor && (SkyLight <= 7) && (BlockLight <= 7);
|
|
||||||
}
|
}
|
||||||
|
return CanSpawn && HasFloor && (SkyLight <= 7) && (BlockLight <= 7);
|
||||||
|
}
|
||||||
|
|
||||||
case mtCaveSpider:
|
case mtCaveSpider:
|
||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
(TargetBlock == E_BLOCK_AIR) &&
|
(TargetBlock == E_BLOCK_AIR) &&
|
||||||
(!cBlockInfo::IsTransparent(BlockBelow)) &&
|
(!cBlockInfo::IsTransparent(BlockBelow)) &&
|
||||||
(SkyLight <= 7) &&
|
(SkyLight <= 7) &&
|
||||||
(BlockLight <= 7) &&
|
(BlockLight <= 7) &&
|
||||||
(Random.NextInt(2) == 0)
|
(Random.NextInt(2) == 0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
case mtCreeper:
|
case mtCreeper:
|
||||||
case mtSkeleton:
|
case mtSkeleton:
|
||||||
case mtZombie:
|
case mtZombie:
|
||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
(TargetBlock == E_BLOCK_AIR) &&
|
(TargetBlock == E_BLOCK_AIR) &&
|
||||||
(BlockAbove == E_BLOCK_AIR) &&
|
(BlockAbove == E_BLOCK_AIR) &&
|
||||||
(!cBlockInfo::IsTransparent(BlockBelow)) &&
|
(!cBlockInfo::IsTransparent(BlockBelow)) &&
|
||||||
(SkyLight <= 7) &&
|
(SkyLight <= 7) &&
|
||||||
(BlockLight <= 7) &&
|
(BlockLight <= 7) &&
|
||||||
(Random.NextInt(2) == 0)
|
(Random.NextInt(2) == 0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
case mtMagmaCube:
|
case mtMagmaCube:
|
||||||
case mtSlime:
|
case mtSlime:
|
||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
(TargetBlock == E_BLOCK_AIR) &&
|
(TargetBlock == E_BLOCK_AIR) &&
|
||||||
(BlockAbove == E_BLOCK_AIR) &&
|
(BlockAbove == E_BLOCK_AIR) &&
|
||||||
(!cBlockInfo::IsTransparent(BlockBelow)) &&
|
(!cBlockInfo::IsTransparent(BlockBelow)) &&
|
||||||
(
|
(
|
||||||
(a_RelY <= 40) || (a_Biome == biSwampland)
|
(a_RelY <= 40) || (a_Biome == biSwampland)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
case mtGhast:
|
case mtGhast:
|
||||||
case mtZombiePigman:
|
case mtZombiePigman:
|
||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
(TargetBlock == E_BLOCK_AIR) &&
|
(TargetBlock == E_BLOCK_AIR) &&
|
||||||
(BlockAbove == E_BLOCK_AIR) &&
|
(BlockAbove == E_BLOCK_AIR) &&
|
||||||
(!cBlockInfo::IsTransparent(BlockBelow)) &&
|
(!cBlockInfo::IsTransparent(BlockBelow)) &&
|
||||||
(Random.NextInt(20) == 0)
|
(Random.NextInt(20) == 0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
case mtWolf:
|
case mtWolf:
|
||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
(TargetBlock == E_BLOCK_GRASS) &&
|
(TargetBlock == E_BLOCK_GRASS) &&
|
||||||
(BlockAbove == E_BLOCK_AIR) &&
|
(BlockAbove == E_BLOCK_AIR) &&
|
||||||
(
|
(
|
||||||
(a_Biome == biTaiga) ||
|
(a_Biome == biTaiga) ||
|
||||||
(a_Biome == biTaigaHills) ||
|
(a_Biome == biTaigaHills) ||
|
||||||
(a_Biome == biForest) ||
|
(a_Biome == biForest) ||
|
||||||
(a_Biome == biForestHills) ||
|
(a_Biome == biForestHills) ||
|
||||||
(a_Biome == biColdTaiga) ||
|
(a_Biome == biColdTaiga) ||
|
||||||
(a_Biome == biColdTaigaHills) ||
|
(a_Biome == biColdTaigaHills) ||
|
||||||
(a_Biome == biTaigaM) ||
|
(a_Biome == biTaigaM) ||
|
||||||
(a_Biome == biMegaTaiga) ||
|
(a_Biome == biMegaTaiga) ||
|
||||||
(a_Biome == biMegaTaigaHills)
|
(a_Biome == biMegaTaigaHills)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
case mtMooshroom:
|
case mtMooshroom:
|
||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
(TargetBlock == E_BLOCK_AIR) &&
|
(TargetBlock == E_BLOCK_AIR) &&
|
||||||
(BlockAbove == E_BLOCK_AIR) &&
|
(BlockAbove == E_BLOCK_AIR) &&
|
||||||
(BlockBelow == E_BLOCK_MYCELIUM) &&
|
(BlockBelow == E_BLOCK_MYCELIUM) &&
|
||||||
(
|
(
|
||||||
(a_Biome == biMushroomShore) ||
|
(a_Biome == biMushroomShore) ||
|
||||||
(a_Biome == biMushroomIsland)
|
(a_Biome == biMushroomIsland)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
LOGD("MG TODO: Write spawning rule for mob type %d", a_MobType);
|
LOGD("MG TODO: Write spawning rule for mob type %d", a_MobType);
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -3504,15 +3504,6 @@ UInt32 cWorld::SpawnMobFinalize(cMonster * a_Monster)
|
|||||||
return cEntity::INVALID_ID;
|
return cEntity::INVALID_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
cPlayer * a_Closest_Player = FindClosestPlayer(a_Monster->GetPosition(), 24);
|
|
||||||
if (a_Closest_Player != nullptr) // Too close to a player, bail out.
|
|
||||||
{
|
|
||||||
delete a_Monster;
|
|
||||||
a_Monster = nullptr;
|
|
||||||
return cEntity::INVALID_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Initialize the monster into the current world.
|
// Initialize the monster into the current world.
|
||||||
if (!a_Monster->Initialize(*this))
|
if (!a_Monster->Initialize(*this))
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user