mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2024-11-18 00:08:25 +01:00
Updated screwdriver (from minetest_game)
This commit is contained in:
parent
deae3cf088
commit
212677382b
@ -6,8 +6,18 @@ local function nextrange(x, max)
|
|||||||
return x
|
return x
|
||||||
end
|
end
|
||||||
|
|
||||||
local ROTATE_FACE = 1
|
screwdriver = {}
|
||||||
local ROTATE_AXIS = 2
|
|
||||||
|
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 = 200
|
||||||
local USES_perfect = 10000
|
local USES_perfect = 10000
|
||||||
|
|
||||||
@ -26,6 +36,31 @@ local function screwdriver_handler(itemstack, user, pointed_thing, mode)
|
|||||||
|
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local ndef = minetest.registered_nodes[node.name]
|
local ndef = minetest.registered_nodes[node.name]
|
||||||
|
-- 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
|
||||||
|
else
|
||||||
if not ndef or not ndef.paramtype2 == "facedir" or
|
if not ndef or not ndef.paramtype2 == "facedir" or
|
||||||
(ndef.drawtype == "nodebox" and
|
(ndef.drawtype == "nodebox" and
|
||||||
not ndef.node_box.type == "fixed") or
|
not ndef.node_box.type == "fixed") or
|
||||||
@ -36,19 +71,12 @@ local function screwdriver_handler(itemstack, user, pointed_thing, mode)
|
|||||||
if ndef.can_dig and not ndef.can_dig(pos, user) then
|
if ndef.can_dig and not ndef.can_dig(pos, user) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set param2
|
|
||||||
local n = node.param2
|
|
||||||
local axisdir = math.floor(n / 4)
|
|
||||||
local rotation = n - axisdir * 4
|
|
||||||
if mode == ROTATE_FACE then
|
|
||||||
n = axisdir * 4 + nextrange(rotation, 3)
|
|
||||||
elseif mode == ROTATE_AXIS then
|
|
||||||
n = nextrange(axisdir, 5) * 4
|
|
||||||
end
|
end
|
||||||
|
|
||||||
node.param2 = n
|
if should_rotate then
|
||||||
|
node.param2 = new_param2
|
||||||
minetest.swap_node(pos, node)
|
minetest.swap_node(pos, node)
|
||||||
|
end
|
||||||
|
|
||||||
if not minetest.setting_getbool("creative_mode") and minetest.registered_tools["screwdriver:screwdriver_perfect"] then
|
if not minetest.setting_getbool("creative_mode") and minetest.registered_tools["screwdriver:screwdriver_perfect"] then
|
||||||
itemstack:add_wear(65535 / (USES_perfect - 1))
|
itemstack:add_wear(65535 / (USES_perfect - 1))
|
||||||
@ -64,11 +92,11 @@ minetest.register_tool("screwdriver:screwdriver", {
|
|||||||
description = "Screwdriver (left-click rotates face, right-click rotates axis)",
|
description = "Screwdriver (left-click rotates face, right-click rotates axis)",
|
||||||
inventory_image = "screwdriver.png",
|
inventory_image = "screwdriver.png",
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
screwdriver_handler(itemstack, user, pointed_thing, ROTATE_FACE)
|
screwdriver_handler(itemstack, user, pointed_thing, screwdriver.ROTATE_FACE)
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end,
|
||||||
on_place = function(itemstack, user, pointed_thing)
|
on_place = function(itemstack, user, pointed_thing)
|
||||||
screwdriver_handler(itemstack, user, pointed_thing, ROTATE_AXIS)
|
screwdriver_handler(itemstack, user, pointed_thing, screwdriver.ROTATE_AXIS)
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
Minetest mod: screwdriver
|
Minetest mod: screwdriver
|
||||||
Edited by TenPlus1 on 2nd Sep 2014
|
=========================
|
||||||
==================================
|
|
||||||
|
|
||||||
License of source code:
|
License of source code:
|
||||||
-----------------------
|
-----------------------
|
||||||
@ -17,3 +16,6 @@ License of media (textures and sounds)
|
|||||||
--------------------------------------
|
--------------------------------------
|
||||||
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
|
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
|
||||||
http://creativecommons.org/licenses/by-sa/3.0/
|
http://creativecommons.org/licenses/by-sa/3.0/
|
||||||
|
|
||||||
|
Created by Gambit (WTFPL):
|
||||||
|
screwdriver.png
|
Loading…
Reference in New Issue
Block a user