aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/HangingEntityItem.cpp
blob: 505dce4d095b6aa3a4ec3e4951b0dc1061279594 (plain)
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
#include "stdafx.h"
#include "net.minecraft.h"
#include "net.minecraft.world.phys.h"
#include "net.minecraft.world.damagesource.h"
#include "net.minecraft.world.level.tile.h"
#include "net.minecraft.world.level.h"
#include "HangingEntityItem.h"
#include "HangingEntity.h"
#include "Painting.h"
#include "GenericStats.h"
#include "ItemFrame.h"


HangingEntityItem::HangingEntityItem(int id, eINSTANCEOF eClassType) : Item(id)
{
	//super(id);
	//this.clazz = clazz;
	this->eType=eClassType;
	// setItemCategory(CreativeModeTab.TAB_DECORATIONS);
}

bool HangingEntityItem::useOn(shared_ptr<ItemInstance> instance, shared_ptr<Player> player, Level *level, int xt, int yt, int zt, int face, float clickX, float clickY, float clickZ, bool bTestOnly)
{
	if (face == Facing::DOWN) return false;
	if (face == Facing::UP) return false;

	if(bTestOnly)
	{
		if (!player->mayBuild(xt, yt, zt)) return false;

		return true;
	}

	int dir = Direction::FACING_DIRECTION[face];

	shared_ptr<HangingEntity> entity = createEntity(level, xt, yt, zt, dir);

	//if (!player->mayUseItemAt(xt, yt, zt, face, instance)) return false;
	if (!player->mayBuild(xt, yt, zt)) return false;

	if (entity != NULL && entity->survives()) 
	{
		if (!level->isClientSide) 
		{
			if(level->addEntity(entity)==TRUE)
			{
				// 4J-JEV: Hook for durango 'BlockPlaced' event.
				if (eType==eTYPE_PAINTING)			player->awardStat(GenericStats::blocksPlaced(Item::painting_Id), GenericStats::param_blocksPlaced(Item::painting_Id,instance->getAuxValue(),1));
				else if (eType==eTYPE_ITEM_FRAME)	player->awardStat(GenericStats::blocksPlaced(Item::itemFrame_Id), GenericStats::param_blocksPlaced(Item::itemFrame_Id,instance->getAuxValue(),1));

				instance->count--;
			}
			else
			{
				player->displayClientMessage(IDS_MAX_HANGINGENTITIES );
				return false;
			}
		}
		else
		{
			instance->count--;
		}
	}
	return true;
}


shared_ptr<HangingEntity> HangingEntityItem::createEntity(Level *level, int x, int y, int z, int dir) 
{
	if (eType == eTYPE_PAINTING) 
	{
		shared_ptr<Painting> painting = shared_ptr<Painting>(new Painting(level, x, y, z, dir));
		painting->PaintingPostConstructor(dir);
		
		return dynamic_pointer_cast<HangingEntity> (painting);
	} 
	else if (eType == eTYPE_ITEM_FRAME) 
	{
		shared_ptr<ItemFrame> itemFrame = shared_ptr<ItemFrame>(new ItemFrame(level, x, y, z, dir));

		return dynamic_pointer_cast<HangingEntity> (itemFrame);
	} 
	else 
	{
		return nullptr;
	}
}