summaryrefslogtreecommitdiffstats
path: root/src/Items/ItemEyeOfEnder.h
blob: f911955a12e847274e399e94a539b0509784efef (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

#pragma once

#include "ItemHandler.h"
#include "ItemThrowable.h"





class cItemEyeOfEnderHandler :
	public cItemThrowableHandler
{
	typedef cItemThrowableHandler super;
public:
	cItemEyeOfEnderHandler(void) :
		super(E_ITEM_EYE_OF_ENDER, cProjectileEntity::pkSnowball, 30)
	{
	}

	virtual bool OnItemUse(
		cWorld * a_World, cPlayer * a_Player, cBlockPluginInterface & a_PluginInterface, const cItem & a_Item,
		int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace
	) override
	{
		BLOCKTYPE FacingBlock;
		NIBBLETYPE FacingMeta;
		a_World->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, FacingBlock, FacingMeta);
		switch (FacingBlock)
		{
			case E_BLOCK_END_PORTAL_FRAME:
			{
				// Fill the portal frame. E_META_END_PORTAL_EYE is the bit for holding the eye of ender.
				if ((FacingMeta & E_META_END_PORTAL_FRAME_EYE) != E_META_END_PORTAL_FRAME_EYE)
				{
					a_World->SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_END_PORTAL_FRAME, FacingMeta | E_META_END_PORTAL_FRAME_EYE);
					if (!a_Player->IsGameModeCreative())
					{
						a_Player->GetInventory().RemoveOneEquippedItem();
					}
				}
				break;
			}
			default:
			{
				// TODO: Create projectile for Eye Of Ender
				// return cItemThrowableHandler::OnItemUse(a_World, a_Player, a_PluginInterface, a_Item, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
			}
		}

		return false;
	}

} ;