2018-11-03 08:46:14 -04:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
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
|
|
|
local ItemStack, math, minetest, nodecore, pairs, setmetatable, type,
|
|
|
|
vector
|
|
|
|
= ItemStack, math, minetest, nodecore, pairs, setmetatable, type,
|
|
|
|
vector
|
|
|
|
local math_floor, math_pi, math_random, math_sqrt
|
|
|
|
= math.floor, math.pi, math.random, math.sqrt
|
2018-11-03 08:46:14 -04:00
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
|
|
|
--[[
|
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
|
|
|
|
|
2019-12-07 18:32:23 -05:00
|
|
|
function nodecore.stackentprops(stack, yaw, rotate, ss)
|
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
|
|
|
local props = {
|
2018-11-03 08:46:14 -04:00
|
|
|
hp_max = 1,
|
|
|
|
physical = false,
|
|
|
|
collide_with_objects = false,
|
|
|
|
collisionbox = {0, 0, 0, 0, 0, 0},
|
|
|
|
visual = "wielditem",
|
2019-12-01 11:08:12 -05:00
|
|
|
visual_size = {x = 0.4, y = 0.4},
|
2018-11-03 08:46:14 -04:00
|
|
|
textures = {""},
|
|
|
|
spritediv = {x = 1, y = 1},
|
|
|
|
initial_sprite_basepos = {x = 0, y = 0},
|
2019-03-04 19:33:55 -05:00
|
|
|
is_visible = false,
|
2019-12-07 18:32:23 -05:00
|
|
|
static_save = ss and true or false
|
2018-11-03 08:46:14 -04:00
|
|
|
}
|
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
|
|
|
local scale = 0
|
|
|
|
yaw = yaw or 0
|
2018-11-03 08:46:14 -04:00
|
|
|
if stack then
|
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
|
|
|
if type(stack) == "string" then stack = ItemStack(stack) end
|
2019-09-06 19:26:39 -04:00
|
|
|
props.is_visible = not stack:is_empty()
|
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
|
|
|
props.textures[1] = stack:get_name()
|
|
|
|
|
|
|
|
local ratio = stack:get_count() / stack:get_stack_max()
|
2019-12-09 07:51:08 -05:00
|
|
|
if ratio > 1 then ratio = 1 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
|
|
|
scale = math_sqrt(ratio) * 0.15 + 0.25
|
|
|
|
props.visual_size = {x = scale, y = scale}
|
|
|
|
|
|
|
|
props.automatic_rotate = rotate
|
|
|
|
and rotate * 2 / math_sqrt(math_sqrt(ratio)) or nil
|
|
|
|
|
|
|
|
if ratio == 1 then ratio = 1 - (stack:get_wear() / 65536) end
|
|
|
|
|
|
|
|
if ratio ~= 1 then yaw = yaw + 1/8 + 3/8 * (1 - ratio) end
|
|
|
|
yaw = yaw - 2 * math_floor(yaw / 2)
|
2018-11-03 08:46:14 -04:00
|
|
|
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
|
|
|
return props, scale, yaw * math_pi / 2
|
2018-11-03 08:46:14 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
------------------------------------------------------------------------
|
|
|
|
-- ITEM ENT APPEARANCE
|
|
|
|
|
|
|
|
local bii = minetest.registered_entities["__builtin:item"]
|
|
|
|
local item = {
|
|
|
|
set_item = function(self, ...)
|
|
|
|
local realobj = self.object
|
|
|
|
self.object = {}
|
|
|
|
setmetatable(self.object, {
|
|
|
|
__index = {
|
|
|
|
set_properties = function() end
|
|
|
|
}
|
|
|
|
})
|
|
|
|
bii.set_item(self, ...)
|
|
|
|
self.object = realobj
|
2019-08-27 19:14:51 -04:00
|
|
|
|
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
|
|
|
self.rotdir = self.rotdir or math_random(1, 2) * 2 - 3
|
2019-12-07 18:32:23 -05:00
|
|
|
local p, s = nodecore.stackentprops(self.itemstring, 0, self.rotdir, true)
|
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
|
|
|
p.physical = true
|
2019-03-31 21:32:11 -04:00
|
|
|
s = s / math_sqrt(2)
|
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
|
|
|
p.collisionbox = {-s, -s, -s, s, s, s}
|
|
|
|
return realobj:set_properties(p)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
setmetatable(item, bii)
|
|
|
|
minetest.register_entity(":__builtin:item", item)
|
|
|
|
|
2018-11-03 08:46:14 -04:00
|
|
|
------------------------------------------------------------------------
|
|
|
|
-- 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,
|
|
|
|
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
|