commit | author | age
|
ee0765
|
1 |
local sonic_screwdriver_max_charge = 15000 |
be2f30
|
2 |
|
S |
3 |
local S = technic.getter |
|
4 |
|
ee0765
|
5 |
technic.register_power_tool("technic:sonic_screwdriver", sonic_screwdriver_max_charge) |
e23f87
|
6 |
|
fe4372
|
7 |
-- screwdriver handler code reused from minetest/minetest_game screwdriver @a9ac480 |
T |
8 |
local ROTATE_FACE = 1 |
|
9 |
local ROTATE_AXIS = 2 |
|
10 |
|
|
11 |
local function nextrange(x, max) |
|
12 |
x = x + 1 |
|
13 |
if x > max then |
|
14 |
x = 0 |
|
15 |
end |
|
16 |
return x |
|
17 |
end |
|
18 |
|
|
19 |
-- Handles rotation |
|
20 |
local function screwdriver_handler(itemstack, user, pointed_thing, mode) |
|
21 |
if pointed_thing.type ~= "node" then |
|
22 |
return |
|
23 |
end |
|
24 |
|
|
25 |
local pos = pointed_thing.under |
|
26 |
|
|
27 |
if minetest.is_protected(pos, user:get_player_name()) then |
|
28 |
minetest.record_protection_violation(pos, user:get_player_name()) |
|
29 |
return |
|
30 |
end |
|
31 |
|
|
32 |
local node = minetest.get_node(pos) |
|
33 |
local ndef = minetest.registered_nodes[node.name] |
|
34 |
if not ndef or not ndef.paramtype2 == "facedir" or |
|
35 |
(ndef.drawtype == "nodebox" and |
|
36 |
not ndef.node_box.type == "fixed") or |
|
37 |
node.param2 == nil then |
|
38 |
return |
|
39 |
end |
|
40 |
|
|
41 |
-- contrary to the default screwdriver, do not check for can_dig, to allow rotating machines with CLU's in them |
|
42 |
-- this is consistent with the previous sonic screwdriver |
|
43 |
|
|
44 |
local meta1 = minetest.deserialize(itemstack:get_metadata()) |
|
45 |
if not meta1 or not meta1.charge or meta1.charge < 100 then |
|
46 |
return |
|
47 |
end |
|
48 |
|
|
49 |
minetest.sound_play("technic_sonic_screwdriver", {pos = pos, gain = 0.3, max_hear_distance = 10}) |
|
50 |
|
|
51 |
-- Set param2 |
|
52 |
local rotationPart = node.param2 % 32 -- get first 4 bits |
|
53 |
local preservePart = node.param2 - rotationPart |
|
54 |
|
|
55 |
local axisdir = math.floor(rotationPart / 4) |
|
56 |
local rotation = rotationPart - axisdir * 4 |
|
57 |
if mode == ROTATE_FACE then |
|
58 |
rotationPart = axisdir * 4 + nextrange(rotation, 3) |
|
59 |
elseif mode == ROTATE_AXIS then |
|
60 |
rotationPart = nextrange(axisdir, 5) * 4 |
|
61 |
end |
|
62 |
|
|
63 |
node.param2 = preservePart + rotationPart |
|
64 |
minetest.swap_node(pos, node) |
|
65 |
|
b8c902
|
66 |
if not technic.creative_mode then |
fe4372
|
67 |
meta1.charge = meta1.charge - 100 |
T |
68 |
itemstack:set_metadata(minetest.serialize(meta1)) |
|
69 |
technic.set_RE_wear(itemstack, meta1.charge, sonic_screwdriver_max_charge) |
|
70 |
end |
|
71 |
|
|
72 |
return itemstack |
|
73 |
end |
|
74 |
|
e23f87
|
75 |
minetest.register_tool("technic:sonic_screwdriver", { |
fe4372
|
76 |
description = S("Sonic Screwdriver (left-click rotates face, right-click rotates axis)"), |
eac484
|
77 |
inventory_image = "technic_sonic_screwdriver.png", |
99fd5d
|
78 |
wear_represents = "technic_RE_charge", |
00d7c9
|
79 |
on_refill = technic.refill_RE_charge, |
eac484
|
80 |
on_use = function(itemstack, user, pointed_thing) |
fe4372
|
81 |
screwdriver_handler(itemstack, user, pointed_thing, ROTATE_FACE) |
eac484
|
82 |
return itemstack |
fe4372
|
83 |
end, |
T |
84 |
on_place = function(itemstack, user, pointed_thing) |
|
85 |
screwdriver_handler(itemstack, user, pointed_thing, ROTATE_AXIS) |
|
86 |
return itemstack |
|
87 |
end, |
eac484
|
88 |
}) |
4f78a6
|
89 |
|
e23f87
|
90 |
minetest.register_craft({ |
R |
91 |
output = "technic:sonic_screwdriver", |
|
92 |
recipe = { |
5e4a87
|
93 |
{"", "default:diamond", ""}, |
Z |
94 |
{"mesecons_materials:fiber", "technic:battery", "mesecons_materials:fiber"}, |
|
95 |
{"mesecons_materials:fiber", "moreores:mithril_ingot", "mesecons_materials:fiber"} |
f3d8b4
|
96 |
} |
e23f87
|
97 |
}) |
f3d8b4
|
98 |
|