cuberite / cuberite

A lightweight, fast and extensible game server for Minecraft

Home Page:https://cuberite.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Taking damage on TP

seem0nster opened this issue · comments

Client version: 1.8.9
Server OS: Linux

Expected behavior

To do "/home" from 0,75,0 - -200,25,150 Without taking damage while teleporting.

Actual behavior

Taking damage if the coordinates you are teleporting to are below the Y coord you are at

Maybe the solution

Setting the velocity to 0 while teleporting.

English might be Horrible

Confirmed: I tried with a simple /tp and the same happen.
I also noticed that when you /tp ~ ~50 ~ you don't get fall damages.
That is strange I think this is supposed to be handled by https://github.com/cuberite/cuberite/blob/master/src/Entities/Player.cpp#L2530-L2559 which is called by Player:TeleportToCords()

hmm, i think it is because it handles fall damage like if you go from Y- 80 to Y- 20, it takes where you fell to, not how long you have spent in the air.

English may be horrible.

Fall damage is currently not handled well. We currently don't look at the y-speed of the player to calculate the damage amount but by looking at the current y-level compared to the previous on-ground y-level:

const auto FallHeight = m_LastGroundHeight - GetPosY();
auto Damage = static_cast<int>(FallHeight - 3.0);
const auto Below = POS_TOINT.addedY(-1);
const auto BlockBelow = (cChunkDef::IsValidHeight(Below)) ? GetWorld()->GetBlock(Below) : static_cast<BLOCKTYPE>(E_BLOCK_AIR);
if ((Damage > 0) && !FallDamageAbsorbed)
{
if (IsElytraFlying())
{
Damage = static_cast<int>(static_cast<float>(Damage) * 0.33);
}
if (BlockBelow == E_BLOCK_HAY_BALE)
{
Damage = std::clamp(static_cast<int>(static_cast<float>(Damage) * 0.2), 1, 20);
}
// Fall particles
// TODO: falling on a partial (e.g. slab) block shouldn't broadcast particles of the block below
GetWorld()->BroadcastParticleEffect(
"blockdust",
GetPosition(),
{ 0, 0, 0 },
(Damage - 1.f) * ((0.3f - 0.1f) / (15.f - 1.f)) + 0.1f, // Map damage (1 - 15) to particle speed (0.1 - 0.3)
static_cast<int>((Damage - 1.f) * ((50.f - 20.f) / (15.f - 1.f)) + 20.f), // Map damage (1 - 15) to particle quantity (20 - 50)
{ { BlockBelow, 0 } }
);
TakeDamage(dtFalling, nullptr, Damage, static_cast<float>(Damage), 0);