Version MFF.
13
mods/screwdriver/README.txt
Normal file
@ -0,0 +1,13 @@
|
||||
Minetest Game mod: screwdriver
|
||||
==============================
|
||||
See license.txt for license information.
|
||||
|
||||
License of source code
|
||||
----------------------
|
||||
Originally by RealBadAngel, Maciej Kasatkin (LGPL 2.1)
|
||||
Various Minetest developers and contributors (LGPL 2.1)
|
||||
|
||||
License of media (textures)
|
||||
---------------------------
|
||||
Created by Gambit (CC BY-SA 3.0):
|
||||
screwdriver.png
|
226
mods/screwdriver/init.lua
Normal file → Executable file
@ -1,51 +1,4 @@
|
||||
|
||||
local mode_text = {
|
||||
{"Change rotation, Don't change axisdir."},
|
||||
{"Keep choosen face in front then rotate it."},
|
||||
{"Change axis dir, Reset rotation."},
|
||||
{"Bring top in front then rotate it."},
|
||||
}
|
||||
|
||||
local opposite_faces = {
|
||||
[0] = 5,
|
||||
[1] = 2,
|
||||
[2] = 1,
|
||||
[3] = 4,
|
||||
[4] = 3,
|
||||
[5] = 0,
|
||||
}
|
||||
|
||||
local function screwdriver_setmode(user,itemstack)
|
||||
local player_name = user:get_player_name()
|
||||
local item = itemstack:to_table()
|
||||
local mode = tonumber(itemstack:get_metadata())
|
||||
if not mode then
|
||||
minetest.chat_send_player(player_name, "Hold shift and use to change screwdriwer modes.")
|
||||
mode = 0
|
||||
end
|
||||
mode = mode + 1
|
||||
if mode == 5 then
|
||||
mode = 1
|
||||
end
|
||||
minetest.chat_send_player(player_name, "Screwdriver mode : "..mode.." - "..mode_text[mode][1] )
|
||||
itemstack:set_name("screwdriver:screwdriver"..mode)
|
||||
itemstack:set_metadata(mode)
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local function get_node_face(pointed_thing)
|
||||
local ax, ay, az = pointed_thing.above.x, pointed_thing.above.y, pointed_thing.above.z
|
||||
local ux, uy, uz = pointed_thing.under.x, pointed_thing.under.y, pointed_thing.under.z
|
||||
if ay > uy then return 0 -- Top
|
||||
elseif az > uz then return 1 -- Z+ side
|
||||
elseif az < uz then return 2 -- Z- side
|
||||
elseif ax > ux then return 3 -- X+ side
|
||||
elseif ax < ux then return 4 -- X- side
|
||||
elseif ay < uy then return 5 -- Bottom
|
||||
else
|
||||
error("pointed_thing.above and under are the same!")
|
||||
end
|
||||
end
|
||||
screwdriver = {}
|
||||
|
||||
local function nextrange(x, max)
|
||||
x = x + 1
|
||||
@ -55,78 +8,119 @@ local function nextrange(x, max)
|
||||
return x
|
||||
end
|
||||
|
||||
local function screwdriver_handler(itemstack, user, pointed_thing)
|
||||
screwdriver.ROTATE_FACE = 1
|
||||
screwdriver.ROTATE_AXIS = 2
|
||||
screwdriver.disallow = function(pos, node, user, mode, new_param2)
|
||||
return false
|
||||
end
|
||||
screwdriver.rotate_simple = function(pos, node, user, mode, new_param2)
|
||||
if mode ~= screwdriver.ROTATE_FACE then
|
||||
return false
|
||||
end
|
||||
end
|
||||
local USES = 200
|
||||
local USES_perfect = 10000
|
||||
|
||||
-- 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 keys = user:get_player_control()
|
||||
local player_name = user:get_player_name()
|
||||
local mode = tonumber(itemstack:get_metadata())
|
||||
if not mode or keys["sneak"] == true then
|
||||
return screwdriver_setmode(user, itemstack)
|
||||
end
|
||||
|
||||
if minetest.is_protected(pos, user:get_player_name()) then
|
||||
minetest.record_protection_violation(pos, user:get_player_name())
|
||||
return
|
||||
end
|
||||
|
||||
local node = minetest.get_node(pos)
|
||||
local ndef = minetest.registered_nodes[node.name]
|
||||
if not ndef or not ndef.paramtype2 == "facedir" or
|
||||
(ndef.drawtype == "nodebox" and
|
||||
not ndef.node_box.type == "fixed") or
|
||||
node.param2 == nil then
|
||||
-- verify node is facedir (expected to be rotatable)
|
||||
if not ndef or ndef.paramtype2 ~= "facedir" then
|
||||
return
|
||||
end
|
||||
-- Get ready to set the param2
|
||||
local n = node.param2
|
||||
local axisdir = math.floor(n / 4)
|
||||
local rotation = n - axisdir * 4
|
||||
if mode == 1 then
|
||||
n = axisdir * 4 + nextrange(rotation, 3)
|
||||
elseif mode == 2 then
|
||||
-- If you are pointing at the axisdir face or the
|
||||
-- opposite one then you can just rotate the node.
|
||||
-- Otherwise change the axisdir, avoiding the facing
|
||||
-- and opposite axes.
|
||||
local face = get_node_face(pointed_thing)
|
||||
if axisdir == face or axisdir == opposite_faces[face] then
|
||||
n = axisdir * 4 + nextrange(rotation, 3)
|
||||
else
|
||||
axisdir = nextrange(axisdir, 5)
|
||||
-- This is repeated because switching from the face
|
||||
-- can move to to the opposite and vice-versa
|
||||
if axisdir == face or axisdir == opposite_faces[face] then
|
||||
axisdir = nextrange(axisdir, 5)
|
||||
end
|
||||
if axisdir == face or axisdir == opposite_faces[face] then
|
||||
axisdir = nextrange(axisdir, 5)
|
||||
end
|
||||
n = axisdir * 4
|
||||
-- Compute param2
|
||||
local rotationPart = node.param2 % 32 -- get first 4 bits
|
||||
local preservePart = node.param2 - rotationPart
|
||||
local axisdir = math.floor(rotationPart / 4)
|
||||
local rotation = rotationPart - axisdir * 4
|
||||
if mode == screwdriver.ROTATE_FACE then
|
||||
rotationPart = axisdir * 4 + nextrange(rotation, 3)
|
||||
elseif mode == screwdriver.ROTATE_AXIS then
|
||||
rotationPart = nextrange(axisdir, 5) * 4
|
||||
end
|
||||
|
||||
local new_param2 = preservePart + rotationPart
|
||||
local should_rotate = true
|
||||
|
||||
if ndef and ndef.on_rotate then -- Node provides a handler, so let the handler decide instead if the node can be rotated
|
||||
-- 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
|
||||
elseif result == true then
|
||||
should_rotate = false
|
||||
end
|
||||
elseif mode == 3 then
|
||||
n = nextrange(axisdir, 5) * 4
|
||||
elseif mode == 4 then
|
||||
local face = get_node_face(pointed_thing)
|
||||
if axisdir == face then
|
||||
n = axisdir * 4 + nextrange(rotation, 3)
|
||||
else
|
||||
n = face * 4
|
||||
else
|
||||
if not ndef or not ndef.paramtype2 == "facedir" or
|
||||
ndef.on_rotate == false or
|
||||
(ndef.drawtype == "nodebox" and
|
||||
not ndef.node_box.type == "fixed") or
|
||||
node.param2 == nil then
|
||||
return
|
||||
end
|
||||
|
||||
if ndef.can_dig and not ndef.can_dig(pos, user) then
|
||||
return
|
||||
end
|
||||
end
|
||||
--print (dump(axisdir..", "..rotation))
|
||||
node.param2 = n
|
||||
minetest.swap_node(pos, node)
|
||||
local item_wear = tonumber(itemstack:get_wear())
|
||||
item_wear = item_wear + 327
|
||||
if item_wear > 65535 then
|
||||
itemstack:clear()
|
||||
return itemstack
|
||||
|
||||
if should_rotate then
|
||||
node.param2 = new_param2
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
itemstack:set_wear(item_wear)
|
||||
|
||||
if not minetest.setting_getbool("creative_mode") and minetest.registered_tools["screwdriver:screwdriver_perfect"] then
|
||||
itemstack:add_wear(65535 / (USES_perfect - 1))
|
||||
elseif not minetest.setting_getbool("creative_mode") then
|
||||
itemstack:add_wear(65535 / (USES - 1))
|
||||
end
|
||||
|
||||
return itemstack
|
||||
end
|
||||
|
||||
-- Screwdriver
|
||||
minetest.register_tool("screwdriver:screwdriver", {
|
||||
description = "Screwdriver (left-click rotates face, right-click rotates axis)",
|
||||
inventory_image = "screwdriver.png",
|
||||
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)
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
-- Perfect Screwdriver (en mithril à 10 000 utilisations)
|
||||
minetest.register_tool("screwdriver:screwdriver_perfect", {
|
||||
description = "Perfect Screwdriver (left-click rotates face, right-click rotates axis)",
|
||||
inventory_image = "screwdriver_perfect.png",
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
screwdriver.handler(itemstack, user, pointed_thing, screwdriver.ROTATE_FACE, 10000)
|
||||
return itemstack
|
||||
end,
|
||||
on_place = function(itemstack, user, pointed_thing)
|
||||
screwdriver.handler(itemstack, user, pointed_thing, screwdriver.ROTATE_AXIS, 10000)
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
output = "screwdriver:screwdriver",
|
||||
recipe = {
|
||||
@ -135,25 +129,15 @@ minetest.register_craft({
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_tool("screwdriver:screwdriver", {
|
||||
description = "Screwdriver",
|
||||
inventory_image = "screwdriver.png",
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
screwdriver_handler(itemstack, user, pointed_thing)
|
||||
return itemstack
|
||||
end,
|
||||
minetest.register_craft({
|
||||
output = "screwdriver:screwdriver_perfect",
|
||||
recipe = {
|
||||
{"default:mithril_ingot"},
|
||||
{"group:stick"}
|
||||
}
|
||||
})
|
||||
|
||||
for i = 1, 4 do
|
||||
minetest.register_tool("screwdriver:screwdriver"..i, {
|
||||
description = "Screwdriver in Mode "..i,
|
||||
inventory_image = "screwdriver.png^tool_mode"..i..".png",
|
||||
wield_image = "screwdriver.png",
|
||||
groups = {not_in_creative_inventory=1},
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
screwdriver_handler(itemstack, user, pointed_thing)
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
minetest.register_alias("screwdriver:screwdriver1", "screwdriver:screwdriver")
|
||||
minetest.register_alias("screwdriver:screwdriver2", "screwdriver:screwdriver")
|
||||
minetest.register_alias("screwdriver:screwdriver3", "screwdriver:screwdriver")
|
||||
minetest.register_alias("screwdriver:screwdriver4", "screwdriver:screwdriver")
|
||||
|
50
mods/screwdriver/license.txt
Normal file
@ -0,0 +1,50 @@
|
||||
License of source code
|
||||
----------------------
|
||||
|
||||
GNU Lesser General Public License, version 2.1
|
||||
Copyright (C) 2013-2016 RealBadAngel, Maciej Kasatkin
|
||||
Copyright (C) 2013-2016 Various Minetest developers and contributors
|
||||
|
||||
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 2.1 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/old-licenses/lgpl-2.1.html
|
||||
|
||||
|
||||
Licenses of media (textures)
|
||||
----------------------------
|
||||
|
||||
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
|
||||
Copyright (C) 2013-2016 Gambit
|
||||
|
||||
You are free to:
|
||||
Share — copy and redistribute the material in any medium or format.
|
||||
Adapt — remix, transform, and build upon the material for any purpose, even commercially.
|
||||
The licensor cannot revoke these freedoms as long as you follow the license terms.
|
||||
|
||||
Under the following terms:
|
||||
|
||||
Attribution — You must give appropriate credit, provide a link to the license, and
|
||||
indicate if changes were made. You may do so in any reasonable manner, but not in any way
|
||||
that suggests the licensor endorses you or your use.
|
||||
|
||||
ShareAlike — If you remix, transform, or build upon the material, you must distribute
|
||||
your contributions under the same license as the original.
|
||||
|
||||
No additional restrictions — You may not apply legal terms or technological measures that
|
||||
legally restrict others from doing anything the license permits.
|
||||
|
||||
Notices:
|
||||
|
||||
You do not have to comply with the license for elements of the material in the public
|
||||
domain or where your use is permitted by an applicable exception or limitation.
|
||||
No warranties are given. The license may not give you all of the permissions necessary
|
||||
for your intended use. For example, other rights such as publicity, privacy, or moral
|
||||
rights may limit how you use the material.
|
||||
|
||||
For more details:
|
||||
http://creativecommons.org/licenses/by-sa/3.0/
|
@ -1,18 +0,0 @@
|
||||
Minetest mod: screwdriver
|
||||
=========================
|
||||
|
||||
License of source code:
|
||||
-----------------------
|
||||
Copyright (C) 2013 RealBadAngel, Maciej Kasatkin <mk@realbadangel.pl>
|
||||
|
||||
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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
|
||||
License of media (textures and sounds)
|
||||
--------------------------------------
|
||||
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
|
||||
http://creativecommons.org/licenses/by-sa/3.0/
|
BIN
mods/screwdriver/textures/screwdriver.png
Normal file → Executable file
Before Width: | Height: | Size: 769 B After Width: | Height: | Size: 282 B |
BIN
mods/screwdriver/textures/screwdriver_perfect.png
Executable file
After Width: | Height: | Size: 276 B |
Before Width: | Height: | Size: 211 B |
Before Width: | Height: | Size: 360 B |
Before Width: | Height: | Size: 367 B |
Before Width: | Height: | Size: 268 B |