Apply big stack refactor.

This commit is contained in:
Aaron Suen 2019-02-23 10:21:27 -05:00
parent 94bd5a9cc8
commit 58cd080fdf
8 changed files with 18 additions and 57 deletions

View File

@ -49,11 +49,7 @@ minetest.register_entity(modname .. ":stackent", {
is_stack = true,
itemcheck = function(self)
local pos = self.object:getpos()
local meta = minetest.get_meta(pos)
if not meta then return self.object:remove() end
local inv = meta:get_inventory()
if not inv then return self.object:remove() end
local stack = inv:get_stack("solo", 1)
local stack = nodecore.stack_get(pos)
if not stack or stack:get_count() < 1 then return self.object:remove() end
self.rot = self.rot or math_random(1, 2) * 2 - 3
self.object:set_properties(stackentprops(stack, function(s)
@ -150,9 +146,7 @@ minetest.get_node_drops = function(...)
local drops = old_get_node_drops(...)
if not digpos then return drops end
drops = drops or {}
local meta = minetest.get_meta(digpos)
local inv = meta:get_inventory()
local stack = inv:get_stack("solo", 1)
local stack = nodecore.stack_get(digpos)
if stack and not stack:is_empty() then
drops[#drops + 1] = stack
end

View File

@ -39,7 +39,7 @@ function nodecore.match(thing, crit)
end
local def = minetest.registered_items[thing.name]
if (not thing.stacked) and def.groups and def.groups.is_stack_only then
local stack = minetest.get_meta(thing):get_inventory():get_stack("solo", 1)
local stack = nodecore.stack_get(thing)
if stack and not stack:is_empty() then
thing.name = stack:get_name()
def = minetest.registered_items[thing.name]

View File

@ -20,7 +20,8 @@ function nodecore.stack_add(pos, stack)
end
function nodecore.stack_giveto(pos, player)
local stack = nodecore.solostack_get(pos)
local stack = nodecore.stack_get(pos)
stack = player:get_inventory():add_item("main", stack)
return nodecore.solostack_set(pos, stack)
nodecore.stack_set(pos, stack)
return stack:is_empty()
end

View File

@ -88,13 +88,6 @@ function nodecore.craft_check(pos, node, data)
node.y = pos.y
node.z = pos.z
data.node = node
local reg = minetest.registered_items[node.name]
local groups = reg and reg.groups or {}
if groups.is_stack_only then
local stack = minetest.get_meta(pos):get_inventory():get_stack("solo", 1)
node.name = stack:get_name()
node.count = stack:get_count()
node.wear = stack:get_wear() end
for _, rc in ipairs(nodecore.craft_recipes) do
if nodecore.match(node, rc.root.match) and data.action == rc.action then
if go(rc, 1, 0, 0, 1) then return true end

View File

@ -8,7 +8,7 @@ local function pummelparticles(data)
local nodedef = data.nodedef
local pname = data.pname
local stack = minetest.get_meta(data.node):get_inventory():get_stack("solo", 1)
local stack = nodecore.stack_get(data.node)
if stack and not stack:is_empty() then
nodedef = minetest.registered_items[stack:get_name()] or nodedef
end

View File

@ -10,9 +10,7 @@ local modname = minetest.get_current_modname()
local stackbox = nodecore.fixedbox(-0.4, -0.5, -0.4, 0.4, 0.3, 0.4)
local function invdef(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local stack = inv:get_stack("solo", 1)
local stack = nodecore.stack_get(pos)
if not stack or stack:is_empty() then return end
local def = minetest.registered_items[stack:get_name()]
return stack:get_count() == (def.pummel_stack or 1) and def or nil
@ -41,26 +39,14 @@ minetest.register_node(modname .. ":stack", {
paramtype = "light",
sunlight_propagates = true,
repose_drop = function(posfrom, posto, node)
local meta = minetest.get_meta(posfrom)
local inv = meta:get_inventory()
local stack = inv:get_stack("solo", 1)
local stack = nodecore.stack_get(posfrom)
if stack and not stack:is_empty() then
nodecore.item_eject(posto, stack)
end
return minetest.remove_node(posfrom)
end,
on_rightclick = function(pos, node, whom, stack, pointed, ...)
local inv = minetest.get_meta(pos):get_inventory()
local s = inv:get_stack("solo", 1)
if s and s:get_name() == stack:get_name() then
if whom and whom:get_player_control().sneak then
if inv:add_item("solo", ItemStack(stack:get_name()))
:is_empty() then stack:take_item(1) end
return stack
end
return inv:add_item("solo", stack)
end
return minetest.item_place_node(stack, whom, pointed)
return nodecore.stack_add(pos, stack)
end
})
@ -69,11 +55,11 @@ function nodecore.place_stack(pos, stack, placer, pointed_thing)
local name = stack:get_name()
local below = {x = pos.x, y = pos.y - 1, z = pos.z}
stack = minetest.get_meta(below):get_inventory():add_item("solo", stack)
stack = nodecore.stack_add(below, stack)
if stack:is_empty() then return end
minetest.set_node(pos, {name = modname .. ":stack"})
minetest.get_meta(pos):get_inventory():set_stack("solo", 1, stack)
nodecore.stack_set(pos, stack)
if placer and pointed_thing then
nodecore.craft_check(pos, {name = stack:get_name()}, {
action = "place",
@ -103,7 +89,7 @@ local item = {
pos = nodecore.scan_flood(pos, 5,
function(p)
if p.y > pos.y then return end
i = minetest.get_meta(p):get_inventory():add_item("solo", i)
i = nodecore.stack_add(p, i)
if i:is_empty() then return p end
if nodecore.buildable_to(p) then return p end
end)

View File

@ -112,8 +112,7 @@ nodecore.register_limited_abm({
chance = 1,
nodenames = {"group:visinv"},
action = function(pos, node)
local inv = minetest.get_meta(pos):get_inventory()
local stack = inv:get_stack("solo", 1)
local stack = nodecore.stack_get(pos)
if stack:is_empty() then return end
local def = minetest.registered_items[stack:get_name()]
if not def then return end
@ -127,7 +126,7 @@ nodecore.register_limited_abm({
elseif timecounter(stack:get_meta(), 30, heated(pos)) then
return replacestack(pos, def.metal_alt_hot, stack)
end
return inv:set_stack("solo", 1, stack)
return nodecore.stack_set(pos, stack)
end})
-- Because of how massive they are, forging a block is a hot-working process.

View File

@ -5,15 +5,6 @@ local minetest, nodecore
local modname = minetest.get_current_modname()
local function pickup(pos, whom)
local inv = minetest.get_meta(pos):get_inventory()
local stack = inv:get_stack("solo", 1)
if not stack or stack:is_empty() then return true end
stack = whom:get_inventory():add_item("main", stack)
inv:set_stack("solo", 1, stack)
return stack:is_empty()
end
minetest.register_node(modname .. ":shelf", {
description = "Wooden Shelf",
drawtype = "nodebox",
@ -45,16 +36,13 @@ minetest.register_node(modname .. ":shelf", {
end,
on_rightclick = function(pos, node, clicker, stack, pointed_thing)
if not stack or stack:is_empty() then return end
local inv = minetest.get_meta(pos):get_inventory()
stack = inv:add_item("solo", stack)
nodecore.visinv_update_ents(pos)
return stack
return nodecore.stack_add(pos, stack)
end,
on_punch = function(pos, node, puncher)
return pickup(pos, puncher)
return nodecore.stack_giveto(pos, puncher)
end,
on_dig = function(pos, node, digger, ...)
if pickup(pos, digger) then
if nodecore.stack_giveto(pos, digger) then
return minetest.node_dig(pos, node, digger, ...)
end
end