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
199
200
201
202
203
204
205
206
207
208
209
210
211
|
#include "stdafx.h"
#include "net.minecraft.h"
#include "net.minecraft.world.entity.item.h"
#include "net.minecraft.world.item.h"
#include "net.minecraft.world.inventory.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.tile.entity.h"
#include "net.minecraft.world.h"
#include "HopperTile.h"
const wstring HopperTile::TEXTURE_OUTSIDE = L"hopper_outside";
const wstring HopperTile::TEXTURE_INSIDE = L"hopper_inside";
HopperTile::HopperTile(int id) : BaseEntityTile(id, Material::metal, isSolidRender() )
{
setShape(0, 0, 0, 1, 1, 1);
}
void HopperTile::updateShape(LevelSource *level, int x, int y, int z, int forceData , shared_ptr<TileEntity> forceEntity)
{
setShape(0, 0, 0, 1, 1, 1);
}
void HopperTile::addAABBs(Level *level, int x, int y, int z, AABB *box, AABBList *boxes, shared_ptr<Entity> source)
{
setShape(0, 0, 0, 1, 10.0f / 16.0f, 1);
BaseEntityTile::addAABBs(level, x, y, z, box, boxes, source);
float thickness = 2.0f / 16.0f;
setShape(0, 0, 0, thickness, 1, 1);
BaseEntityTile::addAABBs(level, x, y, z, box, boxes, source);
setShape(0, 0, 0, 1, 1, thickness);
BaseEntityTile::addAABBs(level, x, y, z, box, boxes, source);
setShape(1 - thickness, 0, 0, 1, 1, 1);
BaseEntityTile::addAABBs(level, x, y, z, box, boxes, source);
setShape(0, 0, 1 - thickness, 1, 1, 1);
BaseEntityTile::addAABBs(level, x, y, z, box, boxes, source);
setShape(0, 0, 0, 1, 1, 1);
}
int HopperTile::getPlacedOnFaceDataValue(Level *level, int x, int y, int z, int face, float clickX, float clickY, float clickZ, int itemValue)
{
int attached = Facing::OPPOSITE_FACING[face];
if (attached == Facing::UP) attached = Facing::DOWN;
return attached;
}
shared_ptr<TileEntity> HopperTile::newTileEntity(Level *level)
{
return std::make_shared<HopperTileEntity>();
}
void HopperTile::setPlacedBy(Level *level, int x, int y, int z, shared_ptr<LivingEntity> by, shared_ptr<ItemInstance> itemInstance)
{
BaseEntityTile::setPlacedBy(level, x, y, z, by, itemInstance);
if (itemInstance->hasCustomHoverName())
{
shared_ptr<HopperTileEntity> hopper = getHopper(level, x, y, z);
hopper->setCustomName(itemInstance->getHoverName());
}
}
void HopperTile::onPlace(Level *level, int x, int y, int z)
{
BaseEntityTile::onPlace(level, x, y, z);
checkPoweredState(level, x, y, z);
}
bool HopperTile::use(Level *level, int x, int y, int z, shared_ptr<Player> player, int clickedFace, float clickX, float clickY, float clickZ, bool soundOnly)
{
if (level->isClientSide)
{
return true;
}
shared_ptr<HopperTileEntity> hopper = getHopper(level, x, y, z);
if (hopper != nullptr) player->openHopper(hopper);
return true;
}
void HopperTile::neighborChanged(Level *level, int x, int y, int z, int type)
{
checkPoweredState(level, x, y, z);
}
void HopperTile::checkPoweredState(Level *level, int x, int y, int z)
{
int data = level->getData(x, y, z);
int attachedFace = getAttachedFace(data);
bool shouldBeOn = !level->hasNeighborSignal(x, y, z);
bool isOn = isTurnedOn(data);
if (shouldBeOn != isOn)
{
level->setData(x, y, z, attachedFace | (shouldBeOn ? 0 : MASK_TOGGLE), UPDATE_NONE);
}
}
void HopperTile::onRemove(Level *level, int x, int y, int z, int id, int data)
{
shared_ptr<Container> container = dynamic_pointer_cast<HopperTileEntity>( level->getTileEntity(x, y, z) );
if (container != nullptr)
{
for (int i = 0; i < container->getContainerSize(); i++)
{
shared_ptr<ItemInstance> item = container->getItem(i);
if (item != nullptr)
{
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 = std::make_shared<ItemEntity>(level, x + xo, y + yo, z + zo, shared_ptr<ItemInstance>(new ItemInstance(item->id, count, item->getAuxValue())));
if (item->hasTag())
{
itemEntity->getItem()->setTag(static_cast<CompoundTag *>(item->getTag()->copy()));
}
float pow = 0.05f;
itemEntity->xd = static_cast<float>(random.nextGaussian()) * pow;
itemEntity->yd = static_cast<float>(random.nextGaussian()) * pow + 0.2f;
itemEntity->zd = static_cast<float>(random.nextGaussian()) * pow;
level->addEntity(itemEntity);
}
}
}
level->updateNeighbourForOutputSignal(x, y, z, id);
}
BaseEntityTile::onRemove(level, x, y, z, id, data);
}
int HopperTile::getRenderShape()
{
return SHAPE_HOPPER;
}
bool HopperTile::isCubeShaped()
{
return false;
}
bool HopperTile::isSolidRender(bool isServerLevel /*= false*/)
{
return false;
}
bool HopperTile::shouldRenderFace(LevelSource *level, int x, int y, int z, int face)
{
return true;
}
Icon *HopperTile::getTexture(int face, int data)
{
if (face == Facing::UP)
{
return hopperTopIcon;
}
return hopperIcon;
}
int HopperTile::getAttachedFace(int data)
{
return data & MASK_ATTACHED;
}
bool HopperTile::isTurnedOn(int data)
{
return (data & MASK_TOGGLE) != MASK_TOGGLE;
}
bool HopperTile::hasAnalogOutputSignal()
{
return true;
}
int HopperTile::getAnalogOutputSignal(Level *level, int x, int y, int z, int dir)
{
return AbstractContainerMenu::getRedstoneSignalFromContainer(getHopper(level, x, y, z));
}
void HopperTile::registerIcons(IconRegister *iconRegister)
{
hopperIcon = iconRegister->registerIcon(TEXTURE_OUTSIDE);
hopperTopIcon = iconRegister->registerIcon(L"hopper_top");
hopperInnerIcon = iconRegister->registerIcon(TEXTURE_INSIDE);
}
Icon *HopperTile::getTexture(const wstring &name)
{
if (name.compare(TEXTURE_OUTSIDE) == 0) return Tile::hopper->hopperIcon;
if (name.compare(TEXTURE_INSIDE) == 0) return Tile::hopper->hopperInnerIcon;
return nullptr;
}
wstring HopperTile::getTileItemIconName()
{
return L"hopper";
}
shared_ptr<HopperTileEntity> HopperTile::getHopper(LevelSource *level, int x, int y, int z)
{
return dynamic_pointer_cast<HopperTileEntity>( level->getTileEntity(x, y, z) );
}
|