commit | author | age
|
be2f30
|
1 |
-- Tool workshop |
ee0765
|
2 |
-- This machine repairs tools. |
S |
3 |
|
|
4 |
minetest.register_alias("tool_workshop", "technic:tool_workshop") |
be2f30
|
5 |
|
S |
6 |
local S = technic.getter |
|
7 |
|
ee0765
|
8 |
minetest.register_craft({ |
S |
9 |
output = 'technic:tool_workshop', |
|
10 |
recipe = { |
e8a5a6
|
11 |
{'group:wood', 'default:diamond', 'group:wood'}, |
Z |
12 |
{'group:wood', 'technic:machine_casing', 'group:wood'}, |
68ea0a
|
13 |
{'default:stone', 'technic:mv_cable0', 'default:stone'}, |
ee0765
|
14 |
} |
S |
15 |
}) |
|
16 |
|
|
17 |
local workshop_formspec = |
|
18 |
"invsize[8,9;]".. |
|
19 |
"list[current_name;src;3,1;1,1;]".. |
7c4b70
|
20 |
"label[0,0;"..S("%s Tool Workshop"):format("MV").."]".. |
ee0765
|
21 |
"list[current_player;main;0,5;8,4;]" |
S |
22 |
|
|
23 |
minetest.register_node("technic:tool_workshop", { |
7c4b70
|
24 |
description = S("%s Tool Workshop"):format("MV"), |
ee0765
|
25 |
tiles = {"technic_workshop_top.png", "technic_machine_bottom.png", "technic_workshop_side.png", |
S |
26 |
"technic_workshop_side.png", "technic_workshop_side.png", "technic_workshop_side.png"}, |
|
27 |
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, |
|
28 |
sounds = default.node_sound_wood_defaults(), |
|
29 |
on_construct = function(pos) |
|
30 |
local meta = minetest.get_meta(pos) |
7c4b70
|
31 |
meta:set_string("infotext", S("%s Tool Workshop"):format("MV")) |
ee0765
|
32 |
meta:set_string("formspec", workshop_formspec) |
S |
33 |
local inv = meta:get_inventory() |
|
34 |
inv:set_size("src", 1) |
|
35 |
end, |
0809dd
|
36 |
can_dig = technic.machine_can_dig, |
S |
37 |
allow_metadata_inventory_put = technic.machine_inventory_put, |
|
38 |
allow_metadata_inventory_take = technic.machine_inventory_take, |
ee0765
|
39 |
}) |
S |
40 |
|
|
41 |
minetest.register_abm({ |
|
42 |
nodenames = {"technic:tool_workshop"}, |
|
43 |
interval = 1, |
|
44 |
chance = 1, |
|
45 |
action = function(pos, node, active_object_count, active_object_count_wider) |
|
46 |
local meta = minetest.get_meta(pos) |
|
47 |
local inv = meta:get_inventory() |
|
48 |
local eu_input = meta:get_int("MV_EU_input") |
7c4b70
|
49 |
local machine_name = S("%s Tool Workshop"):format("MV") |
ee0765
|
50 |
local machine_node = "technic:tool_workshop" |
S |
51 |
local demand = 5000 |
|
52 |
|
|
53 |
-- Setup meta data if it does not exist. |
|
54 |
if not eu_input then |
|
55 |
meta:set_int("MV_EU_demand", demand) |
|
56 |
meta:set_int("MV_EU_input", 0) |
|
57 |
return |
|
58 |
end |
|
59 |
|
|
60 |
-- Power off automatically if no longer connected to a switching station |
|
61 |
technic.switching_station_timeout_count(pos, "MV") |
|
62 |
|
99fd5d
|
63 |
local repairable = false |
d8437f
|
64 |
local srcstack = inv:get_stack("src", 1) |
ebc122
|
65 |
if not srcstack:is_empty() then |
99fd5d
|
66 |
local itemdef = minetest.registered_items[srcstack:get_name()] |
7c2f2d
|
67 |
if itemdef and |
799c1b
|
68 |
(not itemdef.wear_represents or |
S |
69 |
itemdef.wear_represents == "mechanical_wear") and |
7c2f2d
|
70 |
srcstack:get_wear() ~= 0 then |
99fd5d
|
71 |
repairable = true |
Z |
72 |
end |
|
73 |
end |
|
74 |
if not repairable then |
be2f30
|
75 |
meta:set_string("infotext", S("%s Idle"):format(machine_name)) |
ee0765
|
76 |
meta:set_int("MV_EU_demand", 0) |
S |
77 |
return |
|
78 |
end |
|
79 |
|
|
80 |
if eu_input < demand then |
be2f30
|
81 |
meta:set_string("infotext", S("%s Unpowered"):format(machine_name)) |
ee0765
|
82 |
elseif eu_input >= demand then |
be2f30
|
83 |
meta:set_string("infotext", S("%s Active"):format(machine_name)) |
ee0765
|
84 |
srcstack:add_wear(-1000) |
S |
85 |
inv:set_stack("src", 1, srcstack) |
|
86 |
end |
|
87 |
meta:set_int("MV_EU_demand", demand) |
|
88 |
end |
|
89 |
}) |
|
90 |
|
|
91 |
technic.register_machine("MV", "technic:tool_workshop", technic.receiver) |
|
92 |
|