Skip to content

Commit 798e4ec

Browse files
SwissalpSOgelGames
authored andcommitted
Adds pipeworks support for the railguns (#22)
Author: Luke aka SwissalpS <Luke@SwissalpS.ws>
1 parent 6737757 commit 798e4ec

File tree

5 files changed

+55
-10
lines changed

5 files changed

+55
-10
lines changed

.luacheckrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ read_globals = {
88
table = {fields = {"copy", "getn"}},
99

1010
-- mod deps
11-
"technic", "default", "digilines",
11+
"default", "digilines", "pipeworks", "technic",
1212

1313
-- Minetest
1414
"minetest",

cannon.lua

+49-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
-- vi: noexpandtab
22

3+
--local has_digilines = minetest.get_modpath("digilines") and true
4+
local has_pipeworks = minetest.get_modpath("pipeworks") and true
5+
36
local cable_entry = "^technic_cable_connection_overlay.png"
47

8+
local groups_base = {
9+
cracky = 3,
10+
oddly_breakable_by_hand = 3,
11+
technic_machine = 1,
12+
technic_hv = 1
13+
}
14+
15+
local groups_rail = table.copy(groups_base)
16+
if has_pipeworks then
17+
groups_rail.tubedevice = 1
18+
groups_rail.tubedevice_receiver = 1
19+
end
20+
521
local register_spacecannon = function(def)
622

723
local entity_texture = "energycube_" .. def.color .. ".png"
@@ -112,11 +128,10 @@ local register_spacecannon = function(def)
112128
textures = def.textures
113129
end
114130

115-
minetest.register_node("spacecannon:cannon_" .. def.color, {
131+
local def_cannon = {
116132
description = def.name .. " (" .. def.desc .. ")",
117133
tiles = textures,
118-
119-
groups = {cracky=3,oddly_breakable_by_hand=3,technic_machine = 1, technic_hv = 1},
134+
groups = def.is_th and groups_base or groups_rail,
120135
drop = "spacecannon:cannon_" .. def.color,
121136
sounds = default.node_sound_glass_defaults(),
122137
paramtype2 = "facedir",
@@ -147,6 +162,9 @@ local register_spacecannon = function(def)
147162
after_place_node = function(pos, placer)
148163
local meta = minetest.get_meta(pos)
149164
meta:set_string("owner", placer:get_player_name() or "")
165+
if has_pipeworks then
166+
pipeworks.after_place(pos)
167+
end
150168
end,
151169

152170
on_construct = function(pos)
@@ -219,8 +237,35 @@ local register_spacecannon = function(def)
219237
if meta.inventory and meta.inventory.src and meta.inventory.src[1] then
220238
minetest.add_item(pos, ItemStack(meta.inventory.src[1]))
221239
end
240+
if has_pipeworks then
241+
pipeworks.after_dig(pos)
242+
end
222243
end
223-
})
244+
}
245+
246+
if has_pipeworks and not def.is_th then
247+
def_cannon.tube = {
248+
insert_object = function(pos, _, stack)
249+
local meta = minetest.get_meta(pos)
250+
local inv = meta:get_inventory()
251+
return inv:add_item("src", stack)
252+
end,
253+
can_insert = function(pos, _, stack)
254+
local meta = minetest.get_meta(pos)
255+
local inv = meta:get_inventory()
256+
stack = stack:peek_item(1)
257+
258+
return inv:room_for_item("src", stack)
259+
end,
260+
input_inventory = "src",
261+
connect_sides = {
262+
left = 1, back = 1, top = 1,
263+
right = 1, front = 1, bottom = nil
264+
}
265+
}
266+
end
267+
268+
minetest.register_node("spacecannon:cannon_" .. def.color, def_cannon)
224269

225270
technic.register_machine("HV", "spacecannon:cannon_" .. def.color, technic.receiver)
226271

@@ -233,8 +278,6 @@ local register_spacecannon = function(def)
233278
}
234279
})
235280

236-
237-
238281
end
239282

240283
register_spacecannon({

init.lua

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ dofile(MP.."/ammo.lua")
2121
dofile(MP.."/node_resilience.lua")
2222

2323
print("[OK] Spacecannon")
24+

mod.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
name = spacecannon
22
description = Adds five scifi/space cannons with various properties
33
depends = default, technic
4-
optional_depends = mesecons, digilines
4+
optional_depends = digilines, mesecons, pipeworks

util.lua

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ spacecannon.update_formspec = function(meta, is_th)
1515
"list[current_name;src;0.375,0.5;1,1;]" ..
1616
"list[current_player;main;0.375,4;8,4;]" ..
1717
"listring[]" ..
18+
"item_image[0.375,0.5;1,1;spacecannon:railgun_slug]" ..
1819
"label[1.75,1;Ammunition]"
1920

2021
-- Manual "fire" button
@@ -102,9 +103,9 @@ spacecannon.fire = function(pos, playername, color, speed, is_th, storage_requir
102103

103104
-- use ammo
104105
if not is_th then
105-
local src_stack = (meta:get_inventory()):get_list("src")[1]
106+
local src_stack = meta:get_inventory():get_list("src")[1]
106107
src_stack:take_item();
107-
(meta:get_inventory()):set_stack("src", 1, src_stack)
108+
meta:get_inventory():set_stack("src", 1, src_stack)
108109
end
109110

110111
minetest.sound_play("spacecannon_shoot", {

0 commit comments

Comments
 (0)