2014-04-02 15:04:41 -04:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockHandler.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-05 06:27:14 -04:00
|
|
|
class cBlockFluidHandler :
|
2013-07-29 07:13:03 -04:00
|
|
|
public cBlockHandler
|
|
|
|
{
|
2020-04-13 12:38:06 -04:00
|
|
|
using Super = cBlockHandler;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
public:
|
2020-04-13 12:38:06 -04:00
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
using Super::Super;
|
2019-10-16 04:06:34 -04:00
|
|
|
|
2020-10-05 06:27:14 -04:00
|
|
|
protected:
|
|
|
|
|
|
|
|
~cBlockFluidHandler() = default;
|
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
private:
|
2019-10-16 04:06:34 -04:00
|
|
|
|
2020-09-23 11:06:27 -04:00
|
|
|
virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, const cEntity * a_Digger, const cItem * a_Tool) const override
|
2013-08-14 06:44:02 -04:00
|
|
|
{
|
|
|
|
// No pickups
|
2019-10-16 04:06:34 -04:00
|
|
|
return {};
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
virtual bool DoesIgnoreBuildCollision(cChunkInterface & a_ChunkInterface, Vector3i a_Pos, cPlayer & a_Player, NIBBLETYPE a_Meta) const override
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-04 13:48:42 -05:00
|
|
|
|
2020-10-05 06:27:14 -04:00
|
|
|
class cBlockLavaHandler final :
|
2013-12-04 13:48:42 -05:00
|
|
|
public cBlockFluidHandler
|
|
|
|
{
|
2020-04-13 12:38:06 -04:00
|
|
|
using Super = cBlockFluidHandler;
|
|
|
|
|
2013-12-04 13:48:42 -05:00
|
|
|
public:
|
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
using Super::Super;
|
2020-04-17 05:36:37 -04:00
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
private:
|
2020-04-17 05:36:37 -04:00
|
|
|
|
|
|
|
virtual void OnUpdate(
|
|
|
|
cChunkInterface & a_ChunkInterface,
|
|
|
|
cWorldInterface & a_WorldInterface,
|
|
|
|
cBlockPluginInterface & a_PluginInterface,
|
|
|
|
cChunk & a_Chunk,
|
|
|
|
const Vector3i a_RelPos
|
2020-09-20 09:50:52 -04:00
|
|
|
) const override
|
2013-12-04 13:48:42 -05:00
|
|
|
{
|
|
|
|
if (a_Chunk.GetWorld()->ShouldLavaSpawnFire())
|
|
|
|
{
|
|
|
|
// Try to start up to 5 fires:
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
{
|
2020-04-17 05:36:37 -04:00
|
|
|
TryStartFireNear(a_RelPos, a_Chunk);
|
2013-12-04 13:48:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2020-04-17 05:36:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-06-30 10:50:15 -04:00
|
|
|
/** Tries to start a fire near the lava at given coords. Returns true if fire started. */
|
2020-04-17 05:36:37 -04:00
|
|
|
static bool TryStartFireNear(const Vector3i a_RelPos, cChunk & a_Chunk)
|
2013-12-04 13:48:42 -05:00
|
|
|
{
|
2020-04-17 05:36:37 -04:00
|
|
|
// Pick a random block next to this lava block:
|
2013-12-04 13:48:42 -05:00
|
|
|
int rnd = a_Chunk.GetWorld()->GetTickRandomNumber(cChunkDef::NumBlocks * 8) / 7;
|
|
|
|
int x = (rnd % 3) - 1; // -1 .. 1
|
|
|
|
int y = ((rnd / 4) % 4) - 1; // -1 .. 2
|
|
|
|
int z = ((rnd / 16) % 3) - 1; // -1 .. 1
|
2020-04-17 05:36:37 -04:00
|
|
|
auto Pos = a_RelPos + Vector3i(x, y, z);
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-12-04 13:48:42 -05:00
|
|
|
// Check if it's fuel:
|
|
|
|
BLOCKTYPE BlockType;
|
|
|
|
if (
|
2020-04-17 05:36:37 -04:00
|
|
|
!cChunkDef::IsValidHeight(Pos.y) ||
|
|
|
|
!a_Chunk.UnboundedRelGetBlockType(Pos, BlockType) ||
|
2014-04-02 15:03:42 -04:00
|
|
|
!cFireSimulator::IsFuel(BlockType)
|
2013-12-04 13:48:42 -05:00
|
|
|
)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2013-12-04 13:48:42 -05:00
|
|
|
// Try to set it on fire:
|
2020-04-17 05:36:37 -04:00
|
|
|
static Vector3i CrossCoords[] =
|
2013-12-04 13:48:42 -05:00
|
|
|
{
|
|
|
|
{-1, 0, 0},
|
|
|
|
{ 1, 0, 0},
|
|
|
|
{ 0, -1, 0},
|
|
|
|
{ 0, 1, 0},
|
|
|
|
{ 0, 0, -1},
|
|
|
|
{ 0, 0, 1},
|
|
|
|
} ;
|
|
|
|
for (size_t i = 0; i < ARRAYCOUNT(CrossCoords); i++)
|
|
|
|
{
|
2020-04-17 05:36:37 -04:00
|
|
|
auto NeighborPos = Pos + CrossCoords[i];
|
2013-12-04 13:48:42 -05:00
|
|
|
if (
|
2020-04-17 05:36:37 -04:00
|
|
|
cChunkDef::IsValidHeight(NeighborPos.y) &&
|
|
|
|
a_Chunk.UnboundedRelGetBlockType(NeighborPos, BlockType) &&
|
2013-12-04 13:48:42 -05:00
|
|
|
(BlockType == E_BLOCK_AIR)
|
|
|
|
)
|
|
|
|
{
|
2020-04-17 05:36:37 -04:00
|
|
|
// This is an air block next to a fuel next to lava, light the fuel block up:
|
|
|
|
a_Chunk.UnboundedRelSetBlock(NeighborPos, E_BLOCK_FIRE, 0);
|
2013-12-04 13:48:42 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} // for i - CrossCoords[]
|
|
|
|
return false;
|
|
|
|
}
|
2015-06-30 10:50:15 -04:00
|
|
|
|
2020-04-17 05:36:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
|
2015-06-30 10:50:15 -04:00
|
|
|
{
|
|
|
|
UNUSED(a_Meta);
|
|
|
|
return 4;
|
|
|
|
}
|
2015-08-19 12:45:53 -04:00
|
|
|
|
2020-04-17 05:36:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-20 09:50:52 -04:00
|
|
|
virtual bool CanSustainPlant(BLOCKTYPE a_Plant) const override
|
2015-08-19 12:45:53 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-04 13:48:42 -05:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-05 06:27:14 -04:00
|
|
|
|
|
|
|
class cBlockWaterHandler final :
|
|
|
|
public cBlockFluidHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
using cBlockFluidHandler::cBlockFluidHandler;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
|
|
|
|
{
|
|
|
|
UNUSED(a_Meta);
|
|
|
|
if (IsBlockWater(m_BlockType))
|
|
|
|
{
|
|
|
|
return 12;
|
|
|
|
}
|
|
|
|
ASSERT(!"Unhandled blocktype in fluid/water handler!");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool CanSustainPlant(BLOCKTYPE a_Plant) const override
|
|
|
|
{
|
|
|
|
return (
|
|
|
|
(a_Plant == E_BLOCK_BEETROOTS) ||
|
|
|
|
(a_Plant == E_BLOCK_CROPS) ||
|
|
|
|
(a_Plant == E_BLOCK_CARROTS) ||
|
|
|
|
(a_Plant == E_BLOCK_POTATOES) ||
|
|
|
|
(a_Plant == E_BLOCK_MELON_STEM) ||
|
|
|
|
(a_Plant == E_BLOCK_PUMPKIN_STEM)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|