aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/MinecartTNT.cpp
diff options
context:
space:
mode:
authordaoge <3523206925@qq.com>2026-03-03 03:04:10 +0800
committerGitHub <noreply@github.com>2026-03-03 03:04:10 +0800
commitb3feddfef372618c8a9d7a0abcaf18cfad866c18 (patch)
tree267761c3bb39241ba5c347bfbe2254d06686e287 /Minecraft.World/MinecartTNT.cpp
parent84c31a2331f7a0ec85b9d438992e244f60e5020f (diff)
feat: TU19 (Dec 2014) Features & Content (#155)
* try to resolve merge conflict * feat: TU19 (Dec 2014) Features & Content (#32) * December 2014 files * Working release build * Fix compilation issues * Add sound to Windows64Media * Add DLC content and force Tutorial DLC * Revert "Add DLC content and force Tutorial DLC" This reverts commit 97a43994725008e35fceb984d5549df9c8cea470. * Disable broken light packing * Disable breakpoint during DLC texture map load Allows DLC loading but the DLC textures are still broken * Fix post build not working * ... * fix vs2022 build * fix cmake build --------- Co-authored-by: Loki <lokirautio@gmail.com>
Diffstat (limited to 'Minecraft.World/MinecartTNT.cpp')
-rw-r--r--Minecraft.World/MinecartTNT.cpp168
1 files changed, 168 insertions, 0 deletions
diff --git a/Minecraft.World/MinecartTNT.cpp b/Minecraft.World/MinecartTNT.cpp
new file mode 100644
index 00000000..26cac5cf
--- /dev/null
+++ b/Minecraft.World/MinecartTNT.cpp
@@ -0,0 +1,168 @@
+#include "stdafx.h"
+#include "net.minecraft.world.damagesource.h"
+#include "net.minecraft.world.level.h"
+#include "net.minecraft.world.level.tile.h"
+#include "MinecartTNT.h"
+
+void MinecartTNT::_init()
+{
+ // 4J Stu - This function call had to be moved here from the Entity ctor to ensure that
+ // the derived version of the function is called
+ this->defineSynchedData();
+
+ fuse = -1;
+}
+
+MinecartTNT::MinecartTNT(Level *level) : Minecart(level)
+{
+ _init();
+}
+
+MinecartTNT::MinecartTNT(Level *level, double x, double y, double z) : Minecart(level, x, y, z)
+{
+ _init();
+}
+
+int MinecartTNT::getType()
+{
+ return TYPE_TNT;
+}
+
+Tile *MinecartTNT::getDefaultDisplayTile()
+{
+ return Tile::tnt;
+}
+
+void MinecartTNT::tick()
+{
+ Minecart::tick();
+
+ if (fuse > 0)
+ {
+ fuse--;
+ level->addParticle(eParticleType_smoke, x, y + 0.5f, z, 0, 0, 0);
+ }
+ else if (fuse == 0)
+ {
+ explode(xd * xd + zd * zd);
+ }
+
+ if (horizontalCollision)
+ {
+ double speedSqr = xd * xd + zd * zd;
+
+ if (speedSqr >= 0.01f)
+ {
+ explode(speedSqr);
+ }
+ }
+}
+
+void MinecartTNT::destroy(DamageSource *source)
+{
+ Minecart::destroy(source);
+
+ double speedSqr = xd * xd + zd * zd;
+
+ if (!source->isExplosion())
+ {
+ spawnAtLocation( shared_ptr<ItemInstance>( new ItemInstance(Tile::tnt, 1) ), 0);
+ }
+
+ if (source->isFire() || source->isExplosion() || speedSqr >= 0.01f)
+ {
+ explode(speedSqr);
+ }
+}
+
+void MinecartTNT::explode(double speedSqr)
+{
+ if (!level->isClientSide)
+ {
+ double speed = sqrt(speedSqr);
+ if (speed > 5) speed = 5;
+ level->explode(shared_from_this(), x, y, z, (float) (4 + random->nextDouble() * 1.5f * speed), true);
+ remove();
+ }
+}
+
+void MinecartTNT::causeFallDamage(float distance)
+{
+ if (distance >= 3)
+ {
+ float power = distance / 10;
+ explode(power * power);
+ }
+
+ Minecart::causeFallDamage(distance);
+}
+
+void MinecartTNT::activateMinecart(int xt, int yt, int zt, bool state)
+{
+ if (state && fuse < 0)
+ {
+ primeFuse();
+ }
+}
+
+void MinecartTNT::handleEntityEvent(byte eventId)
+{
+ if (eventId == EVENT_PRIME)
+ {
+ primeFuse();
+ }
+ else
+ {
+ Minecart::handleEntityEvent(eventId);
+ }
+}
+
+void MinecartTNT::primeFuse()
+{
+ fuse = 80;
+
+ if (!level->isClientSide)
+ {
+ level->broadcastEntityEvent(shared_from_this(), EVENT_PRIME);
+ level->playEntitySound(shared_from_this(), eSoundType_RANDOM_FUSE, 1, 1.0f);
+ }
+}
+
+int MinecartTNT::getFuse()
+{
+ return fuse;
+}
+
+bool MinecartTNT::isPrimed()
+{
+ return fuse > -1;
+}
+
+float MinecartTNT::getTileExplosionResistance(Explosion *explosion, Level *level, int x, int y, int z, Tile *tile)
+{
+ if (isPrimed() && (BaseRailTile::isRail(tile->id) || BaseRailTile::isRail(level, x, y + 1, z)))
+ {
+ return 0;
+ }
+
+ return Minecart::getTileExplosionResistance(explosion, level, x, y, z, tile);
+}
+
+bool MinecartTNT::shouldTileExplode(Explosion *explosion, Level *level, int x, int y, int z, int id, float power)
+{
+ if (isPrimed() && (BaseRailTile::isRail(id) || BaseRailTile::isRail(level, x, y + 1, z))) return false;
+
+ return Minecart::shouldTileExplode(explosion, level, x, y, z, id, power);
+}
+
+void MinecartTNT::readAdditionalSaveData(CompoundTag *tag)
+{
+ Minecart::readAdditionalSaveData(tag);
+ if (tag->contains(L"TNTFuse")) fuse = tag->getInt(L"TNTFuse");
+}
+
+void MinecartTNT::addAdditonalSaveData(CompoundTag *tag)
+{
+ Minecart::addAdditonalSaveData(tag);
+ tag->putInt(L"TNTFuse", fuse);
+} \ No newline at end of file