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/EnderCrystal.cpp | |
| parent | def8cb415354ac390b7e89052a50605285f1aca9 (diff) | |
Initial commit
Diffstat (limited to 'Minecraft.World/EnderCrystal.cpp')
| -rw-r--r-- | Minecraft.World/EnderCrystal.cpp | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/Minecraft.World/EnderCrystal.cpp b/Minecraft.World/EnderCrystal.cpp new file mode 100644 index 00000000..719e9d96 --- /dev/null +++ b/Minecraft.World/EnderCrystal.cpp @@ -0,0 +1,128 @@ +#include "stdafx.h" +#include "net.minecraft.world.level.h" +#include "net.minecraft.world.level.tile.h" +#include "net.minecraft.world.entity.h" +#include "net.minecraft.world.entity.boss.enderdragon.h" +#include "EnderCrystal.h" +#include "DamageSource.h" + + + +void EnderCrystal::_init(Level *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(); + + blocksBuilding = true; + setSize(2.0f, 2.0f); + heightOffset = bbHeight / 2.0f; + life = MAX_LIFE; + + time = random->nextInt(100000); +} + +EnderCrystal::EnderCrystal(Level *level) : Entity( level ) +{ + _init(level); + +} + +EnderCrystal::EnderCrystal(Level *level, double x, double y, double z) : Entity( level ) +{ + _init(level); + setPos(x, y, z); + +} + +bool EnderCrystal::makeStepSound() +{ + return false; +} + +void EnderCrystal::defineSynchedData() +{ + entityData->define(DATA_REMAINING_LIFE, life); +} + +void EnderCrystal::tick() +{ + xo = x; + yo = y; + zo = z; + time++; + + entityData->set(DATA_REMAINING_LIFE, life); + + // Don't set the tile directly on the client, as this can end up in the updatesToReset queue in the MultiPlayerLevel, and the perpetually end up removing/adding these fire tiles causing timing + // glitches from the lighting changes requried. + if (!level->isClientSide) + { + int xt = Mth::floor(x); + int yt = Mth::floor(y); + int zt = Mth::floor(z); + if (level->getTile(xt, yt, zt) != Tile::fire_Id) + { + level->setTile(xt, yt, zt, Tile::fire_Id); + } + } +} + + +void EnderCrystal::addAdditonalSaveData(CompoundTag *tag) +{ +} + +void EnderCrystal::readAdditionalSaveData(CompoundTag *tag) +{ +} + + +float EnderCrystal::getShadowHeightOffs() +{ + return 0; +} + +bool EnderCrystal::isPickable() +{ + return true; +} + +bool EnderCrystal::hurt(DamageSource *source, int damage) +{ + // 4J-PB - if the owner of the source is the enderdragon, then ignore it (where the dragon's fireball hits an endercrystal) + shared_ptr<EnderDragon> sourceIsDragon = dynamic_pointer_cast<EnderDragon>(source->getEntity()); + + if(sourceIsDragon!=NULL) + { + return false; + } + + if (!removed && !level->isClientSide) + { + life = 0; + if (life <= 0) + { + remove(); + if (!level->isClientSide) + { + level->explode(nullptr, x, y, z, 6, true); + + vector<shared_ptr<Entity> > entities = level->getAllEntities(); + shared_ptr<EnderDragon> dragon = nullptr; + AUTO_VAR(itEnd, entities.end()); + for (AUTO_VAR(it, entities.begin()); it != itEnd; it++) + { + shared_ptr<Entity> e = *it; //entities->at(i); + dragon = dynamic_pointer_cast<EnderDragon>(e); + if(dragon != NULL) + { + dragon->handleCrystalDestroyed(source); + break; + } + } + } + } + } + return true; +}
\ No newline at end of file |
