aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/CauldronTile.cpp
blob: c77ebd281ded79b553d2c6b9f7ca70986b61f9d6 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include "stdafx.h"
#include "CauldronTile.h"
#include "Facing.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.item.h"
#include "net.minecraft.world.entity.item.h"
#include "net.minecraft.world.entity.player.h"
#include "net.minecraft.world.h"
#include "..\Minecraft.Client\ServerPlayer.h"

const wstring CauldronTile::TEXTURE_INSIDE = L"cauldron_inner";
const wstring CauldronTile::TEXTURE_BOTTOM = L"cauldron_bottom";

CauldronTile::CauldronTile(int id) : Tile(id, Material::metal, isSolidRender())
{
	iconInner = nullptr;
	iconTop = nullptr;
	iconBottom = nullptr;
}

Icon *CauldronTile::getTexture(int face, int data)
{
	if (face == Facing::UP)
	{
		return iconTop;
	}
	if (face == Facing::DOWN)
	{
		return iconBottom;
	}
	return icon;
}

void CauldronTile::registerIcons(IconRegister *iconRegister)
{
	iconInner = iconRegister->registerIcon(L"cauldron_inner");
	iconTop = iconRegister->registerIcon(L"cauldron_top");
	iconBottom = iconRegister->registerIcon(L"cauldron_bottom");
	icon = iconRegister->registerIcon(L"cauldron_side");
}

Icon *CauldronTile::getTexture(const wstring &name)
{
	if (name.compare(TEXTURE_INSIDE) == 0) return Tile::cauldron->iconInner;
	if (name.compare(TEXTURE_BOTTOM) == 0) return Tile::cauldron->iconBottom;
	return nullptr;
}

void CauldronTile::addAABBs(Level *level, int x, int y, int z, AABB *box, AABBList *boxes, shared_ptr<Entity> source)
{
	setShape(0, 0, 0, 1, 5.0f / 16.0f, 1);
	Tile::addAABBs(level, x, y, z, box, boxes, source);
	float thickness = 2.0f / 16.0f;
	setShape(0, 0, 0, thickness, 1, 1);
	Tile::addAABBs(level, x, y, z, box, boxes, source);
	setShape(0, 0, 0, 1, 1, thickness);
	Tile::addAABBs(level, x, y, z, box, boxes, source);
	setShape(1 - thickness, 0, 0, 1, 1, 1);
	Tile::addAABBs(level, x, y, z, box, boxes, source);
	setShape(0, 0, 1 - thickness, 1, 1, 1);
	Tile::addAABBs(level, x, y, z, box, boxes, source);

	updateDefaultShape();
}

void CauldronTile::updateDefaultShape()
{
	setShape(0, 0, 0, 1, 1, 1);
}

bool CauldronTile::isSolidRender(bool isServerLevel)
{
	return false;
}

int CauldronTile::getRenderShape()
{
	return SHAPE_CAULDRON;
}

bool CauldronTile::isCubeShaped()
{
	return false;
}

bool CauldronTile::use(Level *level, int x, int y, int z, shared_ptr<Player> player, int clickedFace, float clickX, float clickY, float clickZ, bool soundOnly/*=false*/) // 4J added soundOnly param
{
	if(soundOnly) return false;

	if (level->isClientSide)
	{
		return true;
	}

	shared_ptr<ItemInstance> item = player->inventory->getSelected();
	if (item == nullptr)
	{
		return true;
	}

	int currentData = level->getData(x, y, z);
	int fillLevel = getFillLevel(currentData);

	if (item->id == Item::bucket_water_Id)
	{
		if (fillLevel < 3)
		{
			if (!player->abilities.instabuild)
			{
				player->inventory->setItem(player->inventory->selected, std::make_shared<ItemInstance>(Item::bucket_empty));
			}

			level->setData(x, y, z, 3, Tile::UPDATE_CLIENTS);
			level->updateNeighbourForOutputSignal(x, y, z, id);
		}
		return true;
	}
	else if (item->id == Item::glassBottle_Id)
	{
		if (fillLevel > 0)
		{
			shared_ptr<ItemInstance> potion = std::make_shared<ItemInstance>(Item::potion, 1, 0);
			if (!player->inventory->add(potion))
			{
				level->addEntity(std::make_shared<ItemEntity>(level, x + 0.5, y + 1.5, z + 0.5, potion));
			}
			// 4J Stu - Brought forward change to update inventory when filling bottles with water
			else if (player->instanceof(eTYPE_SERVERPLAYER))
			{
				dynamic_pointer_cast<ServerPlayer>( player )->refreshContainer(player->inventoryMenu);
			}
			// 4J-PB - don't lose the water in creative mode
			if (player->abilities.instabuild==false)
			{
				item->count--;
				if (item->count <= 0)
				{
					player->inventory->setItem(player->inventory->selected, nullptr);
				}
			}
			level->setData(x, y, z, fillLevel - 1, Tile::UPDATE_CLIENTS);
			level->updateNeighbourForOutputSignal(x, y, z, id);
		}
	}
	else if (fillLevel > 0)
	{
		ArmorItem *armor = dynamic_cast<ArmorItem *>(item->getItem());
		if(armor && armor->getMaterial() == ArmorItem::ArmorMaterial::CLOTH)
		{
			armor->clearColor(item);
			level->setData(x, y, z, fillLevel - 1, Tile::UPDATE_CLIENTS);
			level->updateNeighbourForOutputSignal(x, y, z, id);
			return true;
		}
	}

	return true;

}

void CauldronTile::handleRain(Level *level, int x, int y, int z)
{
	if (level->random->nextInt(20) != 1) return;

	int data = level->getData(x, y, z);

	if (data < 3)
	{
		level->setData(x, y, z, data + 1, Tile::UPDATE_CLIENTS);
	}
}

int CauldronTile::getResource(int data, Random *random, int playerBonusLevel)
{
	return Item::cauldron_Id;
}

int CauldronTile::cloneTileId(Level *level, int x, int y, int z)
{
	return Item::cauldron_Id;
}

bool CauldronTile::hasAnalogOutputSignal()
{
	return true;
}

int CauldronTile::getAnalogOutputSignal(Level *level, int x, int y, int z, int dir)
{
	int data = level->getData(x, y, z);

	return getFillLevel(data);
}

int CauldronTile::getFillLevel(int data)
{
	return data;
}