aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/BrewingStandTile.cpp
blob: 1aeb52d8f889fec5a07614c89b20f0998670ef02 (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
#include "stdafx.h"
#include "BrewingStandTile.h"
#include "BrewingStandTileEntity.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.item.h"
#include "net.minecraft.world.entity.item.h"
#include "net.minecraft.world.h"
#include "net.minecraft.world.inventory.h"

BrewingStandTile::BrewingStandTile(int id) : BaseEntityTile(id, Material::metal, isSolidRender())
{
	random = new Random();
	iconBase = NULL;
}

BrewingStandTile::~BrewingStandTile()
{
	delete random;
}

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

int BrewingStandTile::getRenderShape()
{
	return SHAPE_BREWING_STAND;
}

shared_ptr<TileEntity> BrewingStandTile::newTileEntity(Level *level)
{
	return shared_ptr<TileEntity>(new BrewingStandTileEntity());
}

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

void BrewingStandTile::addAABBs(Level *level, int x, int y, int z, AABB *box, AABBList *boxes, shared_ptr<Entity> source)
{
	setShape(7.0f / 16.0f, 0, 7.0f / 16.0f, 9.0f / 16.0f, 14.0f / 16.0f, 9.0f / 16.0f);
	BaseEntityTile::addAABBs(level, x, y, z, box, boxes, source);
	updateDefaultShape();
	BaseEntityTile::addAABBs(level, x, y, z, box, boxes, source);
}

void BrewingStandTile::updateDefaultShape()
{
	setShape(0, 0, 0, 1, 2.0f / 16.0f, 1);
}

bool BrewingStandTile::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<BrewingStandTileEntity> brewingStand = dynamic_pointer_cast<BrewingStandTileEntity>(level->getTileEntity(x, y, z));
	if (brewingStand != NULL) player->openBrewingStand(brewingStand);

	return true;
}

void BrewingStandTile::setPlacedBy(Level *level, int x, int y, int z, shared_ptr<LivingEntity> by, shared_ptr<ItemInstance> itemInstance)
{
	if (itemInstance->hasCustomHoverName())
	{
		dynamic_pointer_cast<BrewingStandTileEntity>( level->getTileEntity(x, y, z))->setCustomName(itemInstance->getHoverName());
	}
}

void BrewingStandTile::animateTick(Level *level, int xt, int yt, int zt, Random *random)
{
	double x = xt + 0.4f + random->nextFloat() * 0.2f;
	double y = yt + 0.7f + random->nextFloat() * 0.3f;
	double z = zt + 0.4f + random->nextFloat() * 0.2f;


	level->addParticle(eParticleType_smoke, x, y, z, 0, 0, 0);
}

void BrewingStandTile::onRemove(Level *level, int x, int y, int z, int id, int data)
{
	shared_ptr<TileEntity> tileEntity = level->getTileEntity(x, y, z);
	if (tileEntity != NULL && ( dynamic_pointer_cast<BrewingStandTileEntity>(tileEntity) != NULL) )
	{
		shared_ptr<BrewingStandTileEntity> container = dynamic_pointer_cast<BrewingStandTileEntity>(tileEntity);
		for (int i = 0; i < container->getContainerSize(); i++)
		{
			shared_ptr<ItemInstance> item = container->getItem(i);
			if (item != NULL)
			{
				float xo = random->nextFloat() * 0.8f + 0.1f;
				float yo = random->nextFloat() * 0.8f + 0.1f;
				float zo = random->nextFloat() * 0.8f + 0.1f;

				while (item->count > 0)
				{
					int count = random->nextInt(21) + 10;
					if (count > item->count) count = item->count;
					item->count -= count;

					shared_ptr<ItemEntity> itemEntity = shared_ptr<ItemEntity>(new ItemEntity(level, x + xo, y + yo, z + zo, shared_ptr<ItemInstance>( new ItemInstance(item->id, count, item->getAuxValue()))));
					float pow = 0.05f;
					itemEntity->xd = (float) random->nextGaussian() * pow;
					itemEntity->yd = (float) random->nextGaussian() * pow + 0.2f;
					itemEntity->zd = (float) random->nextGaussian() * pow;
					if (item->hasTag())
					{
						itemEntity->getItem()->setTag((CompoundTag *) item->getTag()->copy());
					}
					level->addEntity(itemEntity);
				}
			}
		}
	}
	BaseEntityTile::onRemove(level, x, y, z, id, data);
}

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

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

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

int BrewingStandTile::getAnalogOutputSignal(Level *level, int x, int y, int z, int dir)
{
	return AbstractContainerMenu::getRedstoneSignalFromContainer(dynamic_pointer_cast<Container>(level->getTileEntity(x, y, z)));
}

void BrewingStandTile::registerIcons(IconRegister *iconRegister)
{
	BaseEntityTile::registerIcons(iconRegister);
	iconBase = iconRegister->registerIcon(getIconName() + L"_base");
}

Icon *BrewingStandTile::getBaseTexture()
{
	return iconBase;
}