summaryrefslogtreecommitdiffstats
path: root/src/Blocks/Mixins/DirtLikeUnderneath.h
blob: 909f1601e078db7303a363a2620ce494a95ac661 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

#pragma once

#include "../../Chunk.h"

/** Mixin to ensure the block has a dirt-like block underneath. */
template <class Base>
class cDirtLikeUnderneath :
	public Base
{
	using Super = Base;
public:

	using Super::Super;

	constexpr cDirtLikeUnderneath(BLOCKTYPE a_BlockType):
		Base(a_BlockType)
	{
	}

protected:

	~cDirtLikeUnderneath() = default;

protected:

	virtual bool CanBeAt(const cChunk & a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override
	{
		if (!Super::CanBeAt(a_Chunk, a_Position, a_Meta))
		{
			return false;
		}

		const auto BelowPos = a_Position.addedY(-1);
		if (!cChunkDef::IsValidHeight(BelowPos))
		{
			return false;
		}

		return IsBlockTypeOfDirt(a_Chunk.GetBlock(BelowPos));
	}
};