34 lines
1.2 KiB
C++
34 lines
1.2 KiB
C++
#include "stdafx.h"
|
|
#include "net.minecraft.world.level.h"
|
|
#include "net.minecraft.world.phys.h"
|
|
#include "net.minecraft.world.entity.h"
|
|
#include "SlimeTile.h"
|
|
|
|
SlimeTile::SlimeTile(int id) : Tile(id, Material::sand)
|
|
{
|
|
}
|
|
|
|
void SlimeTile::fallOn(Level *level, int x, int y, int z, shared_ptr<Entity> entity, float fallDistance)
|
|
{
|
|
// If the entity is a living entity and sneaking (crouching) then do normal fall behavior
|
|
shared_ptr<LivingEntity> le = dynamic_pointer_cast<LivingEntity>(entity);
|
|
if (le != nullptr && le->isSneaking())
|
|
{
|
|
Tile::fallOn(level, x, y, z, entity, fallDistance);
|
|
return;
|
|
}
|
|
|
|
// Only apply bounce when there was fall distance (called when landing)
|
|
if (fallDistance > 0.0f)
|
|
{
|
|
// Use the entity's vertical velocity to compute bounce. Use a reasonable multiplier.
|
|
float bounce = (float)(-entity->yd * 0.8f);
|
|
if (fabs(bounce) < 0.1f) bounce = 0.0f;
|
|
|
|
// Apply bounce by setting vertical velocity and reset fall distance.
|
|
// Do not call move() here — let normal physics apply the velocity next tick.
|
|
entity->yd = bounce;
|
|
entity->fallDistance = 0.0f;
|
|
}
|
|
}
|