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 = { |
5e4a87
|
11 |
{'group:wood', 'default:diamond', 'group:wood'}, |
Z |
12 |
{'mesecons_pistons:piston_sticky_off', 'technic:machine_casing', 'technic:carbon_cloth'}, |
|
13 |
{'default:obsidian', 'technic:mv_cable0', 'default:obsidian'}, |
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 |
|
563a4c
|
23 |
local run = function(pos, node) |
N |
24 |
local meta = minetest.get_meta(pos) |
|
25 |
local inv = meta:get_inventory() |
|
26 |
local eu_input = meta:get_int("MV_EU_input") |
|
27 |
local machine_name = S("%s Tool Workshop"):format("MV") |
|
28 |
local machine_node = "technic:tool_workshop" |
|
29 |
local demand = 5000 |
|
30 |
|
|
31 |
-- Setup meta data if it does not exist. |
|
32 |
if not eu_input then |
|
33 |
meta:set_int("MV_EU_demand", demand) |
|
34 |
meta:set_int("MV_EU_input", 0) |
|
35 |
return |
|
36 |
end |
|
37 |
|
|
38 |
local repairable = false |
|
39 |
local srcstack = inv:get_stack("src", 1) |
|
40 |
if not srcstack:is_empty() then |
|
41 |
local itemdef = minetest.registered_items[srcstack:get_name()] |
|
42 |
if itemdef and |
|
43 |
(not itemdef.wear_represents or |
|
44 |
itemdef.wear_represents == "mechanical_wear") and |
|
45 |
srcstack:get_wear() ~= 0 then |
|
46 |
repairable = true |
|
47 |
end |
|
48 |
end |
|
49 |
if not repairable then |
|
50 |
meta:set_string("infotext", S("%s Idle"):format(machine_name)) |
|
51 |
meta:set_int("MV_EU_demand", 0) |
|
52 |
return |
|
53 |
end |
|
54 |
|
|
55 |
if eu_input < demand then |
|
56 |
meta:set_string("infotext", S("%s Unpowered"):format(machine_name)) |
|
57 |
elseif eu_input >= demand then |
|
58 |
meta:set_string("infotext", S("%s Active"):format(machine_name)) |
|
59 |
srcstack:add_wear(-1000) |
|
60 |
inv:set_stack("src", 1, srcstack) |
|
61 |
end |
|
62 |
meta:set_int("MV_EU_demand", demand) |
|
63 |
end |
|
64 |
|
ee0765
|
65 |
minetest.register_node("technic:tool_workshop", { |
7c4b70
|
66 |
description = S("%s Tool Workshop"):format("MV"), |
ee0765
|
67 |
tiles = {"technic_workshop_top.png", "technic_machine_bottom.png", "technic_workshop_side.png", |
S |
68 |
"technic_workshop_side.png", "technic_workshop_side.png", "technic_workshop_side.png"}, |
563a4c
|
69 |
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_machine=1}, |
ee0765
|
70 |
sounds = default.node_sound_wood_defaults(), |
S |
71 |
on_construct = function(pos) |
|
72 |
local meta = minetest.get_meta(pos) |
7c4b70
|
73 |
meta:set_string("infotext", S("%s Tool Workshop"):format("MV")) |
ee0765
|
74 |
meta:set_string("formspec", workshop_formspec) |
S |
75 |
local inv = meta:get_inventory() |
|
76 |
inv:set_size("src", 1) |
|
77 |
end, |
0809dd
|
78 |
can_dig = technic.machine_can_dig, |
S |
79 |
allow_metadata_inventory_put = technic.machine_inventory_put, |
|
80 |
allow_metadata_inventory_take = technic.machine_inventory_take, |
563a4c
|
81 |
technic_run = run, |
ee0765
|
82 |
}) |
S |
83 |
|
|
84 |
technic.register_machine("MV", "technic:tool_workshop", technic.receiver) |
|
85 |
|