Screwdriver: release

This commit is contained in:
MoNTE48 2021-07-13 19:17:21 +03:00
parent 1ae7b4e07f
commit 5cfab01bd6
10 changed files with 256 additions and 3 deletions

View File

@ -141,6 +141,21 @@ local function register_armor_stand(name, def)
fixed = {-0.5, -0.5, -0.5, 0.5, 1.5, 0.5} fixed = {-0.5, -0.5, -0.5, 0.5, 1.5, 0.5}
}, },
groups = {}, 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) after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)

View File

@ -126,9 +126,10 @@ local function on_destruct(pos, large)
if large then if large then
local right = large == "right" local right = large == "right"
local param2 = minetest.get_node(pos).param2 local param2 = minetest.get_node(pos).param2
local neighbor_pos = neighbor[param2][right and 2 or 1] local nparam2 = neighbor[param2]
local pos2 = if not nparam2 then return end
{x = pos.x + neighbor_pos.x, y = pos.y, z = pos.z + neighbor_pos.z} 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 local name = minetest.get_node(pos2).name
if (right and name == "default:chest_left") if (right and name == "default:chest_left")
@ -148,6 +149,7 @@ local def = {
groups = {choppy = 2, oddly_breakable_by_hand = 2}, groups = {choppy = 2, oddly_breakable_by_hand = 2},
drop = "default:chest", drop = "default:chest",
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_rotate = false,
on_rightclick = on_rightclick, on_rightclick = on_rightclick,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,

View File

@ -28,6 +28,7 @@ function beds.register_bed(name, def)
type = "fixed", type = "fixed",
fixed = def.collisionbox fixed = def.collisionbox
}, },
on_rotate = false,
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
local under = pointed_thing.under local under = pointed_thing.under

View File

@ -120,6 +120,7 @@ minetest.register_node("itemframes:frame",{
sunlight_propagates = true, sunlight_propagates = true,
groups = {choppy = 2, dig_immediate = 2, attached_node = 1}, groups = {choppy = 2, dig_immediate = 2, attached_node = 1},
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_rotate = false,
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type == "node" then if pointed_thing.type == "node" then

View File

@ -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.

176
files/screwdriver/init.lua Normal file
View File

@ -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"}
}
})

View File

@ -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

View File

@ -0,0 +1,3 @@
# textdomain: screwdriver
Screwdriver=Отвёртка
(left-click rotates face, right-click rotates axis)=(клик левой кнопкой мыши вращает грань, клик правой кнопкой мыши вращает ось)

Binary file not shown.

After

Width:  |  Height:  |  Size: 233 B

View File

@ -386,6 +386,28 @@ minetest.register_node("signs:sign", {
} }
}, },
groups = {oddly_breakable_by_hand = 1, choppy = 3, attached_node = 1}, 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_place = place,
on_destruct = destruct, on_destruct = destruct,
@ -406,6 +428,7 @@ minetest.register_node("signs:wall_sign", {
walkable = false, walkable = false,
groups = {oddly_breakable_by_hand = 1, choppy = 3, groups = {oddly_breakable_by_hand = 1, choppy = 3,
not_in_creative_inventory = 1, attached_node = 1}, not_in_creative_inventory = 1, attached_node = 1},
on_rotate = false,
on_destruct = destruct, on_destruct = destruct,
on_punch = check_text, on_punch = check_text,