summaryrefslogtreecommitdiffstats
path: root/src/Items/ItemBigFlower.h
blob: a67ca8d0a372eabd02b6a3a47136035309b4ab94 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

#pragma once

#include "ItemHandler.h"
#include "../BlockInfo.h"





class cItemBigFlowerHandler:
	public cItemHandler
{
	using Super = cItemHandler;

public:

	cItemBigFlowerHandler():
		Super(E_BLOCK_BIG_FLOWER)
	{
	}





	virtual bool GetBlocksToPlace(
		cWorld & a_World,
		cPlayer & a_Player,
		const cItem & a_EquippedItem,
		const Vector3i a_PlacedBlockPos,
		eBlockFace a_ClickedBlockFace,
		const Vector3i a_CursorPos,
		sSetBlockVector & a_BlocksToPlace
	) override
	{
		// Can only be placed on dirt:
		if ((a_PlacedBlockPos.y <= 0) || !IsBlockTypeOfDirt(a_World.GetBlock(a_PlacedBlockPos.addedY(-1))))
		{
			return false;
		}

		// Needs at least two free blocks to build in
		if (a_PlacedBlockPos.y >= cChunkDef::Height - 1)
		{
			return false;
		}

		auto TopPos = a_PlacedBlockPos.addedY(1);
		BLOCKTYPE TopType;
		NIBBLETYPE TopMeta;
		a_World.GetBlockTypeMeta(TopPos, TopType, TopMeta);
		cChunkInterface ChunkInterface(a_World.GetChunkMap());

		if (!cBlockHandler::For(TopType).DoesIgnoreBuildCollision(ChunkInterface, TopPos, a_Player, TopMeta))
		{
			return false;
		}

		a_BlocksToPlace.emplace_back(a_PlacedBlockPos, E_BLOCK_BIG_FLOWER, a_EquippedItem.m_ItemDamage & 0x07);
		a_BlocksToPlace.emplace_back(TopPos,           E_BLOCK_BIG_FLOWER, E_META_BIG_FLOWER_TOP);
		return true;
	}
};