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.level.h"
3#include "net.minecraft.world.entity.item.h"
4#include "net.minecraft.world.entity.projectile.h"
5#include "net.minecraft.world.item.h"
6#include "net.minecraft.world.h"
7#include "net.minecraft.h"
8
9#include "TntTile.h"
10#include "SoundTypes.h"
11
12
13TntTile::TntTile(int id) : Tile(id, Material::explosive)
14{
15 iconTop = NULL;
16 iconBottom = NULL;
17}
18
19Icon *TntTile::getTexture(int face, int data)
20{
21 if (face == Facing::DOWN) return iconBottom;
22 if (face == Facing::UP) return iconTop;
23 return icon;
24}
25
26void TntTile::onPlace(Level *level, int x, int y, int z)
27{
28 Tile::onPlace(level, x, y, z);
29 if (level->hasNeighborSignal(x, y, z) && app.GetGameHostOption(eGameHostOption_TNT))
30 {
31 destroy(level, x, y, z, EXPLODE_BIT);
32 level->removeTile(x, y, z);
33 }
34}
35
36void TntTile::neighborChanged(Level *level, int x, int y, int z, int type)
37{
38 if (level->hasNeighborSignal(x, y, z) && app.GetGameHostOption(eGameHostOption_TNT))
39 {
40 destroy(level, x, y, z, EXPLODE_BIT);
41 level->removeTile(x, y, z);
42 }
43}
44
45int TntTile::getResourceCount(Random *random)
46{
47 return 1;
48}
49
50void TntTile::wasExploded(Level *level, int x, int y, int z, Explosion *explosion)
51{
52 // 4J - added - don't every create on the client, I think this must be the cause of a bug reported in the java
53 // version where white tnts are created in the network game
54 if (level->isClientSide) return;
55
56 // 4J - added condition to have finite limit of these
57 // 4J-JEV: Fix for #90934 - Customer Encountered: TU11: Content: Gameplay: TNT blocks are triggered by explosions even though "TNT explodes" option is unchecked.
58 if( level->newPrimedTntAllowed() && app.GetGameHostOption(eGameHostOption_TNT) )
59 {
60 shared_ptr<PrimedTnt> primed = shared_ptr<PrimedTnt>( new PrimedTnt(level, x + 0.5f, y + 0.5f, z + 0.5f, explosion->getSourceMob()) );
61 primed->life = level->random->nextInt(primed->life / 4) + primed->life / 8;
62 level->addEntity(primed);
63 }
64}
65
66void TntTile::destroy(Level *level, int x, int y, int z, int data)
67{
68 destroy(level, x, y, z, data, nullptr);
69}
70
71void TntTile::destroy(Level *level, int x, int y, int z, int data, shared_ptr<LivingEntity> source)
72{
73 if (level->isClientSide) return;
74
75 if ((data & EXPLODE_BIT) == 1 )
76 {
77 // 4J - added condition to have finite limit of these
78 if( level->newPrimedTntAllowed() && app.GetGameHostOption(eGameHostOption_TNT) )
79 {
80 shared_ptr<PrimedTnt> tnt = shared_ptr<PrimedTnt>( new PrimedTnt(level, x + 0.5f, y + 0.5f, z + 0.5f, source) );
81 level->addEntity(tnt);
82 level->playEntitySound(tnt, eSoundType_RANDOM_FUSE, 1, 1.0f);
83 }
84 }
85}
86
87bool TntTile::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
88{
89 if (soundOnly) return false;
90 if (player->getSelectedItem() != NULL && player->getSelectedItem()->id == Item::flintAndSteel_Id)
91 {
92 destroy(level, x, y, z, EXPLODE_BIT, player);
93 level->removeTile(x, y, z);
94 player->getSelectedItem()->hurtAndBreak(1, player);
95 return true;
96 }
97 return Tile::use(level, x, y, z, player, clickedFace, clickX, clickY, clickZ);
98}
99
100void TntTile::entityInside(Level *level, int x, int y, int z, shared_ptr<Entity> entity)
101{
102 if (entity->GetType() == eTYPE_ARROW && !level->isClientSide)
103 {
104 if (entity->isOnFire())
105 {
106 shared_ptr<Arrow> arrow = dynamic_pointer_cast<Arrow>(entity);
107 destroy(level, x, y, z, EXPLODE_BIT, arrow->owner->instanceof(eTYPE_LIVINGENTITY) ? dynamic_pointer_cast<LivingEntity>(arrow->owner) : nullptr);
108 level->removeTile(x, y, z);
109 }
110 }
111}
112
113void TntTile::registerIcons(IconRegister *iconRegister)
114{
115 icon = iconRegister->registerIcon(L"tnt_side");
116 iconTop = iconRegister->registerIcon(L"tnt_top");
117 iconBottom = iconRegister->registerIcon(L"tnt_bottom");
118}
119
120bool TntTile::dropFromExplosion(Explosion *explosion)
121{
122 return false;
123}