Files
MinecraftConsoles/Minecraft.World/ThrownEgg.cpp
void_17 7074f35e4b shared_ptr -> std::shared_ptr
This is one of the first commits in a plan to remove all `using namespace std;` lines in the entire codebase as it is considered anti-pattern today.
2026-03-02 15:58:20 +07:00

68 lines
1.6 KiB
C++

#include "stdafx.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.phys.h"
#include "net.minecraft.world.entity.animal.h"
#include "net.minecraft.world.damagesource.h"
#include "com.mojang.nbt.h"
#include "ThrownEgg.h"
#include "MobCategory.h"
void ThrownEgg::_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();
}
ThrownEgg::ThrownEgg(Level *level) : Throwable(level)
{
_init();
}
ThrownEgg::ThrownEgg(Level *level, std::shared_ptr<Mob> mob) : Throwable(level,mob)
{
_init();
}
ThrownEgg::ThrownEgg(Level *level, double x, double y, double z) : Throwable(level,x,y,z)
{
_init();
}
void ThrownEgg::onHit(HitResult *res)
{
if (res->entity != NULL)
{
DamageSource *damageSource = DamageSource::thrown(shared_from_this(), owner);
res->entity->hurt(damageSource, 0);
delete damageSource;
}
if (!level->isClientSide && random->nextInt(8) == 0)
{
if(level->canCreateMore( eTYPE_CHICKEN, Level::eSpawnType_Breed) ) // 4J - added limit for number of chickens in world
{
int count = 1;
if (random->nextInt(32) == 0) count = 4;
for (int i = 0; i < count; i++)
{
std::shared_ptr<Chicken> chicken = std::shared_ptr<Chicken>( new Chicken(level) );
chicken->setAge(-20 * 60 * 20);
chicken->moveTo(x, y, z, yRot, 0);
chicken->setDespawnProtected(); // 4J added, default to being protected against despawning
level->addEntity(chicken);
}
}
}
for (int i = 0; i < 8; i++)
level->addParticle(eParticleType_snowballpoof, x, y, z, 0, 0, 0);
if (!level->isClientSide)
{
remove();
}
}