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