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() local pos = obj:get_pos()
if not pos then visinv_ents[self] = nil return end 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 stack = nodecore.stack_get(pos)
local sstr = stack:to_string() 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 self.stackstring = sstr
if stack:is_empty() then return objremove(self, obj) end 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 def = minetest.registered_items[stack:get_name()] or {}
local src = def.light_source or 0 local src = def.light_source or 0
if src > 0 then if src > 0 then
@ -70,14 +73,24 @@ local function itemcheck(self)
local props, scale, yaw = nodecore.stackentprops(stack, local props, scale, yaw = nodecore.stackentprops(stack,
rp.x * 3 + rp.y * 5 + rp.z * 7) 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 if obj:get_yaw() ~= yaw then
obj:set_yaw(yaw) obj:set_yaw(yaw)
end end
if not vector.equals(obj:get_pos(), rp) then
obj:set_pos(rp)
end
return obj:set_properties(props) return obj:set_properties(props)
end end

View File

@ -35,7 +35,10 @@ local function tryprocess(item, retry)
local meta = minetest.get_meta(item.from):to_table() local meta = minetest.get_meta(item.from):to_table()
minetest.remove_node(item.from) minetest.remove_node(item.from)
nodecore.set_loud(t, node) nodecore.set_loud(t, node)
meta.fields = meta.fields or {}
meta.fields.tweenfrom = minetest.serialize(item.from)
minetest.get_meta(t):from_table(meta) minetest.get_meta(t):from_table(meta)
nodecore.visinv_update_ents(t)
nodecore.fallcheck(t) nodecore.fallcheck(t)
local re = retry[hashpos(item.from)] local re = retry[hashpos(item.from)]
if not re then return end 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) 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 or nodecore.walkable({x = p.x, y = p.y - 1, z = p.z})) then
nodecore.place_stack(p, item) nodecore.place_stack(p, item)
minetest.get_meta(p):set_string("tweenfrom",
minetest.serialize(self.object:get_pos()))
self.itemstring = "" self.itemstring = ""
self.object:remove() self.object:remove()
return true return true