diff options
| author | daoge_cmd <3523206925@qq.com> | 2026-03-01 12:16:08 +0800 |
|---|---|---|
| committer | daoge_cmd <3523206925@qq.com> | 2026-03-01 12:16:08 +0800 |
| commit | b691c43c44ff180d10e7d4a9afc83b98551ff586 (patch) | |
| tree | 3e9849222cbc6ba49f2f1fc6e5fe7179632c7390 /Minecraft.World/PrimedTnt.cpp | |
| parent | def8cb415354ac390b7e89052a50605285f1aca9 (diff) | |
Initial commit
Diffstat (limited to 'Minecraft.World/PrimedTnt.cpp')
| -rw-r--r-- | Minecraft.World/PrimedTnt.cpp | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/Minecraft.World/PrimedTnt.cpp b/Minecraft.World/PrimedTnt.cpp new file mode 100644 index 00000000..09926d50 --- /dev/null +++ b/Minecraft.World/PrimedTnt.cpp @@ -0,0 +1,116 @@ +#include "stdafx.h" +#include "JavaMath.h" +#include "com.mojang.nbt.h" +#include "net.minecraft.world.level.h" +#include "PrimedTnt.h" + + + +void PrimedTnt::_init() +{ + life = 0; + + // Original Java Ctor + blocksBuilding = true; + setSize(0.98f, 0.98f); + heightOffset = bbHeight / 2.0f; +} + +PrimedTnt::PrimedTnt(Level *level) : Entity( level ) +{ + // 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(); + + _init(); +} + +PrimedTnt::PrimedTnt(Level *level, double x, double y, double z) : Entity( level ) +{ + _init(); + + setPos(x, y, z); + + float rot = (float) (Math::random() * PI * 2); + xd = -sin(rot) * 0.02f; + yd = +0.2f; + zd = -cos(rot) * 0.02f; + + life = 80; + + xo = x; + yo = y; + zo = z; +} + +void PrimedTnt::defineSynchedData() +{ +} + +bool PrimedTnt::makeStepSound() +{ + return false; +} + +bool PrimedTnt::isPickable() +{ + return !removed; +} + +void PrimedTnt::tick() +{ + xo = x; + yo = y; + zo = z; + + yd -= 0.04f; + move(xd, yd, zd); + xd *= 0.98f; + yd *= 0.98f; + zd *= 0.98f; + + if (onGround) + { + xd *= 0.7f; + zd *= 0.7f; + yd *= -0.5f; + } + + if (life-- <= 0) + { + remove(); + if (!level->isClientSide) + { + explode(); + } + } + else + { + level->addParticle(eParticleType_smoke, x, y + 0.5f, z, 0, 0, 0); + } + +} + + +void PrimedTnt::explode() +{ + float r = 4.0f; + level->explode(nullptr, x, y, z, r, true); +} + + +void PrimedTnt::addAdditonalSaveData(CompoundTag *entityTag) +{ + entityTag->putByte(L"Fuse", (byte) life); +} + +void PrimedTnt::readAdditionalSaveData(CompoundTag *tag) +{ + life = tag->getByte(L"Fuse"); +} + + +float PrimedTnt::getShadowHeightOffs() +{ + return 0; +}
\ No newline at end of file |
