2012-10-13 05:53:28 -04:00
|
|
|
#include "Globals.h"
|
|
|
|
|
|
|
|
#include "FluidSimulator.h"
|
2012-10-13 12:24:50 -04:00
|
|
|
#include "../World.h"
|
2012-10-13 05:53:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-02-28 08:39:20 -05:00
|
|
|
cFluidSimulator::cFluidSimulator(cWorld & a_World, BLOCKTYPE a_Fluid, BLOCKTYPE a_StationaryFluid) :
|
2020-04-13 12:38:06 -04:00
|
|
|
Super(a_World),
|
2012-10-13 05:53:28 -04:00
|
|
|
m_FluidBlock(a_Fluid),
|
|
|
|
m_StationaryFluidBlock(a_StationaryFluid)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-13 12:24:50 -04:00
|
|
|
|
2012-10-14 13:06:21 -04:00
|
|
|
bool cFluidSimulator::IsAllowedBlock(BLOCKTYPE a_BlockType)
|
2012-10-13 12:24:50 -04:00
|
|
|
{
|
2012-10-14 13:06:21 -04:00
|
|
|
return ((a_BlockType == m_FluidBlock) || (a_BlockType == m_StationaryFluidBlock));
|
2012-10-13 12:24:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cFluidSimulator::CanWashAway(BLOCKTYPE a_BlockType)
|
|
|
|
{
|
|
|
|
switch (a_BlockType)
|
|
|
|
{
|
2017-03-21 04:47:03 -04:00
|
|
|
case E_BLOCK_ACTIVATOR_RAIL:
|
|
|
|
case E_BLOCK_ACTIVE_COMPARATOR:
|
2017-02-14 05:13:55 -05:00
|
|
|
case E_BLOCK_BEETROOTS:
|
2017-03-21 04:47:03 -04:00
|
|
|
case E_BLOCK_BIG_FLOWER:
|
2012-10-13 12:24:50 -04:00
|
|
|
case E_BLOCK_BROWN_MUSHROOM:
|
|
|
|
case E_BLOCK_CACTUS:
|
2020-04-05 07:41:31 -04:00
|
|
|
case E_BLOCK_CARROTS:
|
2013-04-06 14:20:06 -04:00
|
|
|
case E_BLOCK_COBWEB:
|
2012-10-19 14:48:34 -04:00
|
|
|
case E_BLOCK_CROPS:
|
2012-10-18 15:41:29 -04:00
|
|
|
case E_BLOCK_DEAD_BUSH:
|
2017-03-21 04:47:03 -04:00
|
|
|
case E_BLOCK_DETECTOR_RAIL:
|
|
|
|
case E_BLOCK_INACTIVE_COMPARATOR:
|
2014-03-28 18:51:30 -04:00
|
|
|
case E_BLOCK_LILY_PAD:
|
2020-04-05 07:43:03 -04:00
|
|
|
case E_BLOCK_POTATOES:
|
2017-03-21 04:47:03 -04:00
|
|
|
case E_BLOCK_POWERED_RAIL:
|
2012-10-18 15:41:29 -04:00
|
|
|
case E_BLOCK_RAIL:
|
2017-03-21 04:47:03 -04:00
|
|
|
case E_BLOCK_REDSTONE_REPEATER_OFF:
|
|
|
|
case E_BLOCK_REDSTONE_REPEATER_ON:
|
2012-10-16 16:49:17 -04:00
|
|
|
case E_BLOCK_REDSTONE_TORCH_OFF:
|
|
|
|
case E_BLOCK_REDSTONE_TORCH_ON:
|
2012-10-18 15:41:29 -04:00
|
|
|
case E_BLOCK_REDSTONE_WIRE:
|
|
|
|
case E_BLOCK_RED_MUSHROOM:
|
|
|
|
case E_BLOCK_RED_ROSE:
|
|
|
|
case E_BLOCK_SNOW:
|
2012-10-19 14:48:34 -04:00
|
|
|
case E_BLOCK_SUGARCANE:
|
2012-10-18 15:41:29 -04:00
|
|
|
case E_BLOCK_TALL_GRASS:
|
|
|
|
case E_BLOCK_TORCH:
|
2017-03-21 04:47:03 -04:00
|
|
|
case E_BLOCK_TRIPWIRE:
|
2020-04-05 07:43:03 -04:00
|
|
|
case E_BLOCK_TRIPWIRE_HOOK:
|
2012-10-18 15:41:29 -04:00
|
|
|
case E_BLOCK_YELLOW_FLOWER:
|
2012-10-13 12:24:50 -04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cFluidSimulator::IsSolidBlock(BLOCKTYPE a_BlockType)
|
|
|
|
{
|
|
|
|
return !IsPassableForFluid(a_BlockType);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-10-14 13:06:21 -04:00
|
|
|
bool cFluidSimulator::IsPassableForFluid(BLOCKTYPE a_BlockType)
|
|
|
|
{
|
|
|
|
return (
|
|
|
|
(a_BlockType == E_BLOCK_AIR) ||
|
|
|
|
(a_BlockType == E_BLOCK_FIRE) ||
|
|
|
|
IsAllowedBlock(a_BlockType) ||
|
|
|
|
CanWashAway(a_BlockType)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool cFluidSimulator::IsHigherMeta(NIBBLETYPE a_Meta1, NIBBLETYPE a_Meta2)
|
|
|
|
{
|
|
|
|
if (a_Meta1 == 0)
|
|
|
|
{
|
|
|
|
// Source block is higher than anything, even itself.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if ((a_Meta1 & 0x08) != 0)
|
|
|
|
{
|
|
|
|
// Falling fluid is higher than anything, including self
|
|
|
|
return true;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2012-10-14 13:06:21 -04:00
|
|
|
if (a_Meta2 == 0)
|
|
|
|
{
|
|
|
|
// Second block is a source and first block isn't
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ((a_Meta2 & 0x08) != 0)
|
|
|
|
{
|
|
|
|
// Second block is falling and the first one is neither a source nor falling
|
|
|
|
return false;
|
|
|
|
}
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2012-10-14 13:06:21 -04:00
|
|
|
// All special cases have been handled, now it's just a raw comparison:
|
|
|
|
return (a_Meta1 < a_Meta2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-07-27 05:01:53 -04:00
|
|
|
Vector3f cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z)
|
2012-10-13 12:24:50 -04:00
|
|
|
{
|
2016-08-24 15:45:03 -04:00
|
|
|
if (!cChunkDef::IsValidHeight(a_Y))
|
2013-03-17 09:24:27 -04:00
|
|
|
{
|
2018-07-27 05:01:53 -04:00
|
|
|
return {};
|
2013-03-17 09:24:27 -04:00
|
|
|
}
|
2012-10-13 12:24:50 -04:00
|
|
|
|
2021-03-14 22:28:18 -04:00
|
|
|
if (!IsAllowedBlock(m_World.GetBlock({ a_X, a_Y, a_Z }))) // No Fluid -> No Flowing direction :D
|
2012-10-13 12:24:50 -04:00
|
|
|
{
|
2018-07-27 05:01:53 -04:00
|
|
|
return {};
|
2012-10-13 12:24:50 -04:00
|
|
|
}
|
|
|
|
|
2018-07-27 05:01:53 -04:00
|
|
|
const auto HeightFromMeta = [](NIBBLETYPE a_BlockMeta) -> NIBBLETYPE
|
|
|
|
{
|
|
|
|
// Falling water blocks are always full height (0)
|
|
|
|
return ((a_BlockMeta & 0x08) != 0) ? 0 : a_BlockMeta;
|
|
|
|
};
|
2012-10-13 12:24:50 -04:00
|
|
|
|
2021-03-14 22:28:18 -04:00
|
|
|
auto BlockMeta = m_World.GetBlockMeta({ a_X, a_Y, a_Z });
|
2018-07-27 05:01:53 -04:00
|
|
|
NIBBLETYPE CentralPoint = HeightFromMeta(BlockMeta);
|
|
|
|
NIBBLETYPE LevelPoint[4];
|
2012-10-13 12:24:50 -04:00
|
|
|
|
2018-07-27 05:01:53 -04:00
|
|
|
// blocks around the checking pos
|
|
|
|
Vector3i Points[]
|
|
|
|
{
|
|
|
|
{ a_X + 1, a_Y, a_Z },
|
|
|
|
{ a_X, a_Y, a_Z + 1 },
|
|
|
|
{ a_X - 1, a_Y, a_Z },
|
|
|
|
{ a_X, a_Y, a_Z - 1 }
|
|
|
|
};
|
2012-10-13 12:24:50 -04:00
|
|
|
|
2018-07-27 05:01:53 -04:00
|
|
|
for (size_t i = 0; i < ARRAYCOUNT(LevelPoint); i++)
|
2012-10-13 12:24:50 -04:00
|
|
|
{
|
2018-07-27 05:01:53 -04:00
|
|
|
if (IsAllowedBlock(m_World.GetBlock(Points[i])))
|
2012-10-13 12:24:50 -04:00
|
|
|
{
|
2018-07-27 05:01:53 -04:00
|
|
|
LevelPoint[i] = HeightFromMeta(m_World.GetBlockMeta(Points[i]));
|
2014-06-19 04:49:56 -04:00
|
|
|
}
|
2018-07-27 05:01:53 -04:00
|
|
|
else
|
2012-10-13 12:24:50 -04:00
|
|
|
{
|
2018-07-27 05:01:53 -04:00
|
|
|
LevelPoint[i] = CentralPoint;
|
2012-10-13 12:24:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-27 05:01:53 -04:00
|
|
|
Vector3f Direction;
|
2012-10-13 12:24:50 -04:00
|
|
|
|
2018-07-27 05:01:53 -04:00
|
|
|
// Calculate the flow direction
|
2012-10-13 12:24:50 -04:00
|
|
|
|
2018-07-27 05:01:53 -04:00
|
|
|
Direction.x = (LevelPoint[0] - LevelPoint[2]) / 2.0f;
|
|
|
|
Direction.z = (LevelPoint[1] - LevelPoint[3]) / 2.0f;
|
2012-10-13 12:24:50 -04:00
|
|
|
|
2018-07-27 05:01:53 -04:00
|
|
|
if ((BlockMeta & 0x08) != 0) // Test falling bit
|
2012-10-13 12:24:50 -04:00
|
|
|
{
|
2018-07-27 05:01:53 -04:00
|
|
|
Direction.y = -1.0f;
|
2012-10-13 12:24:50 -04:00
|
|
|
}
|
|
|
|
|
2018-07-27 05:01:53 -04:00
|
|
|
return Direction;
|
2012-10-13 12:24:50 -04:00
|
|
|
}
|
|
|
|
|