Skip to content

Commit

Permalink
Player collisionbox: Make settable
Browse files Browse the repository at this point in the history
Breaks compatibility with old clients.
  • Loading branch information
TeTpaAka authored and paramat committed Jul 21, 2017
1 parent 5045bdc commit 49920cf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/content_cao.cpp
Expand Up @@ -972,7 +972,7 @@ void GenericCAO::step(float dtime, ClientEnvironment *env)
if (m_is_visible) {
int old_anim = player->last_animation;
float old_anim_speed = player->last_animation_speed;
m_position = player->getPosition() + v3f(0,BS,0);
m_position = player->getPosition();
m_velocity = v3f(0,0,0);
m_acceleration = v3f(0,0,0);
pos_translator.vect_show = m_position;
Expand Down Expand Up @@ -1512,6 +1512,7 @@ void GenericCAO::processMessage(const std::string &data)
if (m_is_local_player) {
LocalPlayer *player = m_env->getLocalPlayer();
player->makes_footstep_sound = m_prop.makes_footstep_sound;
player->setCollisionbox(m_selection_box);
}

if ((m_is_player && !m_is_local_player) && m_prop.nametag == "")
Expand Down
10 changes: 6 additions & 4 deletions src/content_sao.cpp
Expand Up @@ -784,7 +784,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, u16 peer_id
m_prop.hp_max = PLAYER_MAX_HP;
m_prop.physical = false;
m_prop.weight = 75;
m_prop.collisionbox = aabb3f(-0.3f, -1.0f, -0.3f, 0.3f, 0.75f, 0.3f);
m_prop.collisionbox = aabb3f(-0.3f, 0.0f, -0.3f, 0.3f, 1.77f, 0.3f);
// start of default appearance, this should be overwritten by LUA
m_prop.visual = "upright_sprite";
m_prop.visual_size = v2f(1, 2);
Expand Down Expand Up @@ -856,7 +856,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
os << serializeString(m_player->getName()); // name
writeU8(os, 1); // is_player
writeS16(os, getId()); //id
writeV3F1000(os, m_base_position + v3f(0,BS*1,0));
writeV3F1000(os, m_base_position);
writeF1000(os, m_yaw);
writeS16(os, getHP());

Expand Down Expand Up @@ -1009,7 +1009,7 @@ void PlayerSAO::step(float dtime, bool send_recommended)
if(isAttached()) // Just in case we ever do send attachment position too
pos = m_env->getActiveObject(m_attachment_parent_id)->getBasePosition();
else
pos = m_base_position + v3f(0,BS*1,0);
pos = m_base_position;
std::string str = gob_cmd_update_position(
pos,
v3f(0,0,0),
Expand Down Expand Up @@ -1414,7 +1414,9 @@ bool PlayerSAO::checkMovementCheat()

bool PlayerSAO::getCollisionBox(aabb3f *toset) const
{
*toset = aabb3f(-0.3f * BS, 0.0f, -0.3f * BS, 0.3f * BS, 1.75f * BS, 0.3f * BS);
//update collision box
toset->MinEdge = m_prop.collisionbox.MinEdge * BS;
toset->MaxEdge = m_prop.collisionbox.MaxEdge * BS;

toset->MinEdge += m_base_position;
toset->MaxEdge += m_base_position;
Expand Down
6 changes: 3 additions & 3 deletions src/inventorymanager.cpp
Expand Up @@ -611,8 +611,8 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
// Drop the item
ItemStack item1 = list_from->getItem(from_i);
item1.count = take_count;
if (PLAYER_TO_SA(player)->item_OnDrop(item1, player,
player->getBasePosition() + v3f(0,1,0))) {
if(PLAYER_TO_SA(player)->item_OnDrop(item1, player,
player->getBasePosition())) {
actually_dropped_count = take_count - item1.count;

if (actually_dropped_count == 0) {
Expand Down Expand Up @@ -815,7 +815,7 @@ void ICraftAction::apply(InventoryManager *mgr,
u16 count = it->count;
do {
PLAYER_TO_SA(player)->item_OnDrop(*it, player,
player->getBasePosition() + v3f(0,1,0));
player->getBasePosition());
if (count >= it->count) {
errorstream << "Couldn't drop replacement stack " <<
it->getItemString() << " because drop loop didn't "
Expand Down
2 changes: 2 additions & 0 deletions src/localplayer.h
Expand Up @@ -140,6 +140,8 @@ class LocalPlayer : public Player
v3f getEyePosition() const { return m_position + getEyeOffset(); }
v3f getEyeOffset() const;

void setCollisionbox(const aabb3f &box) { m_collisionbox = box; }

private:
void accelerateHorizontal(const v3f &target_speed, const f32 max_increase);
void accelerateVertical(const v3f &target_speed, const f32 max_increase);
Expand Down

0 comments on commit 49920cf

Please sign in to comment.