|
Cuberite
A lightweight, fast and extensible game server for Minecraft
|
Go to the documentation of this file.
3 #include "../FastRandom.h"
4 #include "../BlockArea.h"
11 #define LEAVES_CHECK_DISTANCE 6
28 static double FortuneDropProbability(
unsigned char a_DefaultDenominator,
unsigned char a_FirstDenominatorReduction,
unsigned char a_FortuneLevel)
31 if (a_FortuneLevel == 3)
37 const auto Denominator = std::max<unsigned char>(10, a_DefaultDenominator - a_FortuneLevel * a_FirstDenominatorReduction);
38 return 1.0 / Denominator;
74 auto ProcessNeighbor = [&a_Area, i](
int cbx,
int cby,
int cbz) ->
bool
85 for (
int y = std::max(a_BlockPos.
y - i, 0); y <= std::min(a_BlockPos.
y + i,
cChunkDef::Height - 1); y++)
87 for (
int z = a_BlockPos.
z - i; z <= a_BlockPos.
z + i; z++)
89 for (
int x = a_BlockPos.
x - i; x <= a_BlockPos.
x + i; x++)
96 ProcessNeighbor(x - 1, y, z) ||
97 ProcessNeighbor(x + 1, y, z) ||
98 ProcessNeighbor(x, y, z - 1) ||
99 ProcessNeighbor(x, y, z + 1) ||
100 ProcessNeighbor(x, y + 1, z) ||
101 ProcessNeighbor(x, y - 1, z)
124 double DropProbability;
140 if (Random.RandBool(DropProbability))
153 if (Random.RandBool(DropProbability))
161 if (Random.RandBool(DropProbability))
179 if ((meta & 0x08) == 0)
181 a_ChunkInterface.
SetBlockMeta(a_BlockPos.
x, a_BlockPos.
y, a_BlockPos.
z, meta | 0x8);
197 auto Meta = a_Chunk.
GetMeta(a_RelPos);
198 if ((Meta & 0x04) != 0)
204 if ((Meta & 0x08) == 0)
227 a_Chunk.
SetMeta(a_RelPos, Meta ^ 0x08);
static bool HasNearLog(cBlockArea &a_Area, const Vector3i a_BlockPos)
Returns true if the area contains a continous path from the specified block to a log block entirely m...
void SetMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Meta)
static double FortuneDropProbability(unsigned char a_DefaultDenominator, unsigned char a_FirstDenominatorReduction, unsigned char a_FortuneLevel)
void DropBlockAsPickups(Vector3i a_BlockPos, const cEntity *a_Digger=nullptr, const cItem *a_Tool=nullptr)
Digs the block and spawns the relevant pickups, as if a_Digger used a_Tool to dig the block.
virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem *const a_Tool) const override
Returns the pickups that would result if the block was mined by a_Digger using a_Tool.
const BLOCKTYPE m_BlockType
void SetBlockType(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType)
void Add(const cItem &a_Item)
bool Read(cForEachChunkProvider &a_ForEachChunkProvider, int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ, int a_DataTypes=baTypes|baMetas|baBlockEntities)
Reads an area of blocks specified.
BLOCKTYPE * GetBlockTypes(void) const
Returns the internal pointer to the block types.
size_t GetBlockCount(void) const
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
This interface is used to decouple block handlers from the cPluginManager dependency through cWorld.
NIBBLETYPE GetBlockMeta(Vector3i a_Pos)
virtual void OnNeighborChanged(cChunkInterface &a_ChunkInterface, Vector3i a_BlockPos, eBlockFace a_WhichNeighbor) const override
Called when a direct neighbor of this block has been changed.
MTRand & GetRandomProvider()
Returns the current thread's random number source.
This class bridges a vector of cItem for safe access via Lua.
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
Returns the base colour ID of the block, as will be represented on a map, as per documentation: https...
unsigned char BLOCKTYPE
The datatype used by blockdata.
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
void SetBlockMeta(Vector3i a_BlockPos, NIBBLETYPE a_MetaData)
Sets the meta for the specified block, while keeping the blocktype.
NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const
Vector3i RelativeToAbsolute(Vector3i a_RelBlockPosition) const
Converts the coord relative to this chunk into an absolute coord.
virtual void OnUpdate(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cBlockPluginInterface &a_PluginInterface, cChunk &a_Chunk, const Vector3i a_RelPos) const override
Called when the block gets ticked either by a random tick or by a queued tick.
BLOCKTYPE GetBlockType(int a_BlockX, int a_BlockY, int a_BlockZ) const
static unsigned char ToolFortuneLevel(const cItem *a_Tool)
Returns the fortune level of a tool, if it is a valid tool.
#define LEAVES_CHECK_DISTANCE
constexpr cBlockHandler(BLOCKTYPE a_BlockType)
cWorld * GetWorld(void) const