2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockHandler.h"
|
2014-03-30 17:13:13 -04:00
|
|
|
#include "../FastRandom.h"
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Common class that takes care of carrots, potatoes and wheat
|
|
|
|
class cBlockCropsHandler :
|
|
|
|
public cBlockHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cBlockCropsHandler(BLOCKTYPE a_BlockType)
|
|
|
|
: cBlockHandler(a_BlockType)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_Meta) override
|
|
|
|
{
|
2014-03-30 17:13:13 -04:00
|
|
|
cFastRandom rand;
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
if (a_Meta == 0x7)
|
|
|
|
{
|
|
|
|
// Is fully grown, drop the entire produce:
|
|
|
|
switch (m_BlockType)
|
|
|
|
{
|
|
|
|
case E_BLOCK_CROPS:
|
|
|
|
{
|
|
|
|
a_Pickups.push_back(cItem(E_ITEM_WHEAT, 1, 0));
|
2014-03-30 17:13:13 -04:00
|
|
|
a_Pickups.push_back(cItem(E_ITEM_SEEDS, (char)(1 + (rand.NextInt(3) + rand.NextInt(3)) / 2), 0)); // [1 .. 3] with high preference of 2
|
2013-07-29 07:13:03 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case E_BLOCK_CARROTS:
|
|
|
|
{
|
2014-03-30 17:13:13 -04:00
|
|
|
a_Pickups.push_back(cItem(E_ITEM_CARROT, (char)(1 + (rand.NextInt(3) + rand.NextInt(3)) / 2), 0)); // [1 .. 3] with high preference of 2
|
2013-07-29 07:13:03 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case E_BLOCK_POTATOES:
|
|
|
|
{
|
2014-03-30 17:13:13 -04:00
|
|
|
a_Pickups.push_back(cItem(E_ITEM_POTATO, (char)(1 + (rand.NextInt(3) + rand.NextInt(3)) / 2), 0)); // [1 .. 3] with high preference of 2
|
|
|
|
if (rand.NextInt(21) == 0)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
// With a 5% chance, drop a poisonous potato as well
|
|
|
|
a_Pickups.push_back(cItem(E_ITEM_POISONOUS_POTATO, 1, 0));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
ASSERT(!"Unhandled block type");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} // switch (m_BlockType)
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Drop 1 item of whatever is growing
|
|
|
|
switch (m_BlockType)
|
|
|
|
{
|
|
|
|
case E_BLOCK_CROPS: a_Pickups.push_back(cItem(E_ITEM_SEEDS, 1, 0)); break;
|
|
|
|
case E_BLOCK_CARROTS: a_Pickups.push_back(cItem(E_ITEM_CARROT, 1, 0)); break;
|
|
|
|
case E_BLOCK_POTATOES: a_Pickups.push_back(cItem(E_ITEM_POTATO, 1, 0)); break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
ASSERT(!"Unhandled block type");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-17 16:50:58 -04:00
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
|
|
|
|
|
2014-02-02 09:49:37 -05:00
|
|
|
virtual void OnUpdate(cChunkInterface & cChunkInterface, cWorldInterface & a_WorldInterface, cBlockPluginInterface & a_PluginInterface, cChunk & a_Chunk, int a_RelX, int a_RelY, int a_RelZ) override
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2013-11-30 09:58:27 -05:00
|
|
|
NIBBLETYPE Meta = a_Chunk.GetMeta (a_RelX, a_RelY, a_RelZ);
|
|
|
|
NIBBLETYPE Light = a_Chunk.GetBlockLight(a_RelX, a_RelY, a_RelZ);
|
|
|
|
NIBBLETYPE SkyLight = a_Chunk.GetSkyLight (a_RelX, a_RelY, a_RelZ);
|
2013-11-14 11:53:09 -05:00
|
|
|
|
|
|
|
if (SkyLight > Light)
|
|
|
|
{
|
|
|
|
Light = SkyLight;
|
|
|
|
}
|
2013-10-12 17:25:47 -04:00
|
|
|
|
2013-10-12 18:38:07 -04:00
|
|
|
if ((Meta < 7) && (Light > 8))
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
2014-02-03 16:14:52 -05:00
|
|
|
a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, m_BlockType, ++Meta);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
2013-10-12 18:38:07 -04:00
|
|
|
else if (Light < 9)
|
2013-10-12 17:25:47 -04:00
|
|
|
{
|
2013-11-30 09:58:27 -05:00
|
|
|
a_Chunk.GetWorld()->DigBlock(a_RelX + a_Chunk.GetPosX() * cChunkDef::Width, a_RelY, a_RelZ + a_Chunk.GetPosZ() * cChunkDef::Width);
|
2013-10-12 17:25:47 -04:00
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-01 08:06:32 -05:00
|
|
|
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
return ((a_RelY > 0) && (a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ) == E_BLOCK_FARMLAND));
|
|
|
|
}
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|