mirror of
https://git.neolegacy.dev/neoStudiosLCE/neoLegacy.git
synced 2026-11-26 21:26:38 +01:00
Patch Notes: Blocks + Colored shulker boxes + Concrete powder + Concrete + Glazed terracotta Items + Shulker shell + Iron nugget UI Changes + Added Custom Controls to Keyboard & Mouse, as well as Controller + Added Custom SuperFlat + Added Edit Server Menu + Added Firework Crafting Feature Changes + Host Options + Added Pick Block + Added off-hand slot for maps and arrows. Bug Fixes & changes + TU47: Banner hitbox wrong (and inventory model fixed) + TU47/48: Ice not melting properly + TU48: Dead bushes not dropping sticks + TU48: Guardians and polar bears not dropping cooked fish when on fire + TU48: Bonus chest missing saplings and seeds + TU48: Frosted ice obtainable + TU48: Hoppers not collecting items + TU48: Wither skeletons spawning in 2-high gaps + TU48: End crystals exploding with “TNT Explodes” off + TU48: Tamed ocelots staying hostile + TU48: Signs not placing on tall grass + TU51: Skeleton hitbox wrong + TU53: Fall damage in shallow water + TU53: Squids not spawning in man-made pools + Elytra has been improved to be more accurate to the source material + Removed Spectral Arrow from crafting + Fixed several broken item descriptions + You can no longer cook Pufferfish or Clownfish + Fixed scaling issue with paperdoll and chat + Iron and gold armor can now be smelted into nuggets. + More items can now be used as fuel in a furnace. + Using a firework rocket while gliding with elytra will now give the player a boost. + Changed the color of dyes, wool, carpets, and banners. + Reordered all colored blocks and items in the Creative inventory. Banners now have the same order of colors as all other colored blocks and items. + Fishing rods can now hook on entities without causing knockback or pseudo-damage. + Fixed banner crafting + Fixed Map colors for certain blocks + Fixed Path block height + Fixed String block issues + Fixed Item frame culling. + Fixed Tutorial world NBT/Block State issues + Fixed World Slider + Fixed Enderman AI + Fixed Player animation bug + HUD Flash text changes + Generation accuracy changes + Many other small accuracy changes and fixes
277 lines
7.1 KiB
C++
277 lines
7.1 KiB
C++
#include "stdafx.h"
|
|
#include "net.minecraft.world.entity.h"
|
|
#include "net.minecraft.world.item.h"
|
|
#include "net.minecraft.world.level.h"
|
|
#include "net.minecraft.world.damagesource.h"
|
|
#include "net.minecraft.world.phys.h"
|
|
#include "FireworksRocketEntity.h"
|
|
|
|
FireworksRocketEntity::FireworksRocketEntity(Level *level) : Entity(level)
|
|
{
|
|
defineSynchedData();
|
|
|
|
life = 0;
|
|
lifetime = 0;
|
|
setSize(0.25f, 0.25f);
|
|
}
|
|
|
|
void FireworksRocketEntity::defineSynchedData()
|
|
{
|
|
entityData->defineNULL(DATA_ID_FIREWORKS_ITEM, nullptr);
|
|
entityData->define(DATA_ID_ATTACHED_TO_ENTITY, -1);
|
|
}
|
|
|
|
bool FireworksRocketEntity::isAttachedToEntity()
|
|
{
|
|
return entityData->getInteger(DATA_ID_ATTACHED_TO_ENTITY) >= 0;
|
|
}
|
|
|
|
bool FireworksRocketEntity::shouldRenderAtSqrDistance(double distance)
|
|
{
|
|
return distance < 64 * 64 && !isAttachedToEntity();
|
|
}
|
|
|
|
FireworksRocketEntity::FireworksRocketEntity(Level *level, shared_ptr<ItemInstance> sourceItem, shared_ptr<LivingEntity> attachTo, int boostLifetime) : Entity(level)
|
|
{
|
|
defineSynchedData();
|
|
|
|
life = 0;
|
|
setSize(0.25f, 0.25f);
|
|
setPos(attachTo->x, attachTo->y, attachTo->z);
|
|
heightOffset = 0;
|
|
|
|
if (sourceItem != nullptr && sourceItem->hasTag())
|
|
{
|
|
entityData->set(DATA_ID_FIREWORKS_ITEM, sourceItem->copy());
|
|
}
|
|
entityData->set(DATA_ID_ATTACHED_TO_ENTITY, attachTo->entityId);
|
|
attachedToEntity = attachTo;
|
|
|
|
xd = attachTo->xd;
|
|
yd = attachTo->yd;
|
|
zd = attachTo->zd;
|
|
lifetime = boostLifetime;
|
|
}
|
|
|
|
void FireworksRocketEntity::dealExplosionDamage()
|
|
{
|
|
shared_ptr<ItemInstance> sourceItem = entityData->getItemInstance(DATA_ID_FIREWORKS_ITEM);
|
|
if (sourceItem == nullptr || !sourceItem->hasTag())
|
|
return;
|
|
CompoundTag *fireTag = sourceItem->getTag()->getCompound(FireworksItem::TAG_FIREWORKS);
|
|
if (fireTag == nullptr)
|
|
return;
|
|
ListTag<CompoundTag> *explosions = (ListTag<CompoundTag> *) fireTag->getList(FireworksItem::TAG_EXPLOSIONS);
|
|
if (explosions == nullptr || explosions->size() == 0)
|
|
return;
|
|
|
|
float power = static_cast<float>(explosions->size()) * 2.0f + 5.0f;
|
|
shared_ptr<LivingEntity> attached = attachedToEntity.lock();
|
|
if (attached != nullptr)
|
|
attached->hurt(DamageSource::fireworks, power);
|
|
|
|
const double radius = 5.0;
|
|
vector<shared_ptr<Entity> > *nearby = level->getEntitiesOfClass(typeid(LivingEntity), bb->grow(radius, radius, radius));
|
|
if (nearby == nullptr)
|
|
return;
|
|
for (auto &it : *nearby)
|
|
{
|
|
shared_ptr<LivingEntity> living = dynamic_pointer_cast<LivingEntity>(it);
|
|
if (living == nullptr || living == attached || distanceToSqr(living) > radius * radius)
|
|
continue;
|
|
bool visible = false;
|
|
for (int i = 0; i < 2 && !visible; ++i)
|
|
{
|
|
HitResult *hit = level->clip(Vec3::newTemp(x, y, z), Vec3::newTemp(living->x, living->y + living->bbHeight * 0.5 * i, living->z), false, true);
|
|
if (hit == nullptr)
|
|
visible = true;
|
|
else
|
|
delete hit;
|
|
}
|
|
if (visible)
|
|
living->hurt(DamageSource::fireworks, power * static_cast<float>(sqrt((radius - distanceTo(living)) / radius)));
|
|
}
|
|
delete nearby;
|
|
}
|
|
|
|
FireworksRocketEntity::FireworksRocketEntity(Level *level, double x, double y, double z, shared_ptr<ItemInstance> sourceItem) : Entity(level)
|
|
{
|
|
defineSynchedData();
|
|
|
|
life = 0;
|
|
|
|
setSize(0.25f, 0.25f);
|
|
|
|
setPos(x, y, z);
|
|
heightOffset = 0;
|
|
|
|
int flightCount = 1;
|
|
if (sourceItem != nullptr && sourceItem->hasTag())
|
|
{
|
|
entityData->set(DATA_ID_FIREWORKS_ITEM, sourceItem);
|
|
|
|
CompoundTag *tag = sourceItem->getTag();
|
|
CompoundTag *compound = tag->getCompound(FireworksItem::TAG_FIREWORKS);
|
|
if (compound != nullptr)
|
|
{
|
|
flightCount += compound->getByte(FireworksItem::TAG_FLIGHT);
|
|
}
|
|
}
|
|
xd = random->nextGaussian() * .001;
|
|
zd = random->nextGaussian() * .001;
|
|
yd = 0.05;
|
|
|
|
lifetime = (SharedConstants::TICKS_PER_SECOND / 2) * flightCount + random->nextInt(6) + random->nextInt(7);
|
|
}
|
|
|
|
void FireworksRocketEntity::lerpMotion(double xd, double yd, double zd)
|
|
{
|
|
xd = xd;
|
|
yd = yd;
|
|
zd = zd;
|
|
if (xRotO == 0 && yRotO == 0)
|
|
{
|
|
double sd = Mth::sqrt(xd * xd + zd * zd);
|
|
yRotO = yRot = static_cast<float>(atan2(xd, zd) * 180 / PI);
|
|
xRotO = xRot = static_cast<float>(atan2(yd, sd) * 180 / PI);
|
|
}
|
|
}
|
|
|
|
void FireworksRocketEntity::tick()
|
|
{
|
|
xOld = x;
|
|
yOld = y;
|
|
zOld = z;
|
|
Entity::tick();
|
|
|
|
bool attachedMode = isAttachedToEntity();
|
|
if (attachedMode)
|
|
{
|
|
shared_ptr<LivingEntity> attached = attachedToEntity.lock();
|
|
if (attached == nullptr)
|
|
{
|
|
attached = dynamic_pointer_cast<LivingEntity>(level->getEntity(entityData->getInteger(DATA_ID_ATTACHED_TO_ENTITY)));
|
|
if (attached != nullptr)
|
|
attachedToEntity = attached;
|
|
}
|
|
if (attached != nullptr)
|
|
{
|
|
setPos(attached->x, attached->y, attached->z);
|
|
xd = attached->xd;
|
|
yd = attached->yd;
|
|
zd = attached->zd;
|
|
}
|
|
xRot = 90.0f;
|
|
yRot = 0.0f;
|
|
}
|
|
else
|
|
{
|
|
xd *= 1.15;
|
|
zd *= 1.15;
|
|
yd += .04;
|
|
move(xd, yd, zd);
|
|
|
|
double sd = Mth::sqrt(xd * xd + zd * zd);
|
|
yRot = static_cast<float>(atan2(xd, zd) * 180 / PI);
|
|
xRot = static_cast<float>(atan2(yd, 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 )
|
|
{
|
|
if (life == 0)
|
|
{
|
|
level->playEntitySound(shared_from_this(), eSoundType_FIREWORKS_LAUNCH, 3, 1);
|
|
}
|
|
}
|
|
|
|
life++;
|
|
if (level->isClientSide && (!attachedMode || (life % 2) == 0))
|
|
{
|
|
level->addParticle(eParticleType_fireworksspark, x, y - .3, z, random->nextGaussian() * .05, -yd * .5, random->nextGaussian() * .05);
|
|
}
|
|
if (!level->isClientSide && life > lifetime)
|
|
{
|
|
if (attachedMode)
|
|
dealExplosionDamage();
|
|
level->broadcastEntityEvent(shared_from_this(), EntityEvent::FIREWORKS_EXPLODE);
|
|
remove();
|
|
}
|
|
}
|
|
|
|
void FireworksRocketEntity::handleEntityEvent(byte eventId)
|
|
{
|
|
if (eventId == EntityEvent::FIREWORKS_EXPLODE && level->isClientSide)
|
|
{
|
|
shared_ptr<ItemInstance> sourceItem = entityData->getItemInstance(DATA_ID_FIREWORKS_ITEM);
|
|
CompoundTag *tag = nullptr;
|
|
if (sourceItem != nullptr && sourceItem->hasTag())
|
|
{
|
|
tag = sourceItem->getTag()->getCompound(FireworksItem::TAG_FIREWORKS);
|
|
}
|
|
level->createFireworks(x, y, z, xd, yd, zd, tag);
|
|
}
|
|
Entity::handleEntityEvent(eventId);
|
|
}
|
|
|
|
void FireworksRocketEntity::addAdditonalSaveData(CompoundTag *tag)
|
|
{
|
|
tag->putInt(L"Life", life);
|
|
tag->putInt(L"LifeTime", lifetime);
|
|
shared_ptr<ItemInstance> itemInstance = entityData->getItemInstance(DATA_ID_FIREWORKS_ITEM);
|
|
if (itemInstance != nullptr)
|
|
{
|
|
CompoundTag *itemTag = new CompoundTag();
|
|
itemInstance->save(itemTag);
|
|
tag->putCompound(L"FireworksItem", itemTag);
|
|
}
|
|
|
|
}
|
|
|
|
void FireworksRocketEntity::readAdditionalSaveData(CompoundTag *tag)
|
|
{
|
|
life = tag->getInt(L"Life");
|
|
lifetime = tag->getInt(L"LifeTime");
|
|
|
|
CompoundTag *itemTag = tag->getCompound(L"FireworksItem");
|
|
if (itemTag != nullptr)
|
|
{
|
|
shared_ptr<ItemInstance> fromTag = ItemInstance::fromTag(itemTag);
|
|
if (fromTag != nullptr)
|
|
{
|
|
entityData->set(DATA_ID_FIREWORKS_ITEM, fromTag);
|
|
}
|
|
}
|
|
}
|
|
|
|
float FireworksRocketEntity::getShadowHeightOffs()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
float FireworksRocketEntity::getBrightness(float a)
|
|
{
|
|
return Entity::getBrightness(a);
|
|
}
|
|
|
|
int FireworksRocketEntity::getLightColor(float a)
|
|
{
|
|
return Entity::getLightColor(a);
|
|
}
|
|
|
|
bool FireworksRocketEntity::isAttackable()
|
|
{
|
|
return false;
|
|
} |