From 99254bf726353308e7307b42318c385fac64a05c Mon Sep 17 00:00:00 2001 From: Aaron Suen Date: Mon, 5 Jul 2021 13:42:46 -0400 Subject: [PATCH] Simple visinv tweening - On door convey - On item ent settling Only able to support limited cases, and still can't usefully animate nodes, but at least this makes some item placement behavior look smoother. --- mods/nc_api_visinv/init.lua | 25 +++++++++++++++++++------ mods/nc_doors/convey.lua | 3 +++ mods/nc_items/ent_item.lua | 2 ++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/mods/nc_api_visinv/init.lua b/mods/nc_api_visinv/init.lua index c761c797..1297e0c7 100644 --- a/mods/nc_api_visinv/init.lua +++ b/mods/nc_api_visinv/init.lua @@ -52,15 +52,18 @@ local function itemcheck(self) local pos = obj:get_pos() if not pos then visinv_ents[self] = nil return end + local rp = vector.round(pos) + local nodemeta = minetest.get_meta(rp) + local tweenfrom = minetest.deserialize(nodemeta:get_string("tweenfrom")) + local stack = nodecore.stack_get(pos) local sstr = stack:to_string() - if self.stackstring == sstr then return end + if (not tweenfrom) and self.stackstring == sstr then return end self.stackstring = sstr if stack:is_empty() then return objremove(self, obj) end - local rp = vector.round(pos) local def = minetest.registered_items[stack:get_name()] or {} local src = def.light_source or 0 if src > 0 then @@ -70,14 +73,24 @@ local function itemcheck(self) local props, scale, yaw = nodecore.stackentprops(stack, rp.x * 3 + rp.y * 5 + rp.z * 7) - rp.y = rp.y + scale - 31/64 + local op = { + x = rp.x, + y = rp.y + scale - 31/64, + z = rp.z + } + + if tweenfrom then + nodemeta:set_string("tweenfrom", "") + obj:set_pos(tweenfrom) + obj:move_to(op) + elseif not vector.equals(obj:get_pos(), op) then + obj:set_pos(op) + end if obj:get_yaw() ~= yaw then obj:set_yaw(yaw) end - if not vector.equals(obj:get_pos(), rp) then - obj:set_pos(rp) - end + return obj:set_properties(props) end diff --git a/mods/nc_doors/convey.lua b/mods/nc_doors/convey.lua index 24a159e7..1a9a8509 100644 --- a/mods/nc_doors/convey.lua +++ b/mods/nc_doors/convey.lua @@ -35,7 +35,10 @@ local function tryprocess(item, retry) local meta = minetest.get_meta(item.from):to_table() minetest.remove_node(item.from) nodecore.set_loud(t, node) + meta.fields = meta.fields or {} + meta.fields.tweenfrom = minetest.serialize(item.from) minetest.get_meta(t):from_table(meta) + nodecore.visinv_update_ents(t) nodecore.fallcheck(t) local re = retry[hashpos(item.from)] if not re then return end diff --git a/mods/nc_items/ent_item.lua b/mods/nc_items/ent_item.lua index 519fc0c3..a742821f 100644 --- a/mods/nc_items/ent_item.lua +++ b/mods/nc_items/ent_item.lua @@ -44,6 +44,8 @@ nodecore.register_item_entity_on_settle(function(self, pos) and (rel.y <= 0 or (p.y - 1 < nodecore.map_limit_min) or nodecore.walkable({x = p.x, y = p.y - 1, z = p.z})) then nodecore.place_stack(p, item) + minetest.get_meta(p):set_string("tweenfrom", + minetest.serialize(self.object:get_pos())) self.itemstring = "" self.object:remove() return true