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.
This commit is contained in:
Aaron Suen 2021-07-05 13:42:46 -04:00
parent a1bda1a2cb
commit 99254bf726
3 changed files with 24 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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