Files
MinecraftConsoles/Minecraft.World/MobSpawnerTileEntity.cpp
ModMaker101 a9be52c41a Project modernization (#630)
* Fixed boats falling and a TP glitch #266

* Replaced every C-style cast with C++ ones

* Replaced every C-style cast with C++ ones

* Fixed boats falling and a TP glitch #266

* Updated NULL to nullptr and fixing some type issues

* Modernized and fixed a few bugs

- Replaced most instances of `NULL` with `nullptr`.
- Replaced most `shared_ptr(new ...)` with `make_shared`.
- Removed the `nullptr` macro as it was interfering with the actual nullptr keyword in some instances.

* Fixing more conflicts

* Replace int loops with size_t and start work on overrides
2026-03-08 09:56:03 +07:00

102 lines
2.2 KiB
C++

#include "stdafx.h"
#include "net.minecraft.network.packet.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.tile.h"
#include "MobSpawnerTileEntity.h"
MobSpawnerTileEntity::TileEntityMobSpawner::TileEntityMobSpawner(MobSpawnerTileEntity *parent)
{
m_parent = parent;
}
void MobSpawnerTileEntity::TileEntityMobSpawner::broadcastEvent(int id)
{
m_parent->level->tileEvent(m_parent->x, m_parent->y, m_parent->z, Tile::mobSpawner_Id, id, 0);
}
Level *MobSpawnerTileEntity::TileEntityMobSpawner::getLevel()
{
return m_parent->level;
}
int MobSpawnerTileEntity::TileEntityMobSpawner::getX()
{
return m_parent->x;
}
int MobSpawnerTileEntity::TileEntityMobSpawner::getY()
{
return m_parent->y;
}
int MobSpawnerTileEntity::TileEntityMobSpawner::getZ()
{
return m_parent->z;
}
void MobSpawnerTileEntity::TileEntityMobSpawner::setNextSpawnData(BaseMobSpawner::SpawnData *nextSpawnData)
{
BaseMobSpawner::setNextSpawnData(nextSpawnData);
if (getLevel() != nullptr) getLevel()->sendTileUpdated(m_parent->x, m_parent->y, m_parent->z);
}
MobSpawnerTileEntity::MobSpawnerTileEntity()
{
spawner = new TileEntityMobSpawner(this);
}
MobSpawnerTileEntity::~MobSpawnerTileEntity()
{
delete spawner;
}
void MobSpawnerTileEntity::load(CompoundTag *tag)
{
TileEntity::load(tag);
spawner->load(tag);
}
void MobSpawnerTileEntity::save(CompoundTag *tag)
{
TileEntity::save(tag);
spawner->save(tag);
}
void MobSpawnerTileEntity::tick()
{
spawner->tick();
TileEntity::tick();
}
shared_ptr<Packet> MobSpawnerTileEntity::getUpdatePacket()
{
CompoundTag *tag = new CompoundTag();
save(tag);
tag->remove(L"SpawnPotentials");
return std::make_shared<TileEntityDataPacket>(x, y, z, TileEntityDataPacket::TYPE_MOB_SPAWNER, tag);
}
bool MobSpawnerTileEntity::triggerEvent(int b0, int b1)
{
if (spawner->onEventTriggered(b0)) return true;
return TileEntity::triggerEvent(b0, b1);
}
BaseMobSpawner *MobSpawnerTileEntity::getSpawner()
{
return spawner;
}
// 4J Added
shared_ptr<TileEntity> MobSpawnerTileEntity::clone()
{
shared_ptr<MobSpawnerTileEntity> result = std::make_shared<MobSpawnerTileEntity>();
TileEntity::clone(result);
return result;
}
void MobSpawnerTileEntity::setEntityId(const wstring &id)
{
spawner->setEntityId(id);
}