commit | author | age
|
82cba9
|
1 |
|
354ee6
|
2 |
local S = technic.getter |
S |
3 |
|
14b30b
|
4 |
local function deploy_node(inv, slot_name, pos, node, machine_node) |
S |
5 |
if node.name ~= "air" then |
|
6 |
if node.name == "ignore" or |
|
7 |
node.name == "default:lava_source" or |
|
8 |
node.name == "default:lava_flowing" or |
|
9 |
node.name == "default:water_source" or |
|
10 |
node.name == "default:water_flowing" then |
|
11 |
return |
|
12 |
end |
|
13 |
local drops = minetest.get_node_drops(node.name, "") |
|
14 |
local remove_to = false |
|
15 |
for i, item in ipairs(drops) do |
|
16 |
if not inv:room_for_item(slot_name, item) then |
|
17 |
remove_to = i - 1 |
|
18 |
break |
|
19 |
end |
|
20 |
inv:add_item(slot_name, item) |
|
21 |
end |
|
22 |
if remove_to then |
|
23 |
for i = 1, remove_to do |
186f9b
|
24 |
inv:remove_item(slot_name, drops[i]) |
14b30b
|
25 |
end |
S |
26 |
else |
|
27 |
minetest.remove_node(pos) |
|
28 |
end |
|
29 |
return |
|
30 |
end |
|
31 |
if not inv:is_empty(slot_name) then |
|
32 |
local stack = inv:get_list(slot_name)[1] |
|
33 |
local def = stack:get_definition() |
|
34 |
if def.type == "node" then |
|
35 |
minetest.set_node(pos, { |
|
36 |
name = stack:get_name(), |
|
37 |
param2 = machine_node.param2 |
|
38 |
}) |
|
39 |
stack:take_item() |
|
40 |
inv:set_stack(slot_name, 1, stack) |
|
41 |
elseif def.type == "craft" then |
|
42 |
if def.on_place then |
|
43 |
-- Use pcall to avoid nil placer errors. |
|
44 |
-- TODO: Do without pcall. |
|
45 |
local ok, stk = pcall(def.on_place, stack, nil, { |
018b24
|
46 |
-- Fake pointed_thing |
VE |
47 |
type = "node", |
14b30b
|
48 |
above = pos, |
S |
49 |
under = {x=pos.x, y=pos.y-1, z=pos.z}, |
018b24
|
50 |
}) |
14b30b
|
51 |
if ok then |
S |
52 |
inv:set_stack(slot_name, 1, stk or stack) |
|
53 |
return |
018b24
|
54 |
end |
VE |
55 |
end |
14b30b
|
56 |
minetest.item_place_object(stack, nil, { |
S |
57 |
-- Fake pointed_thing |
|
58 |
type = "node", |
|
59 |
above = pos, |
|
60 |
under = pos, |
|
61 |
}) |
|
62 |
inv:set_stack(slot_name, 1, nil) |
018b24
|
63 |
end |
VE |
64 |
end |
|
65 |
end |
|
66 |
|
82cba9
|
67 |
minetest.register_craft({ |
R |
68 |
type = "shapeless", |
|
69 |
output = 'technic:constructor_mk1_off 1', |
|
70 |
recipe = {'technic:nodebreaker_off', 'technic:deployer_off'}, |
|
71 |
|
|
72 |
}) |
|
73 |
minetest.register_craft({ |
|
74 |
type = "shapeless", |
|
75 |
output = 'technic:constructor_mk2_off 1', |
|
76 |
recipe = {'technic:constructor_mk1_off', 'technic:constructor_mk1_off'}, |
|
77 |
|
|
78 |
}) |
|
79 |
|
|
80 |
minetest.register_craft({ |
|
81 |
type = "shapeless", |
|
82 |
output = 'technic:constructor_mk3_off 1', |
|
83 |
recipe = {'technic:constructor_mk2_off', 'technic:constructor_mk2_off'}, |
|
84 |
|
|
85 |
}) |
|
86 |
|
14b30b
|
87 |
local function make_on(mark, length) |
S |
88 |
return function(pos, node) |
ee0765
|
89 |
local meta = minetest.get_meta(pos) |
82cba9
|
90 |
local inv = meta:get_inventory() |
14b30b
|
91 |
local dir = vector.new() |
S |
92 |
if node.param2 == 3 then dir.x = 1 end |
|
93 |
if node.param2 == 2 then dir.z = 1 end |
|
94 |
if node.param2 == 1 then dir.x = -1 end |
|
95 |
if node.param2 == 0 then dir.z = -1 end |
82cba9
|
96 |
|
14b30b
|
97 |
local place_pos = vector.new(pos) |
82cba9
|
98 |
|
14b30b
|
99 |
if node.name == "technic:constructor_mk"..mark.."_off" then |
S |
100 |
technic.swap_node(pos, "technic:constructor_mk"..mark.."_on") |
|
101 |
nodeupdate(pos) |
|
102 |
for i = 1, length do |
|
103 |
place_pos = vector.add(place_pos, dir) |
|
104 |
local place_node = minetest.get_node(place_pos) |
|
105 |
deploy_node(inv, "slot"..i, place_pos, place_node, node) |
|
106 |
end |
|
107 |
end |
82cba9
|
108 |
end |
R |
109 |
end |
|
110 |
|
14b30b
|
111 |
local function make_off(mark) |
S |
112 |
return function(pos, node) |
|
113 |
if node.name == "technic:constructor_mk"..mark.."_on" then |
|
114 |
technic.swap_node(pos,"technic:constructor_mk"..mark.."_off") |
|
115 |
nodeupdate(pos) |
|
116 |
end |
82cba9
|
117 |
end |
R |
118 |
end |
|
119 |
|
|
120 |
|
14b30b
|
121 |
local function make_constructor(mark, length) |
S |
122 |
minetest.register_node("technic:constructor_mk"..mark.."_off", { |
|
123 |
description = S("Constructor Mk%d"):format(mark), |
|
124 |
tiles = {"technic_constructor_mk"..mark.."_top_off.png", |
|
125 |
"technic_constructor_mk"..mark.."_bottom_off.png", |
|
126 |
"technic_constructor_mk"..mark.."_side2_off.png", |
|
127 |
"technic_constructor_mk"..mark.."_side1_off.png", |
|
128 |
"technic_constructor_back.png", |
|
129 |
"technic_constructor_front_off.png"}, |
|
130 |
paramtype2 = "facedir", |
|
131 |
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, mesecon = 2}, |
|
132 |
mesecons = {effector = {action_on = make_on(mark, length)}}, |
|
133 |
sounds = default.node_sound_stone_defaults(), |
|
134 |
on_construct = function(pos) |
|
135 |
local meta = minetest.get_meta(pos) |
|
136 |
local formspec = "size[8,9;]".. |
|
137 |
"label[0,0;"..S("Constructor Mk%d"):format(mark).."]".. |
|
138 |
"list[current_player;main;0,5;8,4;]" |
|
139 |
for i = 1, length do |
|
140 |
formspec = formspec |
|
141 |
.."label[5,"..(i - 1)..";"..S("Slot %d"):format(i).."]" |
|
142 |
.."list[current_name;slot"..i |
|
143 |
..";6,"..(i - 1)..";1,1;]" |
|
144 |
end |
|
145 |
meta:set_string("formspec", formspec) |
|
146 |
meta:set_string("infotext", S("Constructor Mk%d"):format(mark)) |
|
147 |
local inv = meta:get_inventory() |
|
148 |
for i = 1, length do |
|
149 |
inv:set_size("slot"..i, 1) |
|
150 |
end |
|
151 |
end, |
|
152 |
can_dig = function(pos, player) |
|
153 |
local meta = minetest.get_meta(pos) |
|
154 |
local inv = meta:get_inventory() |
|
155 |
for i = 1, length do |
|
156 |
if not inv:is_empty("slot"..i) then |
|
157 |
return false |
|
158 |
end |
|
159 |
end |
|
160 |
return true |
|
161 |
end, |
|
162 |
allow_metadata_inventory_put = technic.machine_inventory_put, |
|
163 |
allow_metadata_inventory_take = technic.machine_inventory_take, |
|
164 |
allow_metadata_inventory_move = technic.machine_inventory_move, |
|
165 |
}) |
82cba9
|
166 |
|
14b30b
|
167 |
minetest.register_node("technic:constructor_mk"..mark.."_on", { |
S |
168 |
tiles = {"technic_constructor_mk"..mark.."_top_on.png", |
|
169 |
"technic_constructor_mk"..mark.."_bottom_on.png", |
|
170 |
"technic_constructor_mk"..mark.."_side2_on.png", |
|
171 |
"technic_constructor_mk"..mark.."_side1_on.png", |
|
172 |
"technic_constructor_back.png", |
|
173 |
"technic_constructor_front_on.png"}, |
|
174 |
paramtype2 = "facedir", |
|
175 |
drop = "technic:constructor_mk"..mark.."_off", |
|
176 |
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, |
|
177 |
mesecon=2, not_in_creative_inventory=1}, |
|
178 |
mesecons= {effector = {action_off = make_off(mark)}}, |
|
179 |
sounds = default.node_sound_stone_defaults(), |
|
180 |
allow_metadata_inventory_put = technic.machine_inventory_put, |
|
181 |
allow_metadata_inventory_take = technic.machine_inventory_take, |
|
182 |
allow_metadata_inventory_move = technic.machine_inventory_move, |
|
183 |
}) |
82cba9
|
184 |
end |
R |
185 |
|
14b30b
|
186 |
make_constructor(1, 1) |
S |
187 |
make_constructor(2, 2) |
|
188 |
make_constructor(3, 4) |
82cba9
|
189 |
|