diff --git a/enchanting.lua b/enchanting.lua index 2eb5f3a..8c7c8bd 100644 --- a/enchanting.lua +++ b/enchanting.lua @@ -31,21 +31,19 @@ function enchanting.on_put(pos, listname, _, stack, _) local stn = stack:get_name() local meta = minetest.get_meta(pos) - if listname == "tool" then - if stn:find("sword") then - meta:set_string("formspec", enchanting.swords_fs()) - else - meta:set_string("formspec", enchanting.tools_fs()) - end - end + if listname == "tool" and stn:find("sword") then + meta:set_string("formspec", enchanting.swords_fs()) + else meta:set_string("formspec", enchanting.tools_fs()) end end function enchanting.is_allowed(toolname) local tdef = minetest.registered_tools[toolname] - if tdef and toolname:find("default:") and not toolname:find("stone") and not + if tdef and toolname:find("default:") and not + toolname:find("stone") and not toolname:find("wood") then return 1 - else return 0 end + end + return 0 end function enchanting.fields(pos, _, fields, _) @@ -69,22 +67,19 @@ end function enchanting.dig(pos, _) local inv = minetest.get_meta(pos):get_inventory() - if not inv:is_empty("tool") or not inv:is_empty("mese") then - return false - end - return true + return inv:is_empty("tool") and inv:is_empty("mese") end function enchanting.put(_, listname, _, stack, _) local toolname = stack:get_name() local count = stack:get_count() - if listname == "mese" then - if toolname == "default:mese_crystal" then return count - else return 0 end + if listname == "mese" and + toolname == "default:mese_crystal" then return count + elseif listname == "tool" then + return enchanting.is_allowed(toolname) end - if listname == "tool" then return enchanting.is_allowed(toolname) end - return count + return 0 end xdecor.register("enchantment_table", { diff --git a/hive.lua b/hive.lua index 58f92f4..9dc377b 100644 --- a/hive.lua +++ b/hive.lua @@ -15,8 +15,7 @@ end function hive.dig(pos, _) local inv = minetest.get_meta(pos):get_inventory() - if not inv:is_empty("honey") then return false end - return true + return inv:is_empty("honey") end xdecor.register("hive", { @@ -37,10 +36,7 @@ xdecor.register("hive", { local health = clicker:get_hp() clicker:set_hp(health - 1) end, - allow_metadata_inventory_put = function(_, listname, _, stack, _) - if listname == "honey" then return 0 end - return stack:get_count() - end + allow_metadata_inventory_put = function(...) return 0 end }) minetest.register_abm({ @@ -56,7 +52,8 @@ minetest.register_abm({ local maxp = vector.add(pos, radius) local flowers = minetest.find_nodes_in_area(minp, maxp, "group:flower") - if #flowers >= 2 and honey < 10 then - inv:add_item("honey", "xdecor:honey") end + if #flowers >= 2 and honey < 12 then + inv:add_item("honey", "xdecor:honey") + end end }) diff --git a/mailbox.lua b/mailbox.lua index 37bec1f..fafd724 100644 --- a/mailbox.lua +++ b/mailbox.lua @@ -1,6 +1,6 @@ local mailbox = {} screwdriver = screwdriver or {} -local xbg = default.gui_bg..default.gui_bg_img..default.gui_slots..default.get_hotbar_bg(0,5.25) +local xbg = default.gui_bg..default.gui_bg_img..default.gui_slots xdecor.register("mailbox", { description = "Mailbox", @@ -38,9 +38,7 @@ xdecor.register("mailbox", { local owner = meta:get_string("owner") local inv = meta:get_inventory() - if not inv:is_empty("main") or not player or - player:get_player_name() ~= owner then return false end - return true + return inv:is_empty("main") and player and player:get_player_name() == owner end, on_metadata_inventory_put = function(pos, listname, _, stack, _) local inv = minetest.get_meta(pos):get_inventory() @@ -50,26 +48,23 @@ xdecor.register("mailbox", { end end, allow_metadata_inventory_put = function(pos, listname, _, stack, _) - if listname == "main" then return 0 end if listname == "drop" then local meta = minetest.get_meta(pos) local inv = meta:get_inventory() - if inv:room_for_item("main", stack) then return -1 - else return 0 end + if inv:room_for_item("main", stack) then return -1 end end + return 0 end }) function mailbox.get_formspec(pos) local spos = pos.x..","..pos.y..","..pos.z - local formspec = "size[8,9]"..xbg.. + return "size[8,9]"..xbg..default.get_hotbar_bg(0,5.25).. "label[0,0;You received...]list[nodemeta:"..spos..";main;0,0.75;8,4;]list[current_player;main;0,5.25;8,4;]" - return formspec end function mailbox.get_insert_formspec(pos, owner) local spos = pos.x..","..pos.y..","..pos.z - local formspec = "size[8,5]"..xbg.. + return "size[8,5]"..xbg..default.get_hotbar_bg(0,1.25).. "label[0.5,0;Send your goods\nto "..owner.." :]list[nodemeta:"..spos..";drop;3.5,0;1,1;]list[current_player;main;0,1.25;8,4;]" - return formspec end diff --git a/nodes.lua b/nodes.lua index e056d84..e307421 100644 --- a/nodes.lua +++ b/nodes.lua @@ -1,4 +1,5 @@ screwdriver = screwdriver or {} +local xbg = default.gui_bg..default.gui_bg_img..default.gui_slots local function sit(pos, node, clicker) local player = clicker:get_player_name() @@ -12,7 +13,7 @@ local function sit(pos, node, clicker) elseif default.player_attached[player] ~= true and clicker:get_player_velocity().x == 0 and clicker:get_player_velocity().y == 0 and - clicker:get_player_velocity().z == 0 then + clicker:get_player_velocity().z == 0 and node.param2 <= 3 then clicker:set_eye_offset({x=0, y=-7, z=2}, {x=0, y=0, z=0}) clicker:set_physics_override(0, 0, 0) @@ -28,8 +29,8 @@ local function sit(pos, node, clicker) clicker:set_look_yaw(6.28) elseif node.param2 == 3 then clicker:set_look_yaw(4.75) - else return end - else return end + end + end end xpanes.register_pane("bamboo_frame", { @@ -188,8 +189,7 @@ xdecor.register("chair", { on_rightclick = function(pos, node, clicker) local objs = minetest.get_objects_inside_radius(pos, 0.5) for _, p in pairs(objs) do - if p:get_player_name() ~= clicker:get_player_name() or - node.param2 > 3 then return end + if p:get_player_name() ~= clicker:get_player_name() then return end end pos.y = pos.y + 0 sit(pos, node, clicker) @@ -284,8 +284,7 @@ xdecor.register("cushion", { on_rightclick = function(pos, node, clicker) local objs = minetest.get_objects_inside_radius(pos, 0.5) for _, p in pairs(objs) do - if p:get_player_name() ~= clicker:get_player_name() or - node.param2 > 3 then return end + if p:get_player_name() ~= clicker:get_player_name() then return end end pos.y = pos.y + 0 sit(pos, node, clicker) @@ -306,8 +305,7 @@ xdecor.register("cushion", { }) local function door_access(door) - if door:find("prison") then return true end - return false + return door:find("prison") end local door_types = { @@ -350,8 +348,7 @@ xdecor.register("enderchest", { on_rotate = screwdriver.rotate_simple, on_construct = function(pos) local meta = minetest.get_meta(pos) - local xbg = default.gui_bg..default.gui_bg_img..default.gui_slots..default.get_hotbar_bg(0,5) - meta:set_string("formspec", "size[8,9]"..xbg.. + meta:set_string("formspec", "size[8,9]"..xbg..default.get_hotbar_bg(0,5) "list[current_player;enderchest;0,0;8,4;]".. "list[current_player;main;0,5;8,4;]") meta:set_string("infotext", "Ender Chest") @@ -395,7 +392,7 @@ minetest.register_tool("xdecor:flint_steel", { else minetest.chat_send_player(player, "This area is protected.") end - else return end + end itemstack:add_wear(1000) return itemstack diff --git a/worktable.lua b/worktable.lua index 0b3dddd..4516c11 100644 --- a/worktable.lua +++ b/worktable.lua @@ -41,10 +41,8 @@ end function worktable.storage(pos) local inv = minetest.get_meta(pos):get_inventory() - local f = "size[8,7]"..xbg.. - "list[context;storage;0,0;8,2;]list[current_player;main;0,3.25;8,4;]" inv:set_size("storage", 8*2) - return f + return "size[8,7]"..xbg.."list[context;storage;0,0;8,2;]list[current_player;main;0,3.25;8,4;]" end function worktable.construct(pos) @@ -76,11 +74,8 @@ end function worktable.dig(pos, _) local inv = minetest.get_meta(pos):get_inventory() - if not inv:is_empty("input") or not inv:is_empty("hammer") or not - inv:is_empty("tool") or not inv:is_empty("storage") then - return false - end - return true + return inv:is_empty("input") and inv:is_empty("hammer") and + inv:is_empty("tool") and inv:is_empty("storage") end function worktable.contains(table, element) @@ -96,18 +91,17 @@ function worktable.put(_, listname, _, stack, _) local stn = stack:get_name() local count = stack:get_count() local mod, node = stn:match("([%a_]+):([%a_]+)") + local tdef = minetest.registered_tools[stn] + local twear = stack:get_wear() - if listname == "forms" then return 0 - elseif listname == "input" then - if not worktable.contains(nodes[mod], node) then return 0 end - elseif listname == "hammer" then - if stn ~= "xdecor:hammer" then return 0 end - elseif listname == "tool" then - local tdef = minetest.registered_tools[stn] - local twear = stack:get_wear() - if not (tdef and twear > 0) then return 0 end + if listname == "input" and + worktable.contains(nodes[mod], node) then return count + elseif listname == "hammer" and + stn == "xdecor:hammer" then return 1 + elseif listname == "tool" and tdef and twear > 0 then + return 1 end - return count + return 0 end function worktable.take(pos, listname, _, stack, _) @@ -192,7 +186,8 @@ for _, name in pairs(n) do for k, v in pairs(ndef.groups) do if k ~= "wood" and k ~= "stone" and k ~= "level" then - groups[k] = v end + groups[k] = v + end end minetest.register_node(":"..mod..":"..name.."_"..d[1], {