From 5cfab01bd64f6258bc367fe9157e79d475616b84 Mon Sep 17 00:00:00 2001 From: MoNTE48 Date: Tue, 13 Jul 2021 19:17:21 +0300 Subject: [PATCH] Screwdriver: release --- files/3d_armor_stand/init.lua | 15 ++ files/default/chests.lua | 8 +- files/furniture/beds/api.lua | 1 + files/itemframes/init.lua | 1 + files/screwdriver/README.txt | 16 ++ files/screwdriver/init.lua | 176 +++++++++++++++++++++ files/screwdriver/license.txt | 16 ++ files/screwdriver/locale/screwdriver.ru.tr | 3 + files/screwdriver/textures/screwdriver.png | Bin 0 -> 233 bytes files/signs/init.lua | 23 +++ 10 files changed, 256 insertions(+), 3 deletions(-) create mode 100644 files/screwdriver/README.txt create mode 100644 files/screwdriver/init.lua create mode 100644 files/screwdriver/license.txt create mode 100644 files/screwdriver/locale/screwdriver.ru.tr create mode 100644 files/screwdriver/textures/screwdriver.png diff --git a/files/3d_armor_stand/init.lua b/files/3d_armor_stand/init.lua index 19eb0f0..c4165ab 100644 --- a/files/3d_armor_stand/init.lua +++ b/files/3d_armor_stand/init.lua @@ -141,6 +141,21 @@ local function register_armor_stand(name, def) fixed = {-0.5, -0.5, -0.5, 0.5, 1.5, 0.5} }, groups = {}, + on_rotate = function(pos, node, user, mode) + if not minetest.is_protected(pos, user:get_player_name()) + and mode == 1 then + node.param2 = (node.param2 % 8) + 1 + if node.param2 > 3 then + node.param2 = 0 + end + minetest.swap_node(pos, node) + update_entity(pos) + + return true + end + + return false + end, after_place_node = function(pos, placer) local meta = minetest.get_meta(pos) diff --git a/files/default/chests.lua b/files/default/chests.lua index b9d5f97..d0ee717 100644 --- a/files/default/chests.lua +++ b/files/default/chests.lua @@ -126,9 +126,10 @@ local function on_destruct(pos, large) if large then local right = large == "right" local param2 = minetest.get_node(pos).param2 - local neighbor_pos = neighbor[param2][right and 2 or 1] - local pos2 = - {x = pos.x + neighbor_pos.x, y = pos.y, z = pos.z + neighbor_pos.z} + local nparam2 = neighbor[param2] + if not nparam2 then return end + local nghbr_p = nparam2[right and 2 or 1] + local pos2 = {x = pos.x + nghbr_p.x, y = pos.y, z = pos.z + nghbr_p.z} local name = minetest.get_node(pos2).name if (right and name == "default:chest_left") @@ -148,6 +149,7 @@ local def = { groups = {choppy = 2, oddly_breakable_by_hand = 2}, drop = "default:chest", sounds = default.node_sound_wood_defaults(), + on_rotate = false, on_rightclick = on_rightclick, on_receive_fields = on_receive_fields, diff --git a/files/furniture/beds/api.lua b/files/furniture/beds/api.lua index 3fbc833..d83b30f 100644 --- a/files/furniture/beds/api.lua +++ b/files/furniture/beds/api.lua @@ -28,6 +28,7 @@ function beds.register_bed(name, def) type = "fixed", fixed = def.collisionbox }, + on_rotate = false, on_place = function(itemstack, placer, pointed_thing) local under = pointed_thing.under diff --git a/files/itemframes/init.lua b/files/itemframes/init.lua index ecb32f1..7c31e76 100644 --- a/files/itemframes/init.lua +++ b/files/itemframes/init.lua @@ -120,6 +120,7 @@ minetest.register_node("itemframes:frame",{ sunlight_propagates = true, groups = {choppy = 2, dig_immediate = 2, attached_node = 1}, sounds = default.node_sound_wood_defaults(), + on_rotate = false, on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type == "node" then diff --git a/files/screwdriver/README.txt b/files/screwdriver/README.txt new file mode 100644 index 0000000..cca6582 --- /dev/null +++ b/files/screwdriver/README.txt @@ -0,0 +1,16 @@ +MultiCraft Game mod: screwdriver +================================ +See license.txt for license information. + +License of source code +---------------------- +Originally by RealBadAngel, Maciej Kasatkin (LGPLv3.0+) +Various Minetest developers and contributors (LGPLv3.0+) +MultiCraft Development Team (LGPLv3.0+) + +License of textures +------------------- +Copyright (C) 2021 MultiCraft Development Team + +Graphics in this mod is NOT free and can be used only as part of the official MultiCraft build. +Allowed to be used in non-official builds ONLY for personal use. diff --git a/files/screwdriver/init.lua b/files/screwdriver/init.lua new file mode 100644 index 0000000..a43f6af --- /dev/null +++ b/files/screwdriver/init.lua @@ -0,0 +1,176 @@ +screwdriver = {} + +local translator = minetest.get_translator +local S = translator and translator("screwdriver") or intllib.make_gettext_pair() + +if translator and not minetest.is_singleplayer() then + local lang = minetest.settings:get("language") + if lang and lang == "ru" then + S = intllib.make_gettext_pair() + end +end + +screwdriver.ROTATE_FACE = 1 +screwdriver.ROTATE_AXIS = 2 +screwdriver.disallow = function() + return false +end +screwdriver.rotate_simple = function(_, _, _, mode) + if mode ~= screwdriver.ROTATE_FACE then + return false + end +end + +-- For attached wallmounted nodes: returns true if rotation is valid +-- simplified version of minetest:builtin/game/falling.lua#L148. +local function check_attached_node(pos, rotation) + local d = minetest.wallmounted_to_dir(rotation) + local p2 = vector.add(pos, d) + local n = minetest.get_node(p2).name + local def2 = minetest.registered_nodes[n] + if def2 and not def2.walkable then + return false + end + return true +end + +screwdriver.rotate = {} + +local facedir_tbl = { + [screwdriver.ROTATE_FACE] = { + [0] = 1, [1] = 2, [2] = 3, [3] = 0, + [4] = 5, [5] = 6, [6] = 7, [7] = 4, + [8] = 9, [9] = 10, [10] = 11, [11] = 8, + [12] = 13, [13] = 14, [14] = 15, [15] = 12, + [16] = 17, [17] = 18, [18] = 19, [19] = 16, + [20] = 21, [21] = 22, [22] = 23, [23] = 20, + }, + [screwdriver.ROTATE_AXIS] = { + [0] = 4, [1] = 4, [2] = 4, [3] = 4, + [4] = 8, [5] = 8, [6] = 8, [7] = 8, + [8] = 12, [9] = 12, [10] = 12, [11] = 12, + [12] = 16, [13] = 16, [14] = 16, [15] = 16, + [16] = 20, [17] = 20, [18] = 20, [19] = 20, + [20] = 0, [21] = 0, [22] = 0, [23] = 0, + }, +} + +screwdriver.rotate.facedir = function(_, node, mode) + local rotation = node.param2 % 32 -- get first 5 bits + local other = node.param2 - rotation + rotation = facedir_tbl[mode][rotation] or 0 + return rotation + other +end + +screwdriver.rotate.colorfacedir = screwdriver.rotate.facedir + +local wallmounted_tbl = { + [screwdriver.ROTATE_FACE] = {[2] = 5, [3] = 4, [4] = 2, [5] = 3, [1] = 0, [0] = 1}, + [screwdriver.ROTATE_AXIS] = {[2] = 5, [3] = 4, [4] = 2, [5] = 1, [1] = 0, [0] = 3} +} + +screwdriver.rotate.wallmounted = function(pos, node, mode) + local rotation = node.param2 % 8 -- get first 3 bits + local other = node.param2 - rotation + rotation = wallmounted_tbl[mode][rotation] or 0 + if minetest.get_item_group(node.name, "attached_node") ~= 0 then + -- find an acceptable orientation + for _ = 1, 5 do + if not check_attached_node(pos, rotation) then + rotation = wallmounted_tbl[mode][rotation] or 0 + else + break + end + end + end + return rotation + other +end + +screwdriver.rotate.colorwallmounted = screwdriver.rotate.wallmounted + +-- Handles rotation +screwdriver.handler = function(itemstack, user, pointed_thing, mode, uses) + if pointed_thing.type ~= "node" then + return + end + + local pos = pointed_thing.under + local player_name = user and user:get_player_name() or "" + + if minetest.is_protected(pos, player_name) then + minetest.record_protection_violation(pos, player_name) + return + end + + local node = minetest.get_node(pos) + local ndef = minetest.registered_nodes[node.name] + if not ndef then + return itemstack + end + -- can we rotate this paramtype2? + local fn = screwdriver.rotate[ndef.paramtype2] + if not fn and not ndef.on_rotate then + return itemstack + end + + local should_rotate = true + local new_param2 + if fn then + new_param2 = fn(pos, node, mode) + else + new_param2 = node.param2 + end + + -- Node provides a handler, so let the handler decide instead if the node can be rotated + if ndef.on_rotate then + -- Copy pos and node because callback can modify it + local result = ndef.on_rotate(vector.new(pos), + {name = node.name, param1 = node.param1, param2 = node.param2}, + user, mode, new_param2) + if result == false then -- Disallow rotation + return itemstack + elseif result == true then + should_rotate = false + end + elseif ndef.on_rotate == false then + return itemstack + elseif ndef.can_dig and not ndef.can_dig(pos, user) then + return itemstack + end + + if should_rotate and new_param2 ~= node.param2 then + node.param2 = new_param2 + minetest.swap_node(pos, node) + minetest.check_for_falling(pos) + end + + if not minetest.is_creative_enabled(player_name) then + itemstack:add_wear(65535 / ((uses or 200) - 1)) + end + + return itemstack +end + +-- Screwdriver +minetest.register_tool("screwdriver:screwdriver", { + description = S("Screwdriver") .. "\n" .. S("(left-click rotates face, right-click rotates axis)"), + inventory_image = "screwdriver.png", + wield_image = "screwdriver.png^[transformR90", + groups = {tool = 1, wieldview = 2}, + on_use = function(itemstack, user, pointed_thing) + screwdriver.handler(itemstack, user, pointed_thing, screwdriver.ROTATE_FACE, 200) + return itemstack + end, + on_place = function(itemstack, user, pointed_thing) + screwdriver.handler(itemstack, user, pointed_thing, screwdriver.ROTATE_AXIS, 200) + return itemstack + end, +}) + +minetest.register_craft({ + output = "screwdriver:screwdriver", + recipe = { + {"default:steel_ingot"}, + {"default:stick"} + } +}) diff --git a/files/screwdriver/license.txt b/files/screwdriver/license.txt new file mode 100644 index 0000000..d0dc876 --- /dev/null +++ b/files/screwdriver/license.txt @@ -0,0 +1,16 @@ +License of source code +---------------------- + +GNU Lesser General Public License, version 3.0 +Copyright (C) 2013-2016 RealBadAngel, Maciej Kasatkin +Copyright (C) 2013-2016 Various Minetest developers and contributors +Copyright (C) 2021 MultiCraft Development Team + +This program is free software; you can redistribute it and/or modify it under the terms +of the GNU Lesser General Public License as published by the Free Software Foundation; +either version 3.0 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; +without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU Lesser General Public License for more details: +https://www.gnu.org/licenses/lgpl-3.0.txt diff --git a/files/screwdriver/locale/screwdriver.ru.tr b/files/screwdriver/locale/screwdriver.ru.tr new file mode 100644 index 0000000..bbab330 --- /dev/null +++ b/files/screwdriver/locale/screwdriver.ru.tr @@ -0,0 +1,3 @@ +# textdomain: screwdriver +Screwdriver=Отвёртка +(left-click rotates face, right-click rotates axis)=(клик левой кнопкой мыши вращает грань, клик правой кнопкой мыши вращает ось) diff --git a/files/screwdriver/textures/screwdriver.png b/files/screwdriver/textures/screwdriver.png new file mode 100644 index 0000000000000000000000000000000000000000..95d9420e7e1462e808e198a17160cb1e1a84ec82 GIT binary patch literal 233 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I3?%1nZ+ru!7JRz^m~|NsAQ z+_>RoE|%#p-<6@EDbEug%^3q!!B`UH7tG-B>_!@pQ|amA7*cWT?WLQHOpYAQiEUR~ zUhYqPJk4Rx)B69bP0l+XkK#ua0E literal 0 HcmV?d00001 diff --git a/files/signs/init.lua b/files/signs/init.lua index cb1b859..2b6ce1d 100644 --- a/files/signs/init.lua +++ b/files/signs/init.lua @@ -386,6 +386,28 @@ minetest.register_node("signs:sign", { } }, groups = {oddly_breakable_by_hand = 1, choppy = 3, attached_node = 1}, + on_rotate = function(pos, node, user, mode) + local pn = user and user:get_player_name() or "" + if not minetest.is_protected(pos, pn) and mode == 1 then + node.param2 = (node.param2 % 8) + 1 + if node.param2 > 3 then + node.param2 = 0 + end + minetest.swap_node(pos, node) + + -- Checks can be skipped if there is no text + local meta = minetest.get_meta(pos) + local text = meta:get_string("sign_text") + if text and text ~= "" then + destruct(pos) + check_text(pos) + end + + return true + end + + return false + end, on_place = place, on_destruct = destruct, @@ -406,6 +428,7 @@ minetest.register_node("signs:wall_sign", { walkable = false, groups = {oddly_breakable_by_hand = 1, choppy = 3, not_in_creative_inventory = 1, attached_node = 1}, + on_rotate = false, on_destruct = destruct, on_punch = check_text,