diff --git a/.luacheckrc b/.luacheckrc index 0a8ecb7..8591b3c 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -8,7 +8,7 @@ read_globals = { table = {fields = {"copy", "getn"}}, -- mod deps - "technic", "default", "digilines", + "default", "digilines", "pipeworks", "technic", -- Minetest "minetest", diff --git a/cannon.lua b/cannon.lua index 813956a..a35778e 100644 --- a/cannon.lua +++ b/cannon.lua @@ -1,7 +1,23 @@ -- vi: noexpandtab +--local has_digilines = minetest.get_modpath("digilines") and true +local has_pipeworks = minetest.get_modpath("pipeworks") and true + local cable_entry = "^technic_cable_connection_overlay.png" +local groups_base = { + cracky = 3, + oddly_breakable_by_hand = 3, + technic_machine = 1, + technic_hv = 1 +} + +local groups_rail = table.copy(groups_base) +if has_pipeworks then + groups_rail.tubedevice = 1 + groups_rail.tubedevice_receiver = 1 +end + local register_spacecannon = function(def) local entity_texture = "energycube_" .. def.color .. ".png" @@ -112,11 +128,10 @@ local register_spacecannon = function(def) textures = def.textures end - minetest.register_node("spacecannon:cannon_" .. def.color, { + local def_cannon = { description = def.name .. " (" .. def.desc .. ")", tiles = textures, - - groups = {cracky=3,oddly_breakable_by_hand=3,technic_machine = 1, technic_hv = 1}, + groups = def.is_th and groups_base or groups_rail, drop = "spacecannon:cannon_" .. def.color, sounds = default.node_sound_glass_defaults(), paramtype2 = "facedir", @@ -147,6 +162,9 @@ local register_spacecannon = function(def) after_place_node = function(pos, placer) local meta = minetest.get_meta(pos) meta:set_string("owner", placer:get_player_name() or "") + if has_pipeworks then + pipeworks.after_place(pos) + end end, on_construct = function(pos) @@ -219,8 +237,35 @@ local register_spacecannon = function(def) if meta.inventory and meta.inventory.src and meta.inventory.src[1] then minetest.add_item(pos, ItemStack(meta.inventory.src[1])) end + if has_pipeworks then + pipeworks.after_dig(pos) + end end - }) + } + + if has_pipeworks and not def.is_th then + def_cannon.tube = { + insert_object = function(pos, _, stack) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + return inv:add_item("src", stack) + end, + can_insert = function(pos, _, stack) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + stack = stack:peek_item(1) + + return inv:room_for_item("src", stack) + end, + input_inventory = "src", + connect_sides = { + left = 1, back = 1, top = 1, + right = 1, front = 1, bottom = nil + } + } + end + + minetest.register_node("spacecannon:cannon_" .. def.color, def_cannon) technic.register_machine("HV", "spacecannon:cannon_" .. def.color, technic.receiver) @@ -233,8 +278,6 @@ local register_spacecannon = function(def) } }) - - end register_spacecannon({ diff --git a/init.lua b/init.lua index 6212f62..033ee62 100644 --- a/init.lua +++ b/init.lua @@ -21,3 +21,4 @@ dofile(MP.."/ammo.lua") dofile(MP.."/node_resilience.lua") print("[OK] Spacecannon") + diff --git a/mod.conf b/mod.conf index f0ed2cd..aabb79c 100644 --- a/mod.conf +++ b/mod.conf @@ -1,4 +1,4 @@ name = spacecannon description = Adds five scifi/space cannons with various properties depends = default, technic -optional_depends = mesecons, digilines +optional_depends = digilines, mesecons, pipeworks diff --git a/util.lua b/util.lua index 283fb82..f39a8f7 100644 --- a/util.lua +++ b/util.lua @@ -15,6 +15,7 @@ spacecannon.update_formspec = function(meta, is_th) "list[current_name;src;0.375,0.5;1,1;]" .. "list[current_player;main;0.375,4;8,4;]" .. "listring[]" .. + "item_image[0.375,0.5;1,1;spacecannon:railgun_slug]" .. "label[1.75,1;Ammunition]" -- Manual "fire" button @@ -102,9 +103,9 @@ spacecannon.fire = function(pos, playername, color, speed, is_th, storage_requir -- use ammo if not is_th then - local src_stack = (meta:get_inventory()):get_list("src")[1] + local src_stack = meta:get_inventory():get_list("src")[1] src_stack:take_item(); - (meta:get_inventory()):set_stack("src", 1, src_stack) + meta:get_inventory():set_stack("src", 1, src_stack) end minetest.sound_play("spacecannon_shoot", {