2018-11-03 08:46:14 -04:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2020-01-05 11:42:22 -05:00
|
|
|
local minetest, nodecore, pairs, vector
|
|
|
|
= minetest, nodecore, pairs, vector
|
2018-11-03 08:46:14 -04:00
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
2020-01-05 12:59:12 -05:00
|
|
|
nodecore.amcoremod()
|
|
|
|
|
2018-11-03 08:46:14 -04:00
|
|
|
--[[
|
2019-08-27 19:14:51 -04:00
|
|
|
Helpers for visible inventory. Use "visinv" node group.
|
2018-11-03 08:46:14 -04:00
|
|
|
Sets up on_construct, after_destruct and an ABM to manage
|
|
|
|
the visual entities.
|
|
|
|
--]]
|
|
|
|
|
|
|
|
local modname = minetest.get_current_modname()
|
|
|
|
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
-- VISIBLE STACK ENTITY
|
|
|
|
|
|
|
|
minetest.register_entity(modname .. ":stackent", {
|
2019-09-06 19:26:39 -04:00
|
|
|
initial_properties = nodecore.stackentprops(),
|
2018-11-03 08:46:14 -04:00
|
|
|
is_stack = true,
|
|
|
|
itemcheck = function(self)
|
2019-04-06 20:34:13 -04:00
|
|
|
local pos = self.object:get_pos()
|
2019-02-23 10:21:27 -05:00
|
|
|
local stack = nodecore.stack_get(pos)
|
2019-02-28 23:47:36 -05:00
|
|
|
if not stack or stack:is_empty() then return self.object:remove() end
|
2019-03-08 19:11:05 -05:00
|
|
|
|
|
|
|
local rp = vector.round(pos)
|
2019-09-06 19:26:39 -04:00
|
|
|
local props, scale, yaw = nodecore.stackentprops(stack,
|
Larger, bolder, easier to see item and stack ents.
This restores an old visual scale from the extremely early days
of NodeCore. That style was removed to syncrhonize the scale of
stack nodes with item ents. The syncrhonization can work the
other way, too, though.
This was triggered by wanting to make loose item ents more
visually distinct at a glance from settled stack nodes, by making
loose item ent rotation faster. Since we were going to change the
properties either way, given that, then we might as well use the
better visual.
Since making stack nodes have a full-size collision hull, it was
distracting having the items inside be so mismatched in scale.
Also, the "pointing around stacks" thing becomes less important
in long-run gameplay with shelves in play, which do not allow
pointing around/through anyway.
2019-03-30 22:07:23 -04:00
|
|
|
rp.x * 3 + rp.y * 5 + rp.z * 7)
|
|
|
|
rp.y = rp.y + scale - 31/64
|
|
|
|
|
|
|
|
local obj = self.object
|
|
|
|
obj:set_properties(props)
|
|
|
|
obj:set_yaw(yaw)
|
|
|
|
obj:set_pos(rp)
|
2018-11-03 08:46:14 -04:00
|
|
|
end,
|
|
|
|
on_activate = function(self)
|
|
|
|
self.cktime = 0.00001
|
|
|
|
end,
|
|
|
|
on_step = function(self, dtime)
|
|
|
|
self.cktime = (self.cktime or 0) - dtime
|
|
|
|
if self.cktime > 0 then return end
|
|
|
|
self.cktime = 1
|
|
|
|
return self:itemcheck()
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
function nodecore.visinv_update_ents(pos, node)
|
|
|
|
node = node or minetest.get_node(pos)
|
2019-03-13 23:51:59 -04:00
|
|
|
local def = minetest.registered_items[node.name] or {}
|
|
|
|
local max = def.groups and def.groups.visinv and 1 or 0
|
2018-11-03 08:46:14 -04:00
|
|
|
|
|
|
|
local found = {}
|
2019-08-31 09:26:53 -04:00
|
|
|
for _, v in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do
|
2018-11-03 08:46:14 -04:00
|
|
|
if v and v.get_luaentity and v:get_luaentity()
|
|
|
|
and v:get_luaentity().is_stack then
|
|
|
|
found[#found + 1] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if #found < max then
|
|
|
|
minetest.add_entity(pos, modname .. ":stackent")
|
|
|
|
else
|
|
|
|
while #found > max do
|
|
|
|
found[#found]:remove()
|
|
|
|
found[#found] = nil
|
|
|
|
end
|
|
|
|
end
|
Larger, bolder, easier to see item and stack ents.
This restores an old visual scale from the extremely early days
of NodeCore. That style was removed to syncrhonize the scale of
stack nodes with item ents. The syncrhonization can work the
other way, too, though.
This was triggered by wanting to make loose item ents more
visually distinct at a glance from settled stack nodes, by making
loose item ent rotation faster. Since we were going to change the
properties either way, given that, then we might as well use the
better visual.
Since making stack nodes have a full-size collision hull, it was
distracting having the items inside be so mismatched in scale.
Also, the "pointing around stacks" thing becomes less important
in long-run gameplay with shelves in play, which do not allow
pointing around/through anyway.
2019-03-30 22:07:23 -04:00
|
|
|
|
2019-03-08 19:11:05 -05:00
|
|
|
return found
|
2018-11-03 08:46:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
-- NODE REGISTRATION HELPERS
|
|
|
|
|
|
|
|
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)
|
|
|
|
nodecore.visinv_update_ents(pos)
|
2019-09-09 07:05:01 -04:00
|
|
|
nodecore.fallcheck(pos)
|
2018-11-03 08:46:14 -04:00
|
|
|
end
|
|
|
|
|
2019-08-31 09:26:53 -04:00
|
|
|
nodecore.register_on_register_item(function(_, def)
|
2019-01-24 20:45:14 -05:00
|
|
|
if def.type ~= "node" then return end
|
2019-02-23 21:30:35 -05:00
|
|
|
|
2018-11-03 08:46:14 -04:00
|
|
|
def.groups = def.groups or {}
|
|
|
|
|
|
|
|
if def.groups.visinv then
|
|
|
|
def.on_construct = def.on_construct or nodecore.visinv_on_construct
|
|
|
|
def.after_destruct = def.after_destruct or nodecore.visinv_after_destruct
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2019-01-06 12:02:37 -05:00
|
|
|
nodecore.register_limited_abm({
|
2018-11-03 08:46:14 -04:00
|
|
|
label = "VisInv Check",
|
|
|
|
nodenames = {"group:visinv"},
|
|
|
|
interval = 1,
|
|
|
|
chance = 1,
|
2020-01-10 06:26:07 -05:00
|
|
|
ignore_stasis = true,
|
2018-11-03 08:46:14 -04:00
|
|
|
action = function(...) return nodecore.visinv_update_ents(...) end
|
|
|
|
})
|
|
|
|
|
|
|
|
------------------------------------------------------------------------
|
|
|
|
-- DIG INVENTORY
|
|
|
|
|
|
|
|
local digpos
|
|
|
|
local old_node_dig = minetest.node_dig
|
2019-03-24 18:34:17 -04:00
|
|
|
minetest.node_dig = function(pos, ...)
|
2019-03-24 18:42:32 -04:00
|
|
|
nodecore.stack_sounds(pos, "dug")
|
2018-11-03 08:46:14 -04:00
|
|
|
local function helper(...)
|
|
|
|
digpos = nil
|
|
|
|
return ...
|
|
|
|
end
|
|
|
|
digpos = pos
|
2019-03-24 18:34:17 -04:00
|
|
|
return helper(old_node_dig(pos, ...))
|
2018-11-03 08:46:14 -04:00
|
|
|
end
|
|
|
|
local old_get_node_drops = minetest.get_node_drops
|
|
|
|
minetest.get_node_drops = function(...)
|
2019-03-24 18:34:17 -04:00
|
|
|
local drops = old_get_node_drops(...)
|
|
|
|
if not digpos then return drops end
|
|
|
|
drops = drops or {}
|
2019-02-23 10:21:27 -05:00
|
|
|
local stack = nodecore.stack_get(digpos)
|
2019-03-05 19:20:38 -05:00
|
|
|
if stack and not stack:is_empty() then
|
2019-03-24 18:34:17 -04:00
|
|
|
drops[#drops + 1] = stack
|
2019-03-05 19:20:38 -05:00
|
|
|
end
|
2019-03-24 18:34:17 -04:00
|
|
|
return drops
|
2019-01-28 23:13:21 -05:00
|
|
|
end
|