2013-07-17 21:34:35 +02:00
|
|
|
local sonic_screwdriver_max_charge = 15000
|
2013-10-30 18:45:32 +01:00
|
|
|
|
|
|
|
local S = technic.getter
|
|
|
|
|
2013-07-17 21:34:35 +02:00
|
|
|
technic.register_power_tool("technic:sonic_screwdriver", sonic_screwdriver_max_charge)
|
2013-02-21 22:01:49 +01:00
|
|
|
|
2015-01-10 22:42:49 +01:00
|
|
|
-- screwdriver handler code reused from minetest/minetest_game screwdriver @a9ac480
|
|
|
|
local ROTATE_FACE = 1
|
|
|
|
local ROTATE_AXIS = 2
|
|
|
|
|
|
|
|
local function nextrange(x, max)
|
|
|
|
x = x + 1
|
|
|
|
if x > max then
|
|
|
|
x = 0
|
|
|
|
end
|
|
|
|
return x
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Handles rotation
|
|
|
|
local function screwdriver_handler(itemstack, user, pointed_thing, mode)
|
|
|
|
if pointed_thing.type ~= "node" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local pos = pointed_thing.under
|
|
|
|
|
|
|
|
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
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- contrary to the default screwdriver, do not check for can_dig, to allow rotating machines with CLU's in them
|
|
|
|
-- this is consistent with the previous sonic screwdriver
|
|
|
|
|
|
|
|
local meta1 = minetest.deserialize(itemstack:get_metadata())
|
|
|
|
if not meta1 or not meta1.charge or meta1.charge < 100 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.sound_play("technic_sonic_screwdriver", {pos = pos, gain = 0.3, max_hear_distance = 10})
|
|
|
|
|
|
|
|
-- Set 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 == ROTATE_FACE then
|
|
|
|
rotationPart = axisdir * 4 + nextrange(rotation, 3)
|
|
|
|
elseif mode == ROTATE_AXIS then
|
|
|
|
rotationPart = nextrange(axisdir, 5) * 4
|
|
|
|
end
|
|
|
|
|
|
|
|
node.param2 = preservePart + rotationPart
|
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
|
2015-03-01 05:28:16 +01:00
|
|
|
if not technic.creative_mode then
|
2015-01-10 22:42:49 +01:00
|
|
|
meta1.charge = meta1.charge - 100
|
|
|
|
itemstack:set_metadata(minetest.serialize(meta1))
|
|
|
|
technic.set_RE_wear(itemstack, meta1.charge, sonic_screwdriver_max_charge)
|
|
|
|
end
|
|
|
|
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
|
2013-02-21 22:01:49 +01:00
|
|
|
minetest.register_tool("technic:sonic_screwdriver", {
|
2015-01-10 22:42:49 +01:00
|
|
|
description = S("Sonic Screwdriver (left-click rotates face, right-click rotates axis)"),
|
2013-10-19 04:22:39 +02:00
|
|
|
inventory_image = "technic_sonic_screwdriver.png",
|
Genericise handling of multiple meanings of wear
The tool workshop is meant to repair mechanical damage to tools, so
is at risk of `repairing' tools that use the wear bar to represent
something other than mechanical wear. It had special-case recognition
of the water and lava cans, which use the wear bar to represent how much
content they're carrying, and wouldn't repair them. But it didn't avoid
`repairing' RE chargeable items, which use the wear bar to represent
how much energy they have stored. It would modify the wear bar without
actually affecting the charge, so the wear bar would jump back to the
correct place when the next charging or discharging event occurred.
To genericise, introduce a new item property, "wear_represents", which
indicates how the wear bar is used for this item. Currently defined
values are "mechanical_wear" (straightforward damage to tools that
start out perfect), "technic_RE_charge" (electrical energy, canonically
represented in the meta rather than the wear bar), and "content_level"
(how full a container is). For backcompat, nil is interpreted as
"mechanical_wear". The tool workshop will only repair "mechanical_wear"
tools. As a bonus, set_RE_wear() will only set the wear bar for
"technic_RE_charge" items: this means developers will notice if they
forget to declare wear_represents, but also means that with no further
changes it's possible to have an RE chargeable item that uses its wear
bar to represent something else.
2014-04-28 11:44:07 +02:00
|
|
|
wear_represents = "technic_RE_charge",
|
2014-04-30 11:49:54 +02:00
|
|
|
on_refill = technic.refill_RE_charge,
|
2013-10-19 04:22:39 +02:00
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
2015-01-10 22:42:49 +01:00
|
|
|
screwdriver_handler(itemstack, user, pointed_thing, ROTATE_FACE)
|
|
|
|
return itemstack
|
|
|
|
end,
|
|
|
|
on_place = function(itemstack, user, pointed_thing)
|
|
|
|
screwdriver_handler(itemstack, user, pointed_thing, ROTATE_AXIS)
|
2013-10-19 04:22:39 +02:00
|
|
|
return itemstack
|
2015-01-10 22:42:49 +01:00
|
|
|
end,
|
2013-10-19 04:22:39 +02:00
|
|
|
})
|
2019-01-26 14:15:40 +01:00
|
|
|
|
2013-02-21 22:01:49 +01:00
|
|
|
minetest.register_craft({
|
|
|
|
output = "technic:sonic_screwdriver",
|
|
|
|
recipe = {
|
2014-07-07 22:48:38 +02:00
|
|
|
{"", "default:diamond", ""},
|
|
|
|
{"mesecons_materials:fiber", "technic:battery", "mesecons_materials:fiber"},
|
|
|
|
{"mesecons_materials:fiber", "moreores:mithril_ingot", "mesecons_materials:fiber"}
|
2013-12-11 02:14:39 +01:00
|
|
|
}
|
2013-02-21 22:01:49 +01:00
|
|
|
})
|
2013-12-11 02:14:39 +01:00
|
|
|
|