aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/camera.cpp96
-rw-r--r--src/client/camera.h7
-rw-r--r--src/client/game.cpp1
-rw-r--r--src/itemdef.cpp20
-rw-r--r--src/itemdef.h5
-rw-r--r--src/script/common/c_content.cpp10
-rw-r--r--src/wieldanimation.cpp24
7 files changed, 114 insertions, 49 deletions
diff --git a/src/client/camera.cpp b/src/client/camera.cpp
index c359f3365..6c973c870 100644
--- a/src/client/camera.cpp
+++ b/src/client/camera.cpp
@@ -177,9 +177,12 @@ void Camera::step(f32 dtime)
if (m_wield_change_timer >= 0 && was_under_zero)
{
m_wieldnode->setItem(m_wield_item_next, m_client);
- m_wield_animation = m_wield_item_next
- .getDefinition(m_client->getItemDefManager())
- .wield_animation;
+ const ItemDefinition def = m_wield_item_next
+ .getDefinition(m_client->getItemDefManager());
+ m_wield_animation_base = def.wield_animation_base;
+ m_wield_animation_dig = def.wield_animation_dig;
+ m_wield_animation_place = def.wield_animation_place;
+ m_wield_animation_activate = def.wield_animation_activate;
}
if (m_view_bobbing_state != 0)
@@ -222,23 +225,21 @@ void Camera::step(f32 dtime)
}
}
- if (m_digging_button != -1) {
- float m_digging_anim_was = m_digging_anim;
- m_digging_anim += dtime;
- const WieldAnimation &wield_anim = WieldAnimation::getNamed(m_wield_animation);
- if (m_digging_anim >= wield_anim.getDuration())
- {
- m_digging_anim = 0;
- m_digging_button = -1;
- }
- float lim = 0.05f;
- if(m_digging_anim_was < lim && m_digging_anim >= lim)
- {
- if (m_digging_button == 0) {
- m_client->getEventManager()->put(new SimpleTriggerEvent(MtEvent::CAMERA_PUNCH_LEFT));
- } else if(m_digging_button == 1) {
- m_client->getEventManager()->put(new SimpleTriggerEvent(MtEvent::CAMERA_PUNCH_RIGHT));
- }
+ float m_digging_anim_was = m_digging_anim;
+ m_digging_anim += dtime;
+ const WieldAnimation &wield_anim = getCurrentWieldAnimation();
+ if (m_digging_anim >= wield_anim.getDuration())
+ {
+ m_digging_anim = 0;
+ m_digging_button = -1;
+ }
+ float lim = 0.05f;
+ if(m_digging_anim_was < lim && m_digging_anim >= lim)
+ {
+ if (m_digging_button == 0) {
+ m_client->getEventManager()->put(new SimpleTriggerEvent(MtEvent::CAMERA_PUNCH_LEFT));
+ } else if(m_digging_button == 1) {
+ m_client->getEventManager()->put(new SimpleTriggerEvent(MtEvent::CAMERA_PUNCH_RIGHT));
}
}
}
@@ -559,7 +560,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r
if (m_arm_inertia)
addArmInertia(player->getYaw());
- const WieldAnimation &wield_anim = WieldAnimation::getNamed(m_wield_animation);
+ const WieldAnimation &wield_anim = getCurrentWieldAnimation();
// Position the wielded item
//v3f wield_position = v3f(45, -35, 65);
@@ -568,6 +569,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r
v3f wield_rotation = v3f(-100, 120, -100);
core::quaternion wield_rotation_q = core::quaternion(wield_rotation * core::DEGTORAD);
wield_position.Y += fabs(m_wield_change_timer)*320 - 40;
+
#if 0
if(m_digging_anim < 0.05 || m_digging_anim > 0.5)
{
@@ -586,22 +588,22 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r
//wield_rotation.Z += frac * 15.0 * pow(ratiothing2, 1.0f);
}
#endif
- if (m_digging_button != -1)
- {
- f32 digfrac = m_digging_anim;
- v3f anim_position = wield_anim.getTranslationAt(digfrac);
- wield_position.X += anim_position.X;
- wield_position.Y += anim_position.Y;
- wield_position.Z += anim_position.Z;
-
- // Euler angles are PURE EVIL, so why not use quaternions?
- core::quaternion quat_rot = wield_anim.getRotationAt(digfrac);
- // apply rotation to starting rotation
- wield_rotation_q *= quat_rot;
- // convert back to euler angles
- wield_rotation_q.toEuler(wield_rotation);
- wield_rotation *= core::RADTODEG;
- } else {
+
+ f32 digfrac = m_digging_anim;
+ v3f anim_position = wield_anim.getTranslationAt(digfrac);
+ wield_position.X += anim_position.X;
+ wield_position.Y += anim_position.Y;
+ wield_position.Z += anim_position.Z;
+
+ // Euler angles are PURE EVIL, so why not use quaternions?
+ core::quaternion quat_rot = wield_anim.getRotationAt(digfrac);
+ // apply rotation to starting rotation
+ wield_rotation_q *= quat_rot;
+ // convert back to euler angles
+ wield_rotation_q.toEuler(wield_rotation);
+ wield_rotation *= core::RADTODEG;
+
+ if (m_digging_button == -1) {
f32 bobfrac = my_modf(m_view_bobbing_anim);
// std::cout << "Third block, frac = " << bobfrac << std::endl;
wield_position.X -= sin(bobfrac*M_PI*2.0) * 3.0;
@@ -783,3 +785,23 @@ void Camera::removeNametag(Nametag *nametag)
m_nametags.remove(nametag);
delete nametag;
}
+
+const WieldAnimation &Camera::getCurrentWieldAnimation()
+{
+ std::string anim_name;
+ switch (m_digging_button) {
+ case -1:
+ anim_name = m_wield_animation_base;
+ break;
+ case 0:
+ anim_name = m_wield_animation_dig;
+ break;
+ case 1:
+ anim_name = m_wield_animation_place;
+ break;
+ case 2:
+ anim_name = m_wield_animation_activate;
+ break;
+ }
+ return WieldAnimation::getNamed(anim_name);
+}
diff --git a/src/client/camera.h b/src/client/camera.h
index df156f06d..b5c4850ab 100644
--- a/src/client/camera.h
+++ b/src/client/camera.h
@@ -193,6 +193,8 @@ public:
inline void addArmInertia(f32 player_yaw);
+ const WieldAnimation &getCurrentWieldAnimation();
+
private:
// Nodes
scene::ISceneNode *m_playernode = nullptr;
@@ -254,7 +256,10 @@ private:
// If 0, left-click digging animation
// If 1, right-click digging animation
s32 m_digging_button = -1;
- std::string m_wield_animation = "";
+ std::string m_wield_animation_base = "";
+ std::string m_wield_animation_dig = "";
+ std::string m_wield_animation_place = "";
+ std::string m_wield_animation_activate = "";
// Animation when changing wielded item
f32 m_wield_change_timer = 0.125f;
diff --git a/src/client/game.cpp b/src/client/game.cpp
index 15fa2af23..acd0b959d 100644
--- a/src/client/game.cpp
+++ b/src/client/game.cpp
@@ -3106,6 +3106,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
client->getScript()->on_item_use(selected_item, pointed);
} else if (wasKeyPressed(KeyType::PLACE)) {
handlePointingAtNothing(selected_item);
+ camera->setDigging(2);
}
runData.pointed_old = pointed;
diff --git a/src/itemdef.cpp b/src/itemdef.cpp
index c535ef28c..9363e51c6 100644
--- a/src/itemdef.cpp
+++ b/src/itemdef.cpp
@@ -67,7 +67,10 @@ ItemDefinition& ItemDefinition::operator=(const ItemDefinition &def)
inventory_overlay = def.inventory_overlay;
wield_image = def.wield_image;
wield_overlay = def.wield_overlay;
- wield_animation = def.wield_animation;
+ wield_animation_base = def.wield_animation_base;
+ wield_animation_dig = def.wield_animation_dig;
+ wield_animation_place = def.wield_animation_place;
+ wield_animation_activate = def.wield_animation_activate;
wield_scale = def.wield_scale;
stack_max = def.stack_max;
usable = def.usable;
@@ -109,7 +112,10 @@ void ItemDefinition::reset()
inventory_overlay = "";
wield_image = "";
wield_overlay = "";
- wield_animation = "";
+ wield_animation_base = "base";
+ wield_animation_dig = "punch";
+ wield_animation_place = "punch";
+ wield_animation_activate = "base";
palette_image = "";
color = video::SColor(0xFFFFFFFF);
wield_scale = v3f(1.0, 1.0, 1.0);
@@ -166,7 +172,10 @@ void ItemDefinition::serialize(std::ostream &os, u16 protocol_version) const
writeARGB8(os, color);
os << serializeString16(inventory_overlay);
os << serializeString16(wield_overlay);
- os << serializeString16(wield_animation);
+ os << serializeString16(wield_animation_base);
+ os << serializeString16(wield_animation_dig);
+ os << serializeString16(wield_animation_place);
+ os << serializeString16(wield_animation_activate);
os << serializeString16(short_description);
}
@@ -221,7 +230,10 @@ void ItemDefinition::deSerialize(std::istream &is)
// If you add anything here, insert it primarily inside the try-catch
// block to not need to increase the version.
try {
- wield_animation = deSerializeString16(is);
+ wield_animation_base = deSerializeString16(is);
+ wield_animation_dig = deSerializeString16(is);
+ wield_animation_place = deSerializeString16(is);
+ wield_animation_activate = deSerializeString16(is);
short_description = deSerializeString16(is);
} catch (SerializationError &e) {};
}
diff --git a/src/itemdef.h b/src/itemdef.h
index 10b4e9069..4e12864c7 100644
--- a/src/itemdef.h
+++ b/src/itemdef.h
@@ -65,7 +65,10 @@ struct ItemDefinition
*/
std::string inventory_image; // Optional for nodes, mandatory for tools/craftitems
std::string inventory_overlay; // Overlay of inventory_image.
- std::string wield_animation; // Named wield animation
+ std::string wield_animation_base; // Named wield animations
+ std::string wield_animation_dig;
+ std::string wield_animation_place;
+ std::string wield_animation_activate;
std::string wield_image; // If empty, inventory_image or mesh (only nodes) is used
std::string wield_overlay; // Overlay of wield_image.
std::string palette_image; // If specified, the item will be colorized based on this
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 585e664fd..df8efb189 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -63,9 +63,17 @@ void read_item_definition(lua_State* L, int index,
getstringfield(L, index, "inventory_overlay", def.inventory_overlay);
getstringfield(L, index, "wield_image", def.wield_image);
getstringfield(L, index, "wield_overlay", def.wield_overlay);
- getstringfield(L, index, "wield_animation", def.wield_animation);
getstringfield(L, index, "palette", def.palette_image);
+ lua_getfield(L, index, "wield_animations");
+ if (lua_istable(L, -1)) {
+ getstringfield(L, -1, "base", def.wield_animation_base);
+ getstringfield(L, -1, "dig", def.wield_animation_dig);
+ getstringfield(L, -1, "place", def.wield_animation_place);
+ getstringfield(L, -1, "activate", def.wield_animation_activate);
+ }
+ lua_pop(L, 1);
+
// Read item color.
lua_getfield(L, index, "color");
read_color(L, -1, &def.color);
diff --git a/src/wieldanimation.cpp b/src/wieldanimation.cpp
index 9016098e4..4ddc63399 100644
--- a/src/wieldanimation.cpp
+++ b/src/wieldanimation.cpp
@@ -70,7 +70,7 @@ std::unordered_map<std::string, WieldAnimation> WieldAnimation::repository;
void WieldAnimation::fillRepository()
{
- // default: "punch"
+ // punch / dig
WieldAnimation &punch = repository["punch"];
punch.m_translationspline.addNode(v3f(0, 0, 0))
.addNode(v3f(-70, 50, 0))
@@ -84,6 +84,16 @@ void WieldAnimation::fillRepository()
punch.m_rotationspline.addIndex(1.0, 0, 2);
punch.setDuration(0.3f);
+ // base
+ WieldAnimation &base = repository["base"];
+ base.m_translationspline.addNode(v3f(0, 0, 0));
+ base.m_translationspline.addIndex(0.0, 0, 0);
+
+ base.m_rotationspline.addNode(quatFromAngles(0.0f, 0.0f, 0.0f));
+ base.m_rotationspline.addIndex(0.0, 0, 0);
+ base.setDuration(0.0f);
+
+ /*
WieldAnimation &dig = repository["dig"];
dig.m_translationspline.addNode(v3f(0, 0, 0))
.addNode(v3f(-70, -50, 0))
@@ -99,7 +109,7 @@ void WieldAnimation::fillRepository()
.addNode(quatFromAngles(0.0f, 0.0f, 0.0f));
dig.m_rotationspline.addIndex(1.0, 0, 2).addIndex(1.0, 2, 3);
dig.setDuration(0.3f);
-
+ */
// eat (without chewing)
WieldAnimation &eat = repository["eat"];
eat.m_translationspline.addNode(v3f(0, 0, 0))
@@ -110,6 +120,8 @@ void WieldAnimation::fillRepository()
.addNode(v3f(-55, 10, 0))
.addNode(v3f(-55, 15, 0))
.addNode(v3f(-55, 10, 0))
+ .addNode(v3f(-55, 15, 0))
+ .addNode(v3f(-55, 10, 0))
.addNode(v3f(-30, 0, 0))
.addNode(v3f(0, 0, 0))
.addNode(v3f(0, 0, 0));
@@ -118,13 +130,15 @@ void WieldAnimation::fillRepository()
.addIndex(0.5, 4, 1)
.addIndex(0.5, 5, 1)
.addIndex(0.5, 6, 1)
- .addIndex(1.0, 7, 3);
+ .addIndex(0.5, 7, 1)
+ .addIndex(0.5, 8, 1)
+ .addIndex(1.0, 9, 3);
eat.m_rotationspline.addNode(quatFromAngles(0.0f, 0.0f, 0.0f))
- .addNode(quatFromAngles(-90.0f, 20.0f, -80.0f))
+ .addNode(quatFromAngles(-85.0f, -30.0f, -80.0f))
.addNode(quatFromAngles(0.0f, 0.0f, 0.0f));
eat.m_rotationspline.addIndex(1.0, 0, 1).addIndex(2.0, 1, 0).addIndex(1.0, 1, 1);
- eat.setDuration(1.0f);
+ eat.setDuration(1.3f);
// "poke"
WieldAnimation &poke = repository["poke"];