Commit ce66c45a authored by Aaron Suen's avatar Aaron Suen
Browse files

Experimental tweening for visinv ents.

parent 48191eb0
......@@ -54,15 +54,22 @@ function nodecore.stackentprops(stack, yaw, rotate)
return props, scale, yaw * math_pi / 2
end
local function gettween(pos)
local meta = minetest.get_meta(pos)
local tween = meta:get_string("tween")
tween = tween and tween ~= "" and minetest.deserialize(tween)
return tween and tween.time < nodecore.gametime + 2 and tween or nil
end
minetest.register_entity(modname .. ":stackent", {
initial_properties = nodecore.stackentprops(),
is_stack = true,
itemcheck = function(self)
local pos = self.object:get_pos()
itemcheck = function(self, initial)
local pos = self.pos
local stack = nodecore.stack_get(pos)
if not stack or stack:is_empty() then return self.object:remove() end
local rp = vector.round(pos)
local rp = {x = pos.x, y = pos.y, z = pos.z}
local props, scale, yaw = nodecore.stackentprops(stack,
rp.x * 3 + rp.y * 5 + rp.z * 7)
rp.y = rp.y + scale - 31/64
......@@ -70,10 +77,19 @@ minetest.register_entity(modname .. ":stackent", {
local obj = self.object
obj:set_properties(props)
obj:set_yaw(yaw)
obj:set_pos(rp)
if initial then
local tween = gettween(pos)
if tween then rp = tween.pos end
minetest.log("initial: " .. minetest.serialize(rp))
obj:set_pos(rp)
else
obj:move_to(rp, true)
end
end,
on_activate = function(self)
self.cktime = 0.00001
on_activate = function(self, pos)
self.pos = minetest.deserialize(pos)
self.cktime = 0
return self:itemcheck(true)
end,
on_step = function(self, dtime)
self.cktime = (self.cktime or 0) - dtime
......@@ -89,15 +105,18 @@ function nodecore.visinv_update_ents(pos, node)
local max = def.groups and def.groups.visinv and 1 or 0
local found = {}
for _, v in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do
if v and v.get_luaentity and v:get_luaentity()
and v:get_luaentity().is_stack then
for _, v in pairs(minetest.get_objects_inside_radius(pos, 16)) do
local lua = v and v.get_luaentity and v:get_luaentity()
if lua and lua.is_stack and vector.equals(lua.pos, pos) then
found[#found + 1] = v
end
end
if #found < max then
minetest.add_entity(pos, modname .. ":stackent")
local tween = gettween(pos)
minetest.add_entity(tween and tween.pos or pos,
modname .. ":stackent",
minetest.serialize(pos))
else
while #found > max do
found[#found]:remove()
......@@ -142,7 +161,6 @@ function nodecore.visinv_on_construct(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size("solo", 1)
nodecore.visinv_update_ents(pos)
end
function nodecore.visinv_after_destruct(pos)
......
......@@ -6,7 +6,8 @@ local math_random
-- LUALOCALS > ---------------------------------------------------------
local function settle(self)
local pos = vector.round(self.object:get_pos())
local rawpos = self.object:get_pos()
local pos = vector.round(rawpos)
local i = ItemStack(self.itemstring)
pos = nodecore.scan_flood(pos, 5,
function(p)
......@@ -17,7 +18,9 @@ local function settle(self)
if nodecore.buildable_to(p) then return p end
end)
if not pos then return end
if not i:is_empty() then nodecore.place_stack(pos, i) end
if not i:is_empty() then
nodecore.place_stack(pos, i, nil, nil, rawpos)
end
self.itemstring = ""
self.object:remove()
return true
......
......@@ -59,7 +59,7 @@ function minetest.item_drop(item, player, ...)
if stack:is_empty() then return dummyent end
end
if nodecore.buildable_to(p) then
nodecore.place_stack(p, stack, player)
nodecore.place_stack(p, stack, player, nil, start)
return dummyent
end
end
......
......@@ -66,7 +66,7 @@ minetest.register_node(modname .. ":stack", {
after_dig_node = pezdispense
})
function nodecore.place_stack(pos, stack, placer, pointed_thing)
function nodecore.place_stack(pos, stack, placer, pointed_thing, tweenfrom)
stack = ItemStack(stack)
local below = {x = pos.x, y = pos.y - 1, z = pos.z}
......@@ -87,6 +87,11 @@ function nodecore.place_stack(pos, stack, placer, pointed_thing)
end
minetest.set_node(pos, {name = modname .. ":stack"})
minetest.get_meta(pos):set_string("tween", minetest.serialize({
pos = tweenfrom or pos,
time = nodecore.gametime
}))
minetest.log("tweenfrom: " .. minetest.serialize(tweenfrom or pos))
nodecore.stack_set(pos, stack)
if placer and pointed_thing then
nodecore.craft_check(pos, {name = stack:get_name()}, {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment