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.damagesource.h"
3#include "net.minecraft.world.level.h"
4#include "net.minecraft.world.level.tile.h"
5#include "MinecartTNT.h"
6
7void MinecartTNT::_init()
8{
9 // 4J Stu - This function call had to be moved here from the Entity ctor to ensure that
10 // the derived version of the function is called
11 this->defineSynchedData();
12
13 fuse = -1;
14}
15
16MinecartTNT::MinecartTNT(Level *level) : Minecart(level)
17{
18 _init();
19}
20
21MinecartTNT::MinecartTNT(Level *level, double x, double y, double z) : Minecart(level, x, y, z)
22{
23 _init();
24}
25
26int MinecartTNT::getType()
27{
28 return TYPE_TNT;
29}
30
31Tile *MinecartTNT::getDefaultDisplayTile()
32{
33 return Tile::tnt;
34}
35
36void MinecartTNT::tick()
37{
38 Minecart::tick();
39
40 if (fuse > 0)
41 {
42 fuse--;
43 level->addParticle(eParticleType_smoke, x, y + 0.5f, z, 0, 0, 0);
44 }
45 else if (fuse == 0)
46 {
47 explode(xd * xd + zd * zd);
48 }
49
50 if (horizontalCollision)
51 {
52 double speedSqr = xd * xd + zd * zd;
53
54 if (speedSqr >= 0.01f)
55 {
56 explode(speedSqr);
57 }
58 }
59}
60
61void MinecartTNT::destroy(DamageSource *source)
62{
63 Minecart::destroy(source);
64
65 double speedSqr = xd * xd + zd * zd;
66
67 if (!source->isExplosion())
68 {
69 spawnAtLocation( shared_ptr<ItemInstance>( new ItemInstance(Tile::tnt, 1) ), 0);
70 }
71
72 if (source->isFire() || source->isExplosion() || speedSqr >= 0.01f)
73 {
74 explode(speedSqr);
75 }
76}
77
78void MinecartTNT::explode(double speedSqr)
79{
80 if (!level->isClientSide)
81 {
82 double speed = sqrt(speedSqr);
83 if (speed > 5) speed = 5;
84 level->explode(shared_from_this(), x, y, z, (float) (4 + random->nextDouble() * 1.5f * speed), true);
85 remove();
86 }
87}
88
89void MinecartTNT::causeFallDamage(float distance)
90{
91 if (distance >= 3)
92 {
93 float power = distance / 10;
94 explode(power * power);
95 }
96
97 Minecart::causeFallDamage(distance);
98}
99
100void MinecartTNT::activateMinecart(int xt, int yt, int zt, bool state)
101{
102 if (state && fuse < 0)
103 {
104 primeFuse();
105 }
106}
107
108void MinecartTNT::handleEntityEvent(byte eventId)
109{
110 if (eventId == EVENT_PRIME)
111 {
112 primeFuse();
113 }
114 else
115 {
116 Minecart::handleEntityEvent(eventId);
117 }
118}
119
120void MinecartTNT::primeFuse()
121{
122 fuse = 80;
123
124 if (!level->isClientSide)
125 {
126 level->broadcastEntityEvent(shared_from_this(), EVENT_PRIME);
127 level->playEntitySound(shared_from_this(), eSoundType_RANDOM_FUSE, 1, 1.0f);
128 }
129}
130
131int MinecartTNT::getFuse()
132{
133 return fuse;
134}
135
136bool MinecartTNT::isPrimed()
137{
138 return fuse > -1;
139}
140
141float MinecartTNT::getTileExplosionResistance(Explosion *explosion, Level *level, int x, int y, int z, Tile *tile)
142{
143 if (isPrimed() && (BaseRailTile::isRail(tile->id) || BaseRailTile::isRail(level, x, y + 1, z)))
144 {
145 return 0;
146 }
147
148 return Minecart::getTileExplosionResistance(explosion, level, x, y, z, tile);
149}
150
151bool MinecartTNT::shouldTileExplode(Explosion *explosion, Level *level, int x, int y, int z, int id, float power)
152{
153 if (isPrimed() && (BaseRailTile::isRail(id) || BaseRailTile::isRail(level, x, y + 1, z))) return false;
154
155 return Minecart::shouldTileExplode(explosion, level, x, y, z, id, power);
156}
157
158void MinecartTNT::readAdditionalSaveData(CompoundTag *tag)
159{
160 Minecart::readAdditionalSaveData(tag);
161 if (tag->contains(L"TNTFuse")) fuse = tag->getInt(L"TNTFuse");
162}
163
164void MinecartTNT::addAdditonalSaveData(CompoundTag *tag)
165{
166 Minecart::addAdditonalSaveData(tag);
167 tag->putInt(L"TNTFuse", fuse);
168}