summaryrefslogtreecommitdiffstats
path: root/src/Blocks/BlockEndPortalFrame.h
blob: 567de8bccee58084f037723d3e15ef00cdc65a53 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

#pragma once

#include "BlockHandler.h"





class cBlockEndPortalFrameHandler:
	public cMetaRotator<cBlockHandler, 0x03,
		E_META_END_PORTAL_FRAME_ZM,
		E_META_END_PORTAL_FRAME_XP,
		E_META_END_PORTAL_FRAME_ZP,
		E_META_END_PORTAL_FRAME_XM
	>
{
	using Super = cMetaRotator<
		cBlockHandler, 0x03,
		E_META_END_PORTAL_FRAME_ZM,
		E_META_END_PORTAL_FRAME_XP,
		E_META_END_PORTAL_FRAME_ZP,
		E_META_END_PORTAL_FRAME_XM
	>;

public:

	cBlockEndPortalFrameHandler(BLOCKTYPE a_BlockType):
		Super(a_BlockType)
	{
	}





	virtual bool GetPlacementBlockTypeMeta(
		cChunkInterface & a_ChunkInterface,
		cPlayer & a_Player,
		const Vector3i a_PlacedBlockPos,
		eBlockFace a_ClickedBlockFace,
		const Vector3i a_CursorPos,
		BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
	) override
	{
		a_BlockType = m_BlockType;
		a_BlockMeta = YawToMetaData(a_Player.GetYaw());
		return true;
	}





	inline static NIBBLETYPE YawToMetaData(double a_Rotation)
	{
		a_Rotation += 90 + 45;  // So its not aligned with axis
		if (a_Rotation > 360)
		{
			a_Rotation -= 360;
		}

		if ((a_Rotation >= 0) && (a_Rotation < 90))
		{
			return E_META_END_PORTAL_FRAME_XM;
		}
		else if ((a_Rotation >= 180) && (a_Rotation < 270))
		{
			return E_META_END_PORTAL_FRAME_XP;
		}
		else if ((a_Rotation >= 90) && (a_Rotation < 180))
		{
			return E_META_END_PORTAL_FRAME_ZM;
		}
		else
		{
			return E_META_END_PORTAL_FRAME_ZP;
		}
	}





	virtual bool IsClickedThrough(void) override
	{
		// TODO: Colision
		return true;
	}





	virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
	{
		UNUSED(a_Meta);
		return 27;
	}
};