From e8324f5bf116fc9e97ee68443c302c7f043470a8 Mon Sep 17 00:00:00 2001 From: flux <25628292+fluxionary@users.noreply.github.com> Date: Sun, 19 Jun 2022 17:08:21 -0700 Subject: [PATCH] tweak some things --- .github/workflows/build.yml | 3 +++ CHANGELOG.md | 4 +++- README.md | 8 ++++++- invsaw/README.md | 12 ----------- invsaw/api.lua | 8 +++++-- invsaw/privs.lua | 43 +++++++++++++------------------------ luacheck.sh | 7 ++++++ stairsplus/api/station.lua | 13 ++++++++++- stairsplus/circular_saw.lua | 6 +++--- 9 files changed, 56 insertions(+), 48 deletions(-) delete mode 100644 invsaw/README.md create mode 100644 luacheck.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b5830a6..7b84ab1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,6 +14,9 @@ jobs: - name: install luacheck via luarocks run: luarocks install --local luacheck + - name: luacheck invsaw + run: $HOME/.luarocks/bin/luacheck --config ./invsaw/.luacheckrc -q ./invsaw + - name: luacheck moreblocks run: $HOME/.luarocks/bin/luacheck --config ./moreblocks/.luacheckrc -q ./moreblocks diff --git a/CHANGELOG.md b/CHANGELOG.md index 8be1e8e..64237ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -164,7 +164,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Initial versioned release. -[Unreleased]: https://github.com/minetest-mods/moreblocks/compare/v2.2.0...HEAD +[Unreleased]: https://github.com/minetest-mods/moreblocks/compare/v3.0.0...HEAD + +[3.0.0]: https://github.com/minetest-mods/moreblocks/compare/v2.2.0...v3.0.0 [2.2.0]: https://github.com/minetest-mods/moreblocks/compare/v2.1.0...v2.2.0 diff --git a/README.md b/README.md index c5a8f81..5151ce1 100644 --- a/README.md +++ b/README.md @@ -41,11 +41,17 @@ Stairs+ registrations for various mods which were formerly done automatically as ## invsaw +Adds a button in unified_inventory that allows you to use the circular saw interface if you are +playing creatively, or have a circular saw item in your inventory and have the right priv +(`interact`, by default). +Invsaw was taken from [cheapie's invsaw mod](https://forum.minetest.net/viewtopic.php?t=14736), which +itself borrowed heavily from an older version of this mod. Flux decided to just add it here because it +needed to be fully rewritten to be compatible w/ their modifications to the stairsplus API. # Documentation -## for plaers +## for players ## for admins diff --git a/invsaw/README.md b/invsaw/README.md deleted file mode 100644 index 975af93..0000000 --- a/invsaw/README.md +++ /dev/null @@ -1,12 +0,0 @@ -invsaw -====== - -This mod adds a button in unified_inventory that opens a formspec that works exactly like the -moreblocks circular saw. It requires that either the server is in creative mode, you have the -"creative" priv, or you have one or more circular saws (moreblocks:circular_saw) in your inventory. - -Dependencies: moreblocks, unified_inventory - -Contains large amounts of code based on Calinou's moreblocks mod, and a texture based on some textures -from the same mod. - diff --git a/invsaw/api.lua b/invsaw/api.lua index db7ebf3..f7b982b 100644 --- a/invsaw/api.lua +++ b/invsaw/api.lua @@ -1,3 +1,5 @@ +local server_is_creative = minetest.settings:get_bool("creative_mode", false) + function invsaw.has_saw_in_inventory(player) local inv = player:get_inventory() return inv:contains_item("main", invsaw.settings.saw_item) @@ -5,15 +7,17 @@ end function invsaw.can_use_saw(player) return ( + server_is_creative or minetest.check_player_privs(player, invsaw.settings.creative_priv) or - minetest.check_player_privs(player, invsaw.settings.priv) + minetest.check_player_privs(player, invsaw.settings.priv) ) end function invsaw.allow_use_saw(player) return ( + server_is_creative or minetest.check_player_privs(player, invsaw.settings.creative_priv) or - (minetest.check_player_privs(player, invsaw.settings.priv) and invsaw.has_saw_in_inventory(player)) + (minetest.check_player_privs(player, invsaw.settings.priv) and invsaw.has_saw_in_inventory(player)) ) end diff --git a/invsaw/privs.lua b/invsaw/privs.lua index 5a62af9..b905738 100644 --- a/invsaw/privs.lua +++ b/invsaw/privs.lua @@ -10,22 +10,20 @@ local function on_priv_change(name) end end +local function override_on_priv_change(old) + return function(name, cause) + on_priv_change(name) + if old then + old(name, cause) + end + end +end + if minetest.registered_privileges[priv] then local def = minetest.registered_privileges[priv] - local old_on_grant = def.on_grant - local old_on_revoke = def.on_revoke - def.on_grant = function(name, cause) - on_priv_change(name) - if old_on_grant then - old_on_grant(name, cause) - end - end - def.on_revoke = function(name, cause) - on_priv_change(name) - if old_on_revoke then - old_on_revoke(name, cause) - end - end + def.on_grant = override_on_priv_change(def.on_grant) + def.on_revoke = override_on_priv_change(def.on_revoke) + else minetest.register_privilege(priv, { description = "Allow use of the circular saw in inventory", @@ -38,20 +36,9 @@ end if minetest.registered_privileges[creative_priv] then local def = minetest.registered_privileges[creative_priv] - local old_on_grant = def.on_grant - local old_on_revoke = def.on_revoke - def.on_grant = function(name, cause) - on_priv_change(name) - if old_on_grant then - old_on_grant(name, cause) - end - end - def.on_revoke = function(name, cause) - on_priv_change(name) - if old_on_revoke then - old_on_revoke(name, cause) - end - end + def.on_grant = override_on_priv_change(def.on_grant) + def.on_revoke = override_on_priv_change(def.on_revoke) + else minetest.register_privilege(creative_priv, { description = "Allow use of the inventory saw creatively", diff --git a/luacheck.sh b/luacheck.sh new file mode 100644 index 0000000..6475cbe --- /dev/null +++ b/luacheck.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +luacheck --config ./invsaw/.luacheckrc -q ./invsaw +luacheck --config ./moreblocks/.luacheckrc -q ./moreblocks +luacheck --config ./stairsplus/.luacheckrc -q ./stairsplus +luacheck --config ./stairsplus_legacy/.luacheckrc -q ./stairsplus_legacy + diff --git a/stairsplus/api/station.lua b/stairsplus/api/station.lua index 7e1d2cc..8f23bf6 100644 --- a/stairsplus/api/station.lua +++ b/stairsplus/api/station.lua @@ -200,7 +200,15 @@ function station.initialize_inventory(inv) inv:set_size("stairsplus:input", 1) inv:set_size("stairsplus:micro", 1) inv:set_size("stairsplus:recycle", 1) - inv:set_size("stairsplus:output", 6 * 9) + inv:set_size("stairsplus:output", 7 * 7) + + -- get rid of old lists + for _, listname in ipairs({"input", "micro", "recycle", "output"}) do + if inv:get_size(listname) > 0 then + inv:set_list(("stairsplus:%s"):format(listname), inv:get_list(listname)) + inv:set_size(listname, 0) + end + end end function station.on_construct(pos, shape_groups, build_formspec, update_infotext) @@ -271,6 +279,9 @@ function api.register_station(name, shape_groups, def) def._stairsplus_shape_groups = shape_groups + def.groups = table.copy(def.groups or {}) + def.groups.stairsplus_station = 1 + minetest.register_node(name, def) end diff --git a/stairsplus/circular_saw.lua b/stairsplus/circular_saw.lua index 3224044..688973e 100644 --- a/stairsplus/circular_saw.lua +++ b/stairsplus/circular_saw.lua @@ -14,7 +14,7 @@ local formspec_style = stairsplus.resources.formspec_style function circular_saw.build_formspec(meta, inv) local inv_location = get_location_string(inv) return ([[ - size[12,10] + size[12,11] %s label[0,0;%s] list[%s;stairsplus:input;1.7,0;1,1;] @@ -25,8 +25,8 @@ function circular_saw.build_formspec(meta, inv) field[0.3,3.5;1,1;max_offered;%s:;%i] button[1,3.2;1.7,1;Set;%s] - list[%s;stairsplus:output;2.8,0;9,6;] - list[current_player;main;1.5,6.25;8,4;] + list[%s;stairsplus:output;2.8,0;7,7;] + list[current_player;main;1.5,7.25;8,4;] listring[%s;stairsplus:output] listring[current_player;main]