the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "net.minecraft.world.h"
3#include "net.minecraft.world.entity.item.h"
4#include "net.minecraft.world.item.h"
5#include "net.minecraft.world.level.h"
6#include "net.minecraft.world.level.tile.entity.h"
7#include "WitherBoss.h"
8#include "net.minecraft.h"
9#include "SkullTile.h"
10
11SkullTile::SkullTile(int id) : BaseEntityTile(id, Material::decoration, isSolidRender() )
12{
13 setShape(4.0f / 16.0f, 0, 4.0f / 16.0f, 12.0f / 16.0f, .5f, 12.0f / 16.0f);
14}
15
16int SkullTile::getRenderShape()
17{
18 return SHAPE_INVISIBLE;
19}
20
21bool SkullTile::isSolidRender(bool isServerLevel)
22{
23 return false;
24}
25
26bool SkullTile::isCubeShaped()
27{
28 return false;
29}
30
31void SkullTile::updateShape(LevelSource *level, int x, int y, int z, int forceData , shared_ptr<TileEntity> forceEntity)
32{
33 int data = level->getData(x, y, z) & PLACEMENT_MASK;
34
35 switch (data)
36 {
37 default:
38 case Facing::UP:
39 setShape(4.0f / 16.0f, 0, 4.0f / 16.0f, 12.0f / 16.0f, .5f, 12.0f / 16.0f);
40 break;
41 case Facing::NORTH:
42 setShape(4.0f / 16.0f, 4.0f / 16.0f, .5f, 12.0f / 16.0f, 12.0f / 16.0f, 1);
43 break;
44 case Facing::SOUTH:
45 setShape(4.0f / 16.0f, 4.0f / 16.0f, 0, 12.0f / 16.0f, 12.0f / 16.0f, .5f);
46 break;
47 case Facing::WEST:
48 setShape(.5f, 4.0f / 16.0f, 4.0f / 16.0f, 1, 12.0f / 16.0f, 12.0f / 16.0f);
49 break;
50 case Facing::EAST:
51 setShape(0, 4.0f / 16.0f, 4.0f / 16.0f, .5f, 12.0f / 16.0f, 12.0f / 16.0f);
52 break;
53 }
54}
55
56AABB *SkullTile::getAABB(Level *level, int x, int y, int z)
57{
58 updateShape(level, x, y, z);
59 return BaseEntityTile::getAABB(level, x, y, z);
60}
61
62void SkullTile::setPlacedBy(Level *level, int x, int y, int z, shared_ptr<LivingEntity> by)
63{
64 int dir = Mth::floor(by->yRot * 4 / (360) + 2.5) & 3;
65 level->setData(x, y, z, dir, Tile::UPDATE_CLIENTS);
66}
67
68shared_ptr<TileEntity> SkullTile::newTileEntity(Level *level)
69{
70 return shared_ptr<SkullTileEntity>(new SkullTileEntity());
71}
72
73int SkullTile::cloneTileId(Level *level, int x, int y, int z)
74{
75 return Item::skull_Id;
76}
77
78int SkullTile::cloneTileData(Level *level, int x, int y, int z)
79{
80 shared_ptr<TileEntity> tileEntity = level->getTileEntity(x, y, z);
81 shared_ptr<SkullTileEntity> skull = dynamic_pointer_cast<SkullTileEntity>(tileEntity);
82 if (skull != NULL)
83 {
84 return skull->getSkullType();
85 }
86 return BaseEntityTile::cloneTileData(level, x, y, z);
87}
88
89int SkullTile::getSpawnResourcesAuxValue(int data)
90{
91 return data;
92}
93
94void SkullTile::spawnResources(Level *level, int x, int y, int z, int data, float odds, int playerBonusLevel)
95{
96 // do nothing, resource is popped by onRemove
97 // ... because the tile entity is removed prior to spawnResources
98}
99
100void SkullTile::playerWillDestroy(Level *level, int x, int y, int z, int data, shared_ptr<Player> player)
101{
102 if (player->abilities.instabuild)
103 {
104 // prevent resource drop
105 data |= NO_DROP_BIT;
106 level->setData(x, y, z, data, Tile::UPDATE_NONE);
107 }
108 BaseEntityTile::playerWillDestroy(level, x, y, z, data, player);
109}
110
111void SkullTile::onRemove(Level *level, int x, int y, int z, int id, int data)
112{
113 if (level->isClientSide) return;
114 if ((data & NO_DROP_BIT) == 0)
115 {
116 shared_ptr<ItemInstance> item = shared_ptr<ItemInstance>(new ItemInstance(Item::skull_Id, 1, cloneTileData(level, x, y, z)));
117 shared_ptr<SkullTileEntity> entity = dynamic_pointer_cast<SkullTileEntity>(level->getTileEntity(x, y, z));
118
119 if (entity->getSkullType() == SkullTileEntity::TYPE_CHAR && !entity->getExtraType().empty())
120 {
121 item->setTag(new CompoundTag());
122 item->getTag()->putString(L"SkullOwner", entity->getExtraType());
123 }
124
125 popResource(level, x, y, z, item);
126 }
127 BaseEntityTile::onRemove(level, x, y, z, id, data);
128}
129
130int SkullTile::getResource(int data, Random *random, int playerBonusLevel)
131{
132 return Item::skull_Id;
133}
134
135void SkullTile::checkMobSpawn(Level *level, int x, int y, int z, shared_ptr<SkullTileEntity> placedSkull)
136{
137 if (placedSkull->getSkullType() == SkullTileEntity::TYPE_WITHER && y >= 2 && level->difficulty > Difficulty::PEACEFUL && !level->isClientSide)
138 {
139 // Check wither boss spawn
140 int ss = Tile::soulsand_Id;
141
142 // North-south alignment
143 for (int zo = -2; zo <= 0; zo++)
144 {
145 if ( //
146 level->getTile(x, y - 1, z + zo) == ss && //
147 level->getTile(x, y - 1, z + zo + 1) == ss && //
148 level->getTile(x, y - 2, z + zo + 1) == ss && //
149 level->getTile(x, y - 1, z + zo + 2) == ss && //
150 isSkullAt(level, x, y, z + zo, SkullTileEntity::TYPE_WITHER) && //
151 isSkullAt(level, x, y, z + zo + 1, SkullTileEntity::TYPE_WITHER) && //
152 isSkullAt(level, x, y, z + zo + 2, SkullTileEntity::TYPE_WITHER))
153 {
154 level->setData(x, y, z + zo, NO_DROP_BIT, Tile::UPDATE_CLIENTS);
155 level->setData(x, y, z + zo + 1, NO_DROP_BIT, Tile::UPDATE_CLIENTS);
156 level->setData(x, y, z + zo + 2, NO_DROP_BIT, Tile::UPDATE_CLIENTS);
157 level->setTileAndData(x, y, z + zo, 0, 0, Tile::UPDATE_CLIENTS);
158 level->setTileAndData(x, y, z + zo + 1, 0, 0, Tile::UPDATE_CLIENTS);
159 level->setTileAndData(x, y, z + zo + 2, 0, 0, Tile::UPDATE_CLIENTS);
160 level->setTileAndData(x, y - 1, z + zo, 0, 0, Tile::UPDATE_CLIENTS);
161 level->setTileAndData(x, y - 1, z + zo + 1, 0, 0, Tile::UPDATE_CLIENTS);
162 level->setTileAndData(x, y - 1, z + zo + 2, 0, 0, Tile::UPDATE_CLIENTS);
163 level->setTileAndData(x, y - 2, z + zo + 1, 0, 0, Tile::UPDATE_CLIENTS);
164
165 // 4J: Check that we can spawn a Wither
166 if (level->canCreateMore(eTYPE_WITHERBOSS, Level::eSpawnType_Egg))
167 {
168 // 4J: Removed !isClientSide check because there's one earlier on
169 shared_ptr<WitherBoss> witherBoss = shared_ptr<WitherBoss>( new WitherBoss(level) );
170 witherBoss->moveTo(x + 0.5, y - 1.45, z + zo + 1.5, 90, 0);
171 witherBoss->yBodyRot = 90;
172 witherBoss->makeInvulnerable();
173 level->addEntity(witherBoss);
174 }
175 else
176 {
177 // 4J: Can't spawn, drop resource instead
178 Tile::tiles[Tile::soulsand_Id]->spawnResources(level, x, y - 1, z + zo, 0, 0);
179 Tile::tiles[Tile::soulsand_Id]->spawnResources(level, x, y - 1, z + zo + 1, 0, 0);
180 Tile::tiles[Tile::soulsand_Id]->spawnResources(level, x, y - 2, z + zo + 1, 0, 0);
181 Tile::tiles[Tile::soulsand_Id]->spawnResources(level, x, y - 1, z + zo + 2, 0, 0);
182
183 shared_ptr<ItemInstance> itemInstance = shared_ptr<ItemInstance>(new ItemInstance(Item::skull_Id, 3, SkullTileEntity::TYPE_WITHER));
184 shared_ptr<ItemEntity> itemEntity = shared_ptr<ItemEntity>(new ItemEntity(level, x, y, z + zo + 1, itemInstance) );
185 level->addEntity(itemEntity);
186 }
187
188 for (int i = 0; i < 120; i++)
189 {
190 level->addParticle(eParticleType_snowballpoof, x + level->random->nextDouble(), y - 2 + level->random->nextDouble() * 3.9, z + zo + 1 + level->random->nextDouble(), 0, 0, 0);
191 }
192
193 level->tileUpdated(x, y, z + zo, 0);
194 level->tileUpdated(x, y, z + zo + 1, 0);
195 level->tileUpdated(x, y, z + zo + 2, 0);
196 level->tileUpdated(x, y - 1, z + zo, 0);
197 level->tileUpdated(x, y - 1, z + zo + 1, 0);
198 level->tileUpdated(x, y - 1, z + zo + 2, 0);
199 level->tileUpdated(x, y - 2, z + zo + 1, 0);
200
201 return;
202 }
203 }
204 // West-east alignment
205 for (int xo = -2; xo <= 0; xo++)
206 {
207 if ( //
208 level->getTile(x + xo, y - 1, z) == ss && //
209 level->getTile(x + xo + 1, y - 1, z) == ss && //
210 level->getTile(x + xo + 1, y - 2, z) == ss && //
211 level->getTile(x + xo + 2, y - 1, z) == ss && //
212 isSkullAt(level, x + xo, y, z, SkullTileEntity::TYPE_WITHER) && //
213 isSkullAt(level, x + xo + 1, y, z, SkullTileEntity::TYPE_WITHER) && //
214 isSkullAt(level, x + xo + 2, y, z, SkullTileEntity::TYPE_WITHER))
215 {
216
217 level->setData(x + xo, y, z, NO_DROP_BIT, Tile::UPDATE_CLIENTS);
218 level->setData(x + xo + 1, y, z, NO_DROP_BIT, Tile::UPDATE_CLIENTS);
219 level->setData(x + xo + 2, y, z, NO_DROP_BIT, Tile::UPDATE_CLIENTS);
220 level->setTileAndData(x + xo, y, z, 0, 0, Tile::UPDATE_CLIENTS);
221 level->setTileAndData(x + xo + 1, y, z, 0, 0, Tile::UPDATE_CLIENTS);
222 level->setTileAndData(x + xo + 2, y, z, 0, 0, Tile::UPDATE_CLIENTS);
223 level->setTileAndData(x + xo, y - 1, z, 0, 0, Tile::UPDATE_CLIENTS);
224 level->setTileAndData(x + xo + 1, y - 1, z, 0, 0, Tile::UPDATE_CLIENTS);
225 level->setTileAndData(x + xo + 2, y - 1, z, 0, 0, Tile::UPDATE_CLIENTS);
226 level->setTileAndData(x + xo + 1, y - 2, z, 0, 0, Tile::UPDATE_CLIENTS);
227
228 // 4J: Check that we can spawn a Wither
229 if (level->canCreateMore(eTYPE_WITHERBOSS, Level::eSpawnType_Egg))
230 {
231 // 4J: Removed !isClientSide check because there's one earlier on
232 shared_ptr<WitherBoss> witherBoss = shared_ptr<WitherBoss>( new WitherBoss(level) );
233 witherBoss->moveTo(x + xo + 1.5, y - 1.45, z + .5, 0, 0);
234 witherBoss->makeInvulnerable();
235 level->addEntity(witherBoss);
236 }
237 else
238 {
239 // 4J: Can't spawn, drop resource instead
240 Tile::tiles[Tile::soulsand_Id]->spawnResources(level, x + xo, y - 1, z, 0, 0);
241 Tile::tiles[Tile::soulsand_Id]->spawnResources(level, x + xo + 1, y - 1, z, 0, 0);
242 Tile::tiles[Tile::soulsand_Id]->spawnResources(level, x + xo + 1, y - 2, z, 0, 0);
243 Tile::tiles[Tile::soulsand_Id]->spawnResources(level, x + xo + 2, y - 1, z, 0, 0);
244
245 shared_ptr<ItemInstance> itemInstance = shared_ptr<ItemInstance>(new ItemInstance(Item::skull_Id, 3, SkullTileEntity::TYPE_WITHER));
246 shared_ptr<ItemEntity> itemEntity = shared_ptr<ItemEntity>(new ItemEntity(level, x + xo + 1, y, z, itemInstance) );
247 level->addEntity(itemEntity);
248 }
249
250 for (int i = 0; i < 120; i++)
251 {
252 level->addParticle(eParticleType_snowballpoof, x + xo + 1 + level->random->nextDouble(), y - 2 + level->random->nextDouble() * 3.9, z + level->random->nextDouble(), 0, 0, 0);
253 }
254
255 level->tileUpdated(x + xo, y, z, 0);
256 level->tileUpdated(x + xo + 1, y, z, 0);
257 level->tileUpdated(x + xo + 2, y, z, 0);
258 level->tileUpdated(x + xo, y - 1, z, 0);
259 level->tileUpdated(x + xo + 1, y - 1, z, 0);
260 level->tileUpdated(x + xo + 2, y - 1, z, 0);
261 level->tileUpdated(x + xo + 1, y - 2, z, 0);
262
263 return;
264 }
265 }
266 }
267}
268
269bool SkullTile::isSkullAt(Level *level, int x, int y, int z, int skullType)
270{
271 if (level->getTile(x, y, z) != id)
272 {
273 return false;
274 }
275 shared_ptr<TileEntity> te = level->getTileEntity(x, y, z);
276 shared_ptr<SkullTileEntity> skull = dynamic_pointer_cast<SkullTileEntity>(te);
277 if (skull == NULL)
278 {
279 return false;
280 }
281 return skull->getSkullType() == skullType;
282}
283
284void SkullTile::registerIcons(IconRegister *iconRegister)
285{
286 // None
287}
288
289Icon *SkullTile::getTexture(int face, int data)
290{
291 return Tile::soulsand->getTexture(face);
292}
293
294wstring SkullTile::getTileItemIconName()
295{
296 return getIconName() + L"_" + SkullItem::ICON_NAMES[0];
297}