From 508c998590196c23934f88ff5f3326d3ccda3b80 Mon Sep 17 00:00:00 2001 From: stujones11 Date: Sun, 26 May 2019 17:56:22 +0100 Subject: [PATCH] Fix workbench and drops --- games/default/files/drops/init.lua | 13 ++++++++- games/default/files/workbench/init.lua | 39 +++++++++++++++++--------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/games/default/files/drops/init.lua b/games/default/files/drops/init.lua index 6387c4b95..cc6f5f1e0 100644 --- a/games/default/files/drops/init.lua +++ b/games/default/files/drops/init.lua @@ -2,9 +2,20 @@ local age = 0.5 --How old an item has to be before collecting local radius_magnet = 2 --Radius of item magnet local player_collect_height = 1.3 --Added to their pos y value +local function valid_pos() + if pos then + for _, v in pairs({"x", "y", "z"}) do + if not pos[v] or pos[v] < -32000 or pos[v] > 32000 then + return + end + end + return true + end +end + local function collect_items(player) local pos = player:get_pos() - if not pos then + if not valid_pos(pos) then return end local col_pos = vector.add(pos, {x=0, y=player_collect_height, z=0}) diff --git a/games/default/files/workbench/init.lua b/games/default/files/workbench/init.lua index 434e6940b..426d08cdd 100644 --- a/games/default/files/workbench/init.lua +++ b/games/default/files/workbench/init.lua @@ -166,11 +166,34 @@ function workbench.construct(pos) workbench:set_formspec(meta, 1) end -function workbench.fields(pos, _, fields) +function workbench.fields(pos, _, fields, sender) local meta = minetest.get_meta(pos) if fields.back then workbench:set_formspec(meta, 1) elseif fields.creating then workbench:set_formspec(meta, 2) - elseif fields.anvil then workbench:set_formspec(meta, 3) end + elseif fields.anvil then workbench:set_formspec(meta, 3) + elseif fields.quit and pos and sender then + local inv = sender:get_inventory() + if inv then + for i, stack in ipairs(inv:get_list("craft")) do + minetest.item_drop(stack, nil, pos) + stack:clear() + inv:set_stack("craft", i, stack) + end + end + inv = meta:get_inventory() + if inv then + for _, name in pairs({"input", "tool", "hammer"}) do + local stack = inv:get_stack(name, 1) + minetest.item_drop(stack, nil, pos) + stack:clear() + inv:set_stack(name, 1, stack) + end + for i, stack in ipairs(inv:get_list("forms")) do + stack:clear() + inv:set_stack("forms", i, stack) + end + end + end end function workbench.dig(pos) @@ -270,18 +293,6 @@ minetest.register_node("workbench:workbench", { on_metadata_inventory_take = workbench.on_take, allow_metadata_inventory_put = workbench.put, allow_metadata_inventory_move = workbench.move, - on_receive_fields = function(pos, formname, fields, sender) - if fields.quit and pos and sender then - local inv = sender:get_inventory() - if inv then - for i, stack in ipairs(inv:get_list("craft")) do - minetest.item_drop(stack, nil, pos) - stack:clear() - inv:set_stack("craft", i, stack) - end - end - end - end, }) minetest.register_tool("workbench:hammer", {