aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/client.cpp14
-rw-r--r--src/client/client.h1
-rw-r--r--src/client/content_cao.cpp5
-rw-r--r--src/client/content_cao.h3
-rw-r--r--src/client/game.cpp40
-rw-r--r--src/client/game.h1
-rw-r--r--src/client/localplayer.cpp19
-rw-r--r--src/client/localplayer.h6
-rw-r--r--src/defaultsettings.cpp1
-rw-r--r--src/network/clientpackethandler.cpp13
10 files changed, 73 insertions, 30 deletions
diff --git a/src/client/client.cpp b/src/client/client.cpp
index e3a790a56..d2330ecae 100644
--- a/src/client/client.cpp
+++ b/src/client/client.cpp
@@ -1290,7 +1290,7 @@ void Client::sendReady()
Send(&pkt);
}
-void Client::sendPlayerPos()
+void Client::sendPlayerPos(v3f pos)
{
LocalPlayer *player = m_env.getLocalPlayer();
if (!player)
@@ -1308,7 +1308,7 @@ void Client::sendPlayerPos()
// return;
if (
- player->last_position == player->getPosition() &&
+ player->last_position == pos &&
player->last_speed == player->getSpeed() &&
player->last_pitch == player->getPitch() &&
player->last_yaw == player->getYaw() &&
@@ -1317,7 +1317,7 @@ void Client::sendPlayerPos()
player->last_wanted_range == wanted_range)
return;
- player->last_position = player->getPosition();
+ player->last_position = pos;
player->last_speed = player->getSpeed();
player->last_pitch = player->getPitch();
player->last_yaw = player->getYaw();
@@ -1332,6 +1332,14 @@ void Client::sendPlayerPos()
Send(&pkt);
}
+void Client::sendPlayerPos()
+{
+ LocalPlayer *player = m_env.getLocalPlayer();
+ if (!player)
+ return;
+ sendPlayerPos(player->getPosition());
+}
+
void Client::removeNode(v3s16 p)
{
std::map<v3s16, MapBlock*> modified_blocks;
diff --git a/src/client/client.h b/src/client/client.h
index cdf516886..c7316fd91 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -437,6 +437,7 @@ public:
return m_env.getLocalPlayer()->formspec_prepend;
}
+ void sendPlayerPos(v3f pos);
void sendPlayerPos();
MeshUpdateThread m_mesh_update_thread;
diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp
index db78f7a65..5f60c3375 100644
--- a/src/client/content_cao.cpp
+++ b/src/client/content_cao.cpp
@@ -472,13 +472,14 @@ void GenericCAO::setAttachment(int parent_id, const std::string &bone, v3f posit
ClientActiveObject *parent = m_env->getActiveObject(parent_id);
if (parent_id != old_parent) {
+ if (old_parent)
+ m_waiting_for_reattach = 10;
if (auto *o = m_env->getActiveObject(old_parent))
o->removeAttachmentChild(m_id);
if (parent)
parent->addAttachmentChild(m_id);
}
-
-
+
updateAttachments();
}
diff --git a/src/client/content_cao.h b/src/client/content_cao.h
index 974ff9a1e..88aa4870c 100644
--- a/src/client/content_cao.h
+++ b/src/client/content_cao.h
@@ -224,6 +224,7 @@ public:
void addAttachmentChild(int child_id);
void removeAttachmentChild(int child_id);
ClientActiveObject *getParent() const;
+ int getParentId() const { return m_attachment_parent_id; }
const std::unordered_set<int> &getAttachmentChildIds() const
{ return m_attachment_child_ids; }
void updateAttachments();
@@ -275,4 +276,6 @@ public:
{
return m_prop.infotext;
}
+
+ float m_waiting_for_reattach;
};
diff --git a/src/client/game.cpp b/src/client/game.cpp
index 237d3539c..f1ce4aa60 100644
--- a/src/client/game.cpp
+++ b/src/client/game.cpp
@@ -2417,27 +2417,9 @@ PointedThing Game::updatePointedThing(
ClientMap &map = env.getClientMap();
const NodeDefManager *nodedef = map.getNodeDefManager();
- if (g_settings->getBool("killaura")) {
- std::vector<DistanceSortedActiveObject> allObjects;
- env.getActiveObjects(shootline.start, shootline.getLength() + 10.0f, allObjects);
- const v3f line_vector = shootline.getVector();
- for (const auto &allObject : allObjects) {
- ClientActiveObject *obj = allObject.obj;
- s16 id = obj->getId();
- v3f pos = obj->getPosition();
- v3f intersection;
- v3s16 normal;
- aabb3f selection_box;
- if (! obj->getSelectionBox(&selection_box))
- continue;
- aabb3f offsetted_box(selection_box.MinEdge + pos, selection_box.MaxEdge + pos);
- boxLineCollision(offsetted_box, shootline.start, line_vector, &intersection, &normal);
- PointedThing pointed(id, intersection, normal, (intersection - shootline.start).getLengthSQ());
- client->interact(INTERACT_START_DIGGING, pointed);
- break;
- }
- }
-
+ if (g_settings->getBool("killaura"))
+ handleKillaura(shootline.start, shootline.getLength());
+
runData.selected_object = NULL;
hud->pointing_at_object = false;
RaycastState s(shootline, look_for_object, liquids_pointable);
@@ -2514,6 +2496,22 @@ PointedThing Game::updatePointedThing(
return result;
}
+void Game::handleKillaura(v3f origin, f32 max_d)
+{
+ ClientEnvironment &env = client->getEnv();
+ std::vector<DistanceSortedActiveObject> allObjects;
+ env.getActiveObjects(origin, max_d, allObjects);
+ for (const auto &allObject : allObjects) {
+ ClientActiveObject *obj = allObject.obj;
+ s16 id = obj->getId();
+ aabb3f selection_box;
+ if (! obj->getSelectionBox(&selection_box))
+ continue;
+ PointedThing pointed(id, v3f(0,0,0), v3s16(0,0,0), 0);
+ client->interact(INTERACT_START_DIGGING, pointed);
+ break;
+ }
+}
void Game::handlePointingAtNothing(const ItemStack &playerItem)
{
diff --git a/src/client/game.h b/src/client/game.h
index 042375f4d..af34fb056 100644
--- a/src/client/game.h
+++ b/src/client/game.h
@@ -771,6 +771,7 @@ public:
PointedThing updatePointedThing(
const core::line3d<f32> &shootline, bool liquids_pointable,
bool look_for_object, const v3s16 &camera_offset);
+ void handleKillaura(v3f origin, f32 max_d);
void handlePointingAtNothing(const ItemStack &playerItem);
void handlePointingAtNode(const PointedThing &pointed,
const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime);
diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp
index 1e7040d57..d84238008 100644
--- a/src/client/localplayer.cpp
+++ b/src/client/localplayer.cpp
@@ -27,6 +27,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "map.h"
#include "client.h"
#include "content_cao.h"
+#include "util/pointedthing.h"
+#include "client/game.h"
/*
LocalPlayer
@@ -168,6 +170,9 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position,
void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
std::vector<CollisionInfo> *collision_info)
{
+ if (m_cao && m_cao->m_waiting_for_reattach > 0)
+ m_cao->m_waiting_for_reattach -= dtime;
+
// Node at feet position, update each ClientEnvironment::step()
if (!collision_info || collision_info->empty())
m_standing_node = floatToInt(m_position, BS);
@@ -712,7 +717,7 @@ v3f LocalPlayer::getEyeOffset() const
ClientActiveObject *LocalPlayer::getParent() const
{
- return m_cao ? m_cao->getParent() : nullptr;
+ return (m_cao && ! g_settings->getBool("entity_speed")) ? m_cao->getParent() : nullptr;
}
bool LocalPlayer::isDead() const
@@ -721,6 +726,18 @@ bool LocalPlayer::isDead() const
return !getCAO()->isImmortal() && hp == 0;
}
+void LocalPlayer::tryReattach(int id)
+{
+ PointedThing pointed(id, v3f(0, 0, 0), v3s16(0, 0, 0), 0);
+ m_client->interact(INTERACT_PLACE, pointed);
+ m_cao->m_waiting_for_reattach = 10;
+}
+
+bool LocalPlayer::isWaitingForReattach() const
+{
+ return g_settings->getBool("entity_speed") && m_cao && ! m_cao->getParent() && m_cao->m_waiting_for_reattach > 0;
+}
+
// 3D acceleration
void LocalPlayer::accelerate(const v3f &target_speed, const f32 max_increase_H,
const f32 max_increase_V, const bool use_pitch)
diff --git a/src/client/localplayer.h b/src/client/localplayer.h
index 345aec9d9..dc3e76118 100644
--- a/src/client/localplayer.h
+++ b/src/client/localplayer.h
@@ -157,7 +157,11 @@ public:
{
added_velocity += vel;
}
-
+
+ void tryReattach(int id);
+
+ bool isWaitingForReattach() const;
+
private:
void accelerate(const v3f &target_speed, const f32 max_increase_H,
const f32 max_increase_V, const bool use_pitch);
diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp
index d7399fdf6..3909fefe8 100644
--- a/src/defaultsettings.cpp
+++ b/src/defaultsettings.cpp
@@ -76,6 +76,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("increase_tool_range", "true");
settings->setDefault("hud_flags_bypass", "true");
settings->setDefault("antiknockback", "false");
+ settings->setDefault("entity_speed", "false");
// Keymap
settings->setDefault("remote_port", "30000");
diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp
index 5ca481880..9e0b35f53 100644
--- a/src/network/clientpackethandler.cpp
+++ b/src/network/clientpackethandler.cpp
@@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "server.h"
#include "util/strfnd.h"
#include "client/clientevent.h"
+#include "client/content_cao.h"
#include "client/sound.h"
#include "network/clientopcodes.h"
#include "network/connection.h"
@@ -448,7 +449,10 @@ void Client::handleCommand_ActiveObjectRemoveAdd(NetworkPacket* pkt)
string initialization data
}
*/
-
+
+ LocalPlayer *player = m_env.getLocalPlayer();
+ bool try_reattach = player && player->isWaitingForReattach();
+
try {
u8 type;
u16 removed_count, added_count, id;
@@ -467,6 +471,8 @@ void Client::handleCommand_ActiveObjectRemoveAdd(NetworkPacket* pkt)
for (u16 i = 0; i < added_count; i++) {
*pkt >> id >> type;
m_env.addActiveObject(id, type, pkt->readLongString());
+ if (try_reattach)
+ player->tryReattach(id);
}
} catch (PacketError &e) {
infostream << "handleCommand_ActiveObjectRemoveAdd: " << e.what()
@@ -589,10 +595,13 @@ void Client::handleCommand_Breath(NetworkPacket* pkt)
}
void Client::handleCommand_MovePlayer(NetworkPacket* pkt)
-{
+{
LocalPlayer *player = m_env.getLocalPlayer();
assert(player != NULL);
+ if ((player->getCAO() && player->getCAO()->getParentId()) || player->isWaitingForReattach())
+ return;
+
v3f pos;
f32 pitch, yaw;