1
0

Optimized cBlockFarmlandHandler in wet weather.

The area isn't read at all when the weather is wet, since it isn't needed.
This commit is contained in:
madmaxoft 2013-10-04 08:39:59 +02:00
parent dcea29ec30
commit 8fb80b6369

View File

@ -30,9 +30,16 @@ public:
virtual void OnUpdate(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override virtual void OnUpdate(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ) override
{ {
// TODO: Rain hydrates farmland, too. Check world weather, don't search for water if raining. bool Found = false;
// NOTE: The desert biomes do not get precipitation, so another check needs to be made.
int Biome = a_World->GetBiomeAt(a_BlockX, a_BlockZ);
if (a_World->IsWeatherWet() && (Biome != biDesert) && (Biome != biDesertHills))
{
// Rain hydrates farmland, too, except in Desert biomes.
Found = true;
}
else
{
// Search for water in a close proximity: // Search for water in a close proximity:
// Ref.: http://www.minecraftwiki.net/wiki/Farmland#Hydrated_Farmland_Tiles // Ref.: http://www.minecraftwiki.net/wiki/Farmland#Hydrated_Farmland_Tiles
cBlockArea Area; cBlockArea Area;
@ -41,11 +48,7 @@ public:
// Too close to the world edge, cannot check surroudnings; don't tick at all // Too close to the world edge, cannot check surroudnings; don't tick at all
return; return;
} }
bool Found = false;
int Biome = a_World->GetBiomeAt(a_BlockX, a_BlockZ);
if (a_World->GetWeather() != eWeather_Rain || Biome == biDesert || Biome == biDesertHills)
{
int NumBlocks = Area.GetBlockCount(); int NumBlocks = Area.GetBlockCount();
BLOCKTYPE * BlockTypes = Area.GetBlockTypes(); BLOCKTYPE * BlockTypes = Area.GetBlockTypes();
for (int i = 0; i < NumBlocks; i++) for (int i = 0; i < NumBlocks; i++)
@ -58,11 +61,7 @@ public:
Found = true; Found = true;
break; break;
} }
} } // for i - BlockTypes[]
}
else
{
Found = true;
} }
NIBBLETYPE BlockMeta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); NIBBLETYPE BlockMeta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);