2014-04-02 15:04:41 -04:00
|
|
|
|
2013-07-29 07:13:03 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "BlockHandler.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-13 12:38:06 -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
|
|
|
|
|
|
|
cBlockFluidHandler(BLOCKTYPE a_BlockType):
|
|
|
|
Super(a_BlockType)
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
|
2014-07-17 16:50:58 -04:00
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-07-07 10:37:53 -04:00
|
|
|
virtual bool DoesIgnoreBuildCollision(cChunkInterface & a_ChunkInterface, Vector3i a_Pos, cPlayer & a_Player, NIBBLETYPE a_Meta) override
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtual void Check(
|
|
|
|
cChunkInterface & a_ChunkInterface, cBlockPluginInterface & a_PluginInterface,
|
|
|
|
Vector3i a_RelPos,
|
|
|
|
cChunk & a_Chunk
|
|
|
|
) override
|
2013-07-29 07:13:03 -04:00
|
|
|
{
|
|
|
|
switch (m_BlockType)
|
|
|
|
{
|
|
|
|
case E_BLOCK_STATIONARY_LAVA:
|
|
|
|
{
|
2019-10-16 04:06:34 -04:00
|
|
|
a_Chunk.FastSetBlock(a_RelPos, E_BLOCK_LAVA, a_Chunk.GetMeta(a_RelPos));
|
2013-07-29 07:13:03 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case E_BLOCK_STATIONARY_WATER:
|
|
|
|
{
|
2019-10-16 04:06:34 -04:00
|
|
|
a_Chunk.FastSetBlock(a_RelPos, E_BLOCK_WATER, a_Chunk.GetMeta(a_RelPos));
|
2013-07-29 07:13:03 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-04-13 12:38:06 -04:00
|
|
|
Super::Check(a_ChunkInterface, a_PluginInterface, a_RelPos, a_Chunk);
|
2013-07-29 07:13:03 -04:00
|
|
|
}
|
2015-06-30 10:50:15 -04:00
|
|
|
|
2019-10-16 04:06:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-06-30 10:50:15 -04:00
|
|
|
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
|
|
|
|
{
|
|
|
|
UNUSED(a_Meta);
|
|
|
|
if (IsBlockWater(m_BlockType))
|
|
|
|
{
|
|
|
|
return 12;
|
|
|
|
}
|
|
|
|
ASSERT(!"Unhandled blocktype in fluid/water handler!");
|
|
|
|
return 0;
|
|
|
|
}
|
2015-08-19 12:45:53 -04:00
|
|
|
|
2020-04-17 05:36:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-08-19 12:45:53 -04:00
|
|
|
virtual bool CanSustainPlant(BLOCKTYPE a_Plant) override
|
|
|
|
{
|
|
|
|
return (
|
2017-02-14 05:13:55 -05:00
|
|
|
(a_Plant == E_BLOCK_BEETROOTS) ||
|
2015-08-19 12:45:53 -04:00
|
|
|
(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)
|
|
|
|
);
|
|
|
|
}
|
2013-07-29 07:13:03 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-04 13:48:42 -05:00
|
|
|
|
2020-04-13 12:38:06 -04:00
|
|
|
class cBlockLavaHandler:
|
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-04-13 12:38:06 -04:00
|
|
|
cBlockLavaHandler(BLOCKTYPE a_BlockType):
|
|
|
|
Super(a_BlockType)
|
2013-12-04 13:48:42 -05:00
|
|
|
{
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
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
|
|
|
|
) 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-06-30 10:50:15 -04:00
|
|
|
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
|
|
|
|
{
|
|
|
|
UNUSED(a_Meta);
|
|
|
|
return 4;
|
|
|
|
}
|
2015-08-19 12:45:53 -04:00
|
|
|
|
2020-04-17 05:36:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-08-19 12:45:53 -04:00
|
|
|
virtual bool CanSustainPlant(BLOCKTYPE a_Plant) override
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-04 13:48:42 -05:00
|
|
|
} ;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|