Files
neoLegacy/Minecraft.World/Boat.cpp
T

884 lines
22 KiB
C++

#include "stdafx.h"
#include "com.mojang.nbt.h"
#include "net.minecraft.world.entity.h"
#include "net.minecraft.world.entity.player.h"
#include "net.minecraft.world.entity.monster.h"
#include "net.minecraft.world.item.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.material.h"
#include "net.minecraft.world.level.tile.h"
#include "net.minecraft.world.phys.h"
#include "net.minecraft.world.damagesource.h"
#include "SoundTypes.h"
#include "Boat.h"
// 4J - added for common ctor code
void Boat::_init()
{
paddlePositions[0] = paddlePositions[1] = 0.0f;
doLerp = true;
lSteps = 0;
lx = ly = lz = lyr = lxr = 0.0;
lxd = lyd = lzd = 0.0;
secondRider = weak_ptr<Entity>();
status = IN_WATER;
invFriction = 0.0f;
outOfControlTicks = 0;
deltaRotation = 0.0f;
waterLevel = 0.0;
lastYd = 0.0;
rockPhase = 0.0;
inputLeft = inputRight = inputUp = inputDown = false;
blocksBuilding = true;
setSize(1.375f, 0.6625f);
heightOffset = (bbHeight / 2.0f) + 0.2f;
// 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();
}
Boat::Boat(Level *level) : Entity( level )
{
_init();
}
bool Boat::makeStepSound()
{
return false;
}
void Boat::defineSynchedData()
{
entityData->define(DATA_ID_HURT, 0);
entityData->define(DATA_ID_HURTDIR, 1);
entityData->define(DATA_ID_DAMAGE, 0.0f);
entityData->define(DATA_ID_TYPE, OAK);
entityData->define(DATA_ID_PADDLE_LEFT, static_cast<byte>(0));
entityData->define(DATA_ID_PADDLE_RIGHT, static_cast<byte>(0));
}
AABB *Boat::getCollideAgainstBox(shared_ptr<Entity> entity)
{
if (entity == nullptr || !entity->isPushable() || hasRider(entity) || entity->riding.get() == this) return nullptr;
return entity->bb;
}
AABB *Boat::getCollideBox()
{
return bb;
}
bool Boat::isPushable()
{
return true;
}
Boat::Boat(Level *level, double x, double y, double z) : Entity( level )
{
_init();
setPos(x, y + heightOffset, z);
xd = 0;
yd = 0;
zd = 0;
xo = x;
yo = y;
zo = z;
}
double Boat::getRideHeight()
{
return heightOffset - 0.4f;
}
bool Boat::hurt(DamageSource *source, float hurtDamage)
{
if (isInvulnerable()) return false;
if (source != nullptr && dynamic_cast<IndirectEntityDamageSource *>(source) != nullptr && hasRider(source->getEntity())) return false;
if (level->isClientSide || removed) return true;
// 4J-JEV: Fix for #88212,
// Untrusted players shouldn't be able to damage minecarts or boats.
if (dynamic_cast<EntityDamageSource *>(source) != nullptr)
{
shared_ptr<Entity> attacker = source->getDirectEntity();
if ( attacker->instanceof(eTYPE_PLAYER) && !dynamic_pointer_cast<Player>(attacker)->isAllowedToHurtEntity( shared_from_this() ))
{
return false;
}
}
setHurtDir(-getHurtDir());
setHurtTime(10);
// 4J Stu - If someone is riding in this, then it can tick multiple times which causes the damage to
// decrease too quickly. So just make the damage a bit higher to start with for similar behaviour
// to an unridden one. Only do this change if the riding player is attacking it.
if (hasRider(source->getEntity())) hurtDamage += 1;
setDamage(getDamage() + hurtDamage * 10);
markHurt();
// 4J Stu - Brought froward from 12w36 to fix #46611 - TU5: Gameplay: Minecarts and boat requires more hits than one to be destroyed in creative mode
// 4J-PB - Fix for XB1 #175735 - [CRASH] [Multi-Plat]: Code: Gameplay: Placing a boat on harmful surfaces causes the game to crash
bool creativePlayer = (source->getEntity() != nullptr) && source->getEntity()->instanceof(eTYPE_PLAYER) && dynamic_pointer_cast<Player>(source->getEntity())->abilities.instabuild;
if (creativePlayer || getDamage() > 20 * 2)
{
ejectPassengers();
if (!creativePlayer) spawnAtLocation(getDropItemId(), 1, 0);
remove();
}
return true;
}
void Boat::animateHurt()
{
setHurtDir(-getHurtDir());
setHurtTime(10);
setDamage(getDamage() * 11);
}
bool Boat::isPickable()
{
return !removed;
}
bool Boat::isLocallyDriven()
{
shared_ptr<Entity> driver = rider.lock();
return level->isClientSide && driver != nullptr && driver->instanceof(eTYPE_LOCALPLAYER);
}
void Boat::lerpTo(double x, double y, double z, float yRot, float xRot, int steps)
{
if (isLocallyDriven()) return;
lSteps = steps + 5;
lx = x;
ly = y;
lz = z;
lyr = yRot;
lxr = xRot;
xd = lxd;
yd = lyd;
zd = lzd;
}
void Boat::lerpMotion(double xd, double yd, double zd)
{
if (isLocallyDriven()) return;
lxd = this->xd = xd;
lyd = this->yd = yd;
lzd = this->zd = zd;
}
float Boat::getWaterFill(Level *level, int x, int y, int z)
{
if (level->getMaterial(x, y, z) != Material::water) return 0.0f;
if (level->getMaterial(x, y + 1, z) == Material::water) return 1.0f;
return 1.0f - LiquidTile::getHeight(level->getData(x, y, z));
}
Boat::EStatus Boat::isUnderwater()
{
double surfaceY = bb->y1 + 0.001;
int minX = Mth::floor(bb->x0);
int maxX = Mth::ceil(static_cast<float>(bb->x1));
int minY = Mth::floor(bb->y1);
int maxY = Mth::ceil(static_cast<float>(surfaceY));
int minZ = Mth::floor(bb->z0);
int maxZ = Mth::ceil(static_cast<float>(bb->z1));
bool underWater = false;
for (int xx = minX; xx < maxX; ++xx)
{
for (int yy = minY; yy < maxY; ++yy)
{
for (int zz = minZ; zz < maxZ; ++zz)
{
if (level->getMaterial(xx, yy, zz) != Material::water) continue;
int data = level->getData(xx, yy, zz);
if (surfaceY < yy + 1 - LiquidTile::getHeight(data))
{
if (data != 0) return UNDER_FLOWING_WATER;
underWater = true;
}
}
}
}
return underWater ? UNDER_WATER : IN_AIR;
}
bool Boat::checkInWater()
{
int minX = Mth::floor(bb->x0);
int maxX = Mth::ceil(static_cast<float>(bb->x1));
int minY = Mth::floor(bb->y0);
int maxY = Mth::ceil(static_cast<float>(bb->y0 + 0.001));
int minZ = Mth::floor(bb->z0);
int maxZ = Mth::ceil(static_cast<float>(bb->z1));
bool inWater = false;
waterLevel = -DBL_MAX;
for (int xx = minX; xx < maxX; ++xx)
{
for (int yy = minY; yy < maxY; ++yy)
{
for (int zz = minZ; zz < maxZ; ++zz)
{
if (level->getMaterial(xx, yy, zz) != Material::water) continue;
double height = yy + 1 - LiquidTile::getHeight(level->getData(xx, yy, zz));
waterLevel = max(height, waterLevel);
inWater |= bb->y0 < height;
}
}
}
return inWater;
}
float Boat::getGroundFriction()
{
AABB *box = AABB::newTemp(bb->x0, bb->y0 - 0.001, bb->z0, bb->x1, bb->y0, bb->z1);
int minX = Mth::floor(box->x0) - 1;
int maxX = Mth::ceil(static_cast<float>(box->x1)) + 1;
int minY = Mth::floor(box->y0) - 1;
int maxY = Mth::ceil(static_cast<float>(box->y1)) + 1;
int minZ = Mth::floor(box->z0) - 1;
int maxZ = Mth::ceil(static_cast<float>(box->z1)) + 1;
AABBList collisions;
float friction = 0.0f;
int count = 0;
for (int xx = minX; xx < maxX; ++xx)
{
for (int zz = minZ; zz < maxZ; ++zz)
{
int edges = (xx != minX && xx != maxX - 1 ? 0 : 1) + (zz != minZ && zz != maxZ - 1 ? 0 : 1);
if (edges == 2) continue;
for (int yy = minY; yy < maxY; ++yy)
{
if (edges > 0 && (yy == minY || yy == maxY - 1)) continue;
int t = level->getTile(xx, yy, zz);
if (t <= 0 || Tile::tiles[t] == nullptr) continue;
Tile::tiles[t]->addAABBs(level, xx, yy, zz, box, &collisions, shared_from_this());
if (!collisions.empty())
{
friction += Tile::tiles[t]->friction;
++count;
}
collisions.clear();
}
}
}
return count == 0 ? 0.0f : friction / count;
}
Boat::EStatus Boat::getStatus()
{
EStatus underwaterStatus = isUnderwater();
if (underwaterStatus != IN_AIR)
{
waterLevel = bb->y1;
return underwaterStatus;
}
if (checkInWater()) return IN_WATER;
if (getGroundFriction() > 0.0f) return ON_LAND;
return IN_AIR;
}
float Boat::getWaterLevelAbove()
{
int minY = Mth::floor(bb->y1);
int maxY = Mth::ceil(static_cast<float>(bb->y1 - lastYd));
int minX = Mth::floor(bb->x0);
int maxX = Mth::ceil(static_cast<float>(bb->x1));
int minZ = Mth::floor(bb->z0);
int maxZ = Mth::ceil(static_cast<float>(bb->z1));
for (int yy = minY; yy < maxY; ++yy)
{
float height = 0.0f;
bool open = true;
for (int xx = minX; xx < maxX && open; ++xx)
{
for (int zz = minZ; zz < maxZ; ++zz)
{
height = max(height, getWaterFill(level, xx, yy, zz));
if (height >= 1.0f)
{
open = false;
break;
}
}
}
if (open && height < 1.0f) return yy + height;
}
return maxY + 1.0f;
}
void Boat::floatBoat()
{
double momentum = sqrt(xd * xd + zd * zd) * 30.0 + 1.0;
if (level->random->nextInt(30) == 0) momentum *= 10.0;
rockPhase += 0.05 * momentum;
double buoyancy = 0.0;
double rock = 0.0;
const double buoyancyOffset = 0.1;
bool floating = false;
int px = Mth::floor(x);
int py = Mth::floor(bb->y0);
int pz = Mth::floor(z);
Material *material = level->getMaterial(px, py, pz);
Material *materialAbove = level->getMaterial(px, py + 1, pz);
if (material == Material::water && materialAbove == Material::air)
{
buoyancy = (1.0 - (bb->y0 - py)) * 0.9 + buoyancyOffset;
rock = (sin(rockPhase) + 1.0) * 0.035;
outOfControlTicks = 0;
invFriction = 0.9f;
floating = true;
}
else if (material == Material::water && materialAbove == Material::water)
{
buoyancy = 1.0;
invFriction = 0.9f;
++outOfControlTicks;
}
else if (material == Material::air || material == Material::topSnow)
{
invFriction = 1.0f;
if (onGround)
{
int below = level->getTile(px, py - 1, pz);
if (below > 0 && Tile::tiles[below] != nullptr) invFriction = Tile::tiles[below]->friction;
}
else if (level->getMaterial(px, py - 1, pz) == Material::water)
{
invFriction = 0.9f;
}
}
xd *= invFriction;
zd *= invFriction;
deltaRotation *= invFriction;
if (floating)
{
double bottom = getWaterLevelAbove() - bbHeight + 0.2 + sin(rockPhase) * 0.035;
move(0, bottom - bb->y0, 0);
yd = 0.0;
return;
}
yd = (yd - 0.04) * 0.98;
if (buoyancy > 0.0)
{
yd = min(yd * 0.7 + 0.05, (buoyancy - rock - buoyancyOffset) * 0.15);
}
}
void Boat::controlBoat()
{
if (rider.lock() == nullptr) return;
float acceleration = 0.0f;
if (inputLeft) deltaRotation += -1.0f;
if (inputRight) deltaRotation += 1.0f;
if (inputRight != inputLeft && !inputUp && !inputDown) acceleration += 0.005f;
yRot += deltaRotation;
if (inputUp) acceleration += 0.04f;
if (inputDown) acceleration -= 0.005f;
xd += Mth::sin(-yRot * PI / 180) * acceleration;
zd += Mth::cos(yRot * PI / 180) * acceleration;
if (!level->isClientSide) setPaddleState((inputRight && !inputLeft) || inputUp, (inputLeft && !inputRight) || inputUp);
}
void Boat::setPaddleState(bool left, bool right)
{
entityData->set(DATA_ID_PADDLE_LEFT, static_cast<byte>(left ? 1 : 0));
entityData->set(DATA_ID_PADDLE_RIGHT, static_cast<byte>(right ? 1 : 0));
}
bool Boat::getPaddleState(int side)
{
return entityData->getByte(side == 0 ? DATA_ID_PADDLE_LEFT : DATA_ID_PADDLE_RIGHT) != 0 && rider.lock() != nullptr;
}
void Boat::tick()
{
status = getStatus();
if (status == UNDER_WATER || status == UNDER_FLOWING_WATER) ++outOfControlTicks;
else outOfControlTicks = 0;
if (!level->isClientSide && outOfControlTicks >= 60) ejectPassengers();
if (getHurtTime() > 0) setHurtTime(getHurtTime() - 1);
if (getDamage() > 0) setDamage(getDamage() - 1);
xo = x;
yo = y;
zo = z;
Entity::tick();
const float paddleStroke = PI / 8.0f;
const float paddleSplash = PI / 4.0f;
const float paddleCycle = PI * 2.0f;
for (int side = 0; side < 2; ++side)
{
if (getPaddleState(side))
{
if (!level->isClientSide && fmod(paddlePositions[side], paddleCycle) <= paddleSplash && fmod(paddlePositions[side] + paddleStroke, paddleCycle) >= paddleSplash)
{
int sound = -1;
if (status == ON_LAND) sound = eSoundType_ENTITY_BOAT_PADDLE_LAND;
else if (status != IN_AIR) sound = eSoundType_ENTITY_BOAT_PADDLE_WATER;
if (sound >= 0)
{
double viewX = -Mth::sin(yRot * PI / 180);
double viewZ = Mth::cos(yRot * PI / 180);
double xOffset = side == 1 ? -viewZ : viewZ;
double zOffset = side == 1 ? viewX : -viewX;
level->playSound(x + xOffset, y, z + zOffset, sound, 1.0f, 0.8f + 0.4f * random->nextFloat());
}
}
paddlePositions[side] += paddleStroke;
}
else
{
paddlePositions[side] = 0.0f;
}
}
bool predicting = isLocallyDriven();
if (level->isClientSide && !predicting)
{
if (lSteps > 0)
{
double xt = x + (lx - x) / lSteps;
double yt = y + (ly - y) / lSteps;
double zt = z + (lz - z) / lSteps;
double yrd = Mth::wrapDegrees(lyr - yRot);
yRot += static_cast<float>(yrd / lSteps);
xRot += static_cast<float>((lxr - xRot) / lSteps);
lSteps--;
setPos(xt, yt, zt);
setRot(yRot, xRot);
}
return;
}
shared_ptr<Entity> driver = rider.lock();
shared_ptr<Player> player = driver != nullptr ? dynamic_pointer_cast<Player>(driver) : nullptr;
if (player != nullptr)
{
inputLeft = player->xxa > 0.1f;
inputRight = player->xxa < -0.1f;
inputUp = player->yya > 0.1f;
inputDown = player->yya < -0.1f;
}
else
{
inputLeft = inputRight = inputUp = inputDown = false;
if (!level->isClientSide) setPaddleState(false, false);
}
if (player != nullptr && !level->isClientSide)
{
setPaddleState((inputRight && !inputLeft) || inputUp, (inputLeft && !inputRight) || inputUp);
xd = yd = zd = 0;
}
else
{
floatBoat();
controlBoat();
move(xd, yd, zd);
setRot(yRot, 0);
}
if (level->isClientSide) return;
for (int i = 0; i < 4; i++)
{
int xx = Mth::floor(x + ((i % 2) - 0.5) * 0.8);
int zz = Mth::floor(z + ((i / 2) - 0.5) * 0.8);
for (int j = 0; j < 2; j++)
{
int yy = Mth::floor(bb->y0) + j;
if (level->getTile(xx, yy, zz) == Tile::waterlily_Id) level->destroyTile(xx, yy, zz, true);
}
}
vector<shared_ptr<Entity> > *entities = level->getEntities(shared_from_this(), bb->grow(0.2f, -0.01f, 0.2f));
if (entities != nullptr)
{
for (auto &e : *entities)
{
if (e == nullptr || hasRider(e) || e->riding != nullptr && e->riding.get() == this) continue;
if (!e->isPushable()) continue;
if (canAddPassenger() && e->riding == nullptr && e->rider.lock() == nullptr && e->instanceof(eTYPE_LIVINGENTITY)
&& !e->instanceof(eTYPE_WATERANIMAL) && !e->instanceof(eTYPE_PLAYER))
{
e->ride(shared_from_this());
}
else
{
push(e);
}
}
}
}
void Boat::push(shared_ptr<Entity> e)
{
if (e->instanceof(eTYPE_BOAT))
{
if (e->bb->y0 < bb->y1) Entity::push(e);
}
else if (e->bb->y0 <= bb->y0)
{
Entity::push(e);
}
}
void Boat::checkFallDamage(double ya, bool onGround)
{
lastYd = yd;
if (riding != nullptr) return;
if (onGround)
{
if (fallDistance > 3.0f && status == ON_LAND)
{
causeFallDamage(fallDistance);
if (!level->isClientSide && !removed)
{
ejectPassengers();
remove();
for (int i = 0; i < 3; i++) spawnAtLocation(Tile::planks_Id, 1, getType());
for (int i = 0; i < 2; i++) spawnAtLocation(Item::stick->id, 1, 0);
}
}
fallDistance = 0.0f;
}
else if (level->getMaterial(Mth::floor(x), Mth::floor(bb->y0) - 1, Mth::floor(z)) != Material::water && ya < 0.0)
{
fallDistance -= static_cast<float>(ya);
}
}
void Boat::createSplash(double particleStrengh)
{
double xa = cos(yRot * PI / 180);
double za = sin(yRot * PI / 180);
for (int i = 0; i < 1 + particleStrengh * 60; i++)
{
double side = (random->nextFloat() * 2 - 1);
double side2 = (random->nextInt(2) * 2 - 1) * 0.7;
if (random->nextBoolean())
{
double xx = x - xa * side * 0.8 + za * side2;
double zz = z - za * side * 0.8 - xa * side2;
level->addParticle(eParticleType_splash, xx, y - 2 / 16.0f, zz, +xd, yd, +zd);
}
else
{
double xx = x + xa + za * side * 0.7;
double zz = z + za - xa * side * 0.7;
level->addParticle(eParticleType_splash, xx, y - 2 / 16.0f, zz, +xd, yd, +zd);
}
}
}
bool Boat::hasRider(shared_ptr<Entity> e)
{
return e != nullptr && (rider.lock() == e || secondRider.lock() == e);
}
void Boat::addRider(shared_ptr<Entity> e)
{
if (hasRider(e)) return;
shared_ptr<Entity> driver = rider.lock();
if (driver != nullptr && e->instanceof(eTYPE_PLAYER) && !driver->instanceof(eTYPE_PLAYER) && secondRider.lock() == nullptr)
{
secondRider = driver;
rider = e;
return;
}
if (rider.lock() == nullptr) rider = e;
else secondRider = e;
shared_ptr<Entity> front = rider.lock();
shared_ptr<Entity> back = secondRider.lock();
if (front != nullptr && back != nullptr && !front->instanceof(eTYPE_PLAYER) && !back->instanceof(eTYPE_PLAYER) && back->entityId < front->entityId)
{
rider = back;
secondRider = front;
}
}
void Boat::removeRider(shared_ptr<Entity> e)
{
if (e == nullptr || rider.lock() == e || rider.lock() == nullptr)
{
rider = secondRider;
secondRider = weak_ptr<Entity>();
}
else if (secondRider.lock() == e)
{
secondRider = weak_ptr<Entity>();
}
}
shared_ptr<Entity> Boat::getExtraRider()
{
return secondRider.lock();
}
int Boat::getPassengerCount()
{
return (rider.lock() != nullptr ? 1 : 0) + (secondRider.lock() != nullptr ? 1 : 0);
}
bool Boat::canAddPassenger()
{
return getPassengerCount() < 2;
}
void Boat::ejectPassengers()
{
shared_ptr<Entity> second = secondRider.lock();
if (second != nullptr && second->riding.get() == this) second->ride(nullptr);
shared_ptr<Entity> first = rider.lock();
if (first != nullptr && first->riding.get() == this) first->ride(nullptr);
rider = weak_ptr<Entity>();
secondRider = weak_ptr<Entity>();
}
void Boat::clampRotation(shared_ptr<Entity> passenger)
{
shared_ptr<LivingEntity> living = dynamic_pointer_cast<LivingEntity>(passenger);
if (living != nullptr) living->yBodyRot = yRot;
float relativeYRot = Mth::wrapDegrees(passenger->yRot - yRot);
float clampedYRot = Mth::clamp(relativeYRot, -105.0f, 105.0f);
passenger->yRotO += clampedYRot - relativeYRot;
passenger->yRot += clampedYRot - relativeYRot;
if (living != nullptr) living->setYHeadRot(passenger->yRot);
}
void Boat::positionRider()
{
positionRider(rider.lock());
}
void Boat::positionRider(shared_ptr<Entity> passenger)
{
if (passenger == nullptr || !hasRider(passenger)) return;
float offset = 0.0f;
bool twoAboard = getPassengerCount() > 1;
if (twoAboard)
{
offset = (rider.lock() == passenger) ? 0.2f : -0.6f;
if (passenger->instanceof(eTYPE_ANIMAL)) offset += 0.2f;
}
double seatX = -Mth::sin(yRot * PI / 180) * offset;
double seatZ = Mth::cos(yRot * PI / 180) * offset;
double feet = bb->y0 - 0.3 + (getSeatOffset(passenger) + 0.35);
passenger->setPos(x + seatX, feet + passenger->heightOffset - passenger->ySlideOffset, z + seatZ);
bool isPlayer = passenger->instanceof(eTYPE_PLAYER);
if (level->isClientSide == isPlayer)
{
float turn = Mth::wrapDegrees(yRot - yRotO);
passenger->yRot += turn;
shared_ptr<LivingEntity> living = dynamic_pointer_cast<LivingEntity>(passenger);
if (living != nullptr) living->setYHeadRot(living->yHeadRot + turn);
clampRotation(passenger);
if (twoAboard && living != nullptr && passenger->instanceof(eTYPE_ANIMAL))
{
int facing = (passenger->entityId & 1) == 0 ? 90 : 270;
living->yBodyRot += facing;
living->setYHeadRot(living->yHeadRot + facing);
}
}
}
void Boat::addAdditonalSaveData(CompoundTag *base)
{
static const wchar_t *TYPE_NAMES[TYPE_COUNT] = { L"oak", L"spruce", L"birch", L"jungle", L"acacia", L"dark_oak" };
base->putString(L"Type", TYPE_NAMES[getType()]);
}
void Boat::readAdditionalSaveData(CompoundTag *base)
{
static const wchar_t *TYPE_NAMES[TYPE_COUNT] = { L"oak", L"spruce", L"birch", L"jungle", L"acacia", L"dark_oak" };
if (base->contains(L"Type"))
{
wstring name = base->getString(L"Type");
for (int i = 0; i < TYPE_COUNT; i++)
{
if (name == TYPE_NAMES[i]) setType(i);
}
}
}
float Boat::getShadowHeightOffs()
{
return 0;
}
wstring Boat::getName()
{
return L"Boat";
}
bool Boat::interact(shared_ptr<Player> player)
{
if (!level->isClientSide)
{
if (hasRider(player))
{
// 4J HEG - Fixed issue with player not being able to dismount boat (issue #4446)
player->xd = 0;
player->yd = 0;
player->zd = 0;
player->ride(nullptr);
}
else if (!player->isSneaking() && canAddPassenger() && outOfControlTicks < 60)
{
player->ride(shared_from_this());
}
}
return true;
}
void Boat::setDamage(float damage)
{
entityData->set(DATA_ID_DAMAGE, damage);
}
float Boat::getDamage()
{
return entityData->getFloat(DATA_ID_DAMAGE);
}
void Boat::setHurtTime(int hurtTime)
{
entityData->set(DATA_ID_HURT, hurtTime);
}
int Boat::getHurtTime()
{
return entityData->getInteger(DATA_ID_HURT);
}
void Boat::setHurtDir(int hurtDir)
{
entityData->set(DATA_ID_HURTDIR, hurtDir);
}
int Boat::getHurtDir()
{
return entityData->getInteger(DATA_ID_HURTDIR);
}
bool Boat::getDoLerp()
{
return doLerp;
}
void Boat::setDoLerp(bool doLerp)
{
this->doLerp = doLerp;
}
void Boat::setType(int type)
{
if (type < 0 || type >= TYPE_COUNT) type = OAK;
entityData->set(DATA_ID_TYPE, type);
}
int Boat::getType()
{
int type = entityData->getInteger(DATA_ID_TYPE);
return (type < 0 || type >= TYPE_COUNT) ? OAK : type;
}
int Boat::getItemIdForType(int type)
{
switch (type)
{
case SPRUCE: return Item::spruce_boat_Id;
case BIRCH: return Item::birch_boat_Id;
case JUNGLE: return Item::jungle_boat_Id;
case ACACIA: return Item::acacia_boat_Id;
case DARK_OAK: return Item::dark_oak_boat_Id;
default: return Item::boat_Id;
}
}
int Boat::getDropItemId()
{
return getItemIdForType(getType());
}
float Boat::getRowingTime(int side, float a)
{
if (!getPaddleState(side)) return 0.0f;
float from = paddlePositions[side] - PI / 8.0f;
return from + (paddlePositions[side] - from) * Mth::clamp(a, 0.0f, 1.0f);
}
double Boat::getSeatOffset(shared_ptr<Entity> passenger)
{
if (passenger->instanceof(eTYPE_PLAYER)) return -0.35;
if (passenger->instanceof(eTYPE_ZOMBIE))
{
shared_ptr<Zombie> zombie = dynamic_pointer_cast<Zombie>(passenger);
return (zombie != nullptr && zombie->isBaby()) ? 0.0 : -0.45;
}
if (passenger->instanceof(eTYPE_SKELETON)) return -0.3;
if (passenger->instanceof(eTYPE_ANIMAL)) return 0.14;
if (passenger->instanceof(eTYPE_SILVERFISH) || passenger->instanceof(eTYPE_ENDERMITE)) return 0.1;
if (passenger->instanceof(eTYPE_SHULKER)) return 0.3;
if (passenger->instanceof(eTYPE_ARMORSTAND)) return 0.1;
return 0.0;
}
int Boat::getLightColor(float a)
{
int xTile = Mth::floor(x);
int zTile = Mth::floor(z);
if (!level->hasChunkAt(xTile, 0, zTile)) return 0;
return level->getLightColor(xTile, Mth::floor(bb->y0 + bbHeight * 0.85), zTile, 0);
}