Files
MinecraftConsoles/Minecraft.World/EyeOfEnderSignal.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

202 lines
4.0 KiB
C++

#include "stdafx.h"
#include "net.minecraft.world.phys.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.tile.h"
#include "net.minecraft.world.item.h"
#include "net.minecraft.world.entity.item.h"
#include "SharedConstants.h"
#include "JavaMath.h"
#include "EyeOfEnderSignal.h"
void EyeOfEnderSignal::_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();
// Initialisors
shakeTime = 0;
tx = ty = tz = 0.0;
life = 0;
surviveAfterDeath = false;
}
EyeOfEnderSignal::EyeOfEnderSignal(Level *level) : Entity(level)
{
_init();
setSize(0.25f, 0.25f);
}
void EyeOfEnderSignal::defineSynchedData()
{
}
bool EyeOfEnderSignal::shouldRenderAtSqrDistance(double distance)
{
double size = bb->getSize() * 4;
size *= 64.0f;
return distance < size * size;
}
EyeOfEnderSignal::EyeOfEnderSignal(Level *level, double x, double y, double z) : Entity(level)
{
_init();
life = 0;
setSize(0.25f, 0.25f);
setPos(x, y, z);
heightOffset = 0;
}
void EyeOfEnderSignal::signalTo(double tx, int ty, double tz)
{
double dx = tx - x, dz = tz - z;
float dist = sqrt(dx * dx + dz * dz);
if (dist > 12)
{
this->tx = x + (dx / dist) * 12;
this->tz = z + (dz / dist) * 12;
this->ty = y + 8;
}
else
{
this->tx = tx;
this->ty = ty;
this->tz = tz;
}
life = 0;
surviveAfterDeath = random->nextInt(5) > 0;
}
void EyeOfEnderSignal::lerpMotion(double xd, double yd, double zd)
{
this->xd = xd;
this->yd = yd;
this->zd = zd;
if (xRotO == 0 && yRotO == 0)
{
float sd = static_cast<float>(sqrt(xd * xd + zd * zd));
yRotO = yRot = static_cast<float>(atan2(xd, zd) * 180 / PI);
xRotO = xRot = static_cast<float>(atan2(yd, (double)sd) * 180 / PI);
}
}
void EyeOfEnderSignal::tick()
{
xOld = x;
yOld = y;
zOld = z;
Entity::tick();
x += xd;
y += yd;
z += zd;
float sd = static_cast<float>(sqrt(xd * xd + zd * zd));
yRot = static_cast<float>(atan2(xd, zd) * 180 / PI);
xRot = static_cast<float>(atan2(yd, (double)sd) * 180 / PI);
while (xRot - xRotO < -180)
xRotO -= 360;
while (xRot - xRotO >= 180)
xRotO += 360;
while (yRot - yRotO < -180)
yRotO -= 360;
while (yRot - yRotO >= 180)
yRotO += 360;
xRot = xRotO + (xRot - xRotO) * 0.2f;
yRot = yRotO + (yRot - yRotO) * 0.2f;
if (!level->isClientSide)
{
double dx = tx - x, dz = tz - z;
float tdist = static_cast<float>(sqrt(dx * dx + dz * dz));
float angle = static_cast<float>(atan2(dz, dx));
double tspeed = (sd + (tdist - sd) * .0025);
if (tdist < 1)
{
tspeed *= .8;
yd *= .8;
}
xd = cos(angle) * tspeed;
zd = sin(angle) * tspeed;
if (y < ty)
{
yd = yd + (1 - yd) * .015f;
}
else
{
yd = yd + (-1 - yd) * .015f;
}
}
float s = 1 / 4.0f;
if (isInWater())
{
for (int i = 0; i < 4; i++)
{
level->addParticle(eParticleType_bubble, x - xd * s, y - yd * s, z - zd * s, xd, yd, zd);
}
}
else
{
level->addParticle(eParticleType_ender, x - xd * s + random->nextDouble() * .6 - .3, y - yd * s - .5, z - zd * s + random->nextDouble() * .6 - .3, xd, yd, zd);
}
if (!level->isClientSide)
{
setPos(x, y, z);
life++;
if (life > SharedConstants::TICKS_PER_SECOND * 4 && !level->isClientSide)
{
remove();
if (surviveAfterDeath)
{
level->addEntity(std::make_shared<ItemEntity>(level, x, y, z, shared_ptr<ItemInstance>(new ItemInstance(Item::eyeOfEnder))));
}
else
{
level->levelEvent(LevelEvent::PARTICLES_EYE_OF_ENDER_DEATH, static_cast<int>(Math::round(x)), static_cast<int>(Math::round(y)), static_cast<int>(Math::round(z)), 0);
}
}
}
}
void EyeOfEnderSignal::addAdditonalSaveData(CompoundTag *tag)
{
}
void EyeOfEnderSignal::readAdditionalSaveData(CompoundTag *tag)
{
}
float EyeOfEnderSignal::getShadowHeightOffs()
{
return 0;
}
float EyeOfEnderSignal::getBrightness(float a)
{
return 1.0f;
}
int EyeOfEnderSignal::getLightColor(float a)
{
return 15 << 20 | 15 << 4;
}
bool EyeOfEnderSignal::isAttackable()
{
return false;
}