diff --git a/functions.lua b/functions.lua index 818c484..edf4f08 100644 --- a/functions.lua +++ b/functions.lua @@ -73,6 +73,7 @@ cannons.allow_metadata_inventory_put = function(pos, listname, index, stack, pla end end + cannons.allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) local meta = minetest.get_meta(pos) @@ -91,15 +92,30 @@ cannons.allow_metadata_inventory_move = function(pos, from_list, from_index, to_ return 0 end end + +cannons.can_dig = function(pos,player) + local meta = minetest.get_meta(pos); + local inv = meta:get_inventory() + if not inv:is_empty("gunpowder") then + return false + elseif not inv:is_empty("muni") then + return false + else + return true + end + end + cannons.formspec = "size[8,9]".. "list[current_name;muni;0,1;1,1;] label[0,0.5;Muni:]".. "list[current_name;gunpowder;0,3;1,1;] label[0,2.5;Gunpowder:]".. "list[current_player;main;0,5;8,4;]" + cannons.disabled_formspec = "size[8,9]".. "label[2,0.5;Cannon is Disabled. Place it on a cannonstand to activate it]".. "list[current_player;main;0,5;8,4;]" + cannons.on_construct = function(pos) local node = minetest.get_node({x = pos.x ,y = pos.y-1, z = pos.z}) if minetest.registered_nodes[node.name].groups.cannonstand then @@ -115,6 +131,7 @@ cannons.on_construct = function(pos) meta:set_string("infotext", "Cannon is out of order") end end + cannons.on_construct_locks = function(pos) local node = minetest.get_node({x = pos.x ,y = pos.y-1, z = pos.z}) if minetest.registered_nodes[node.name].groups.cannonstand then @@ -132,37 +149,7 @@ cannons.on_construct_locks = function(pos) meta:set_string("infotext", "Cannon is out of order") end end -cannons.nodebox = { - type = "fixed", - fixed = { - {-0.2, 0.2, -0.7, 0.2, -0.2, 0.9}, -- barrle -- - {0.53, -0.1, 0.1, -0.53, 0.1, -0.1}, -- plinth -- - - -- side , top hight , depth , side , bottom, side, - - } - } -cannons.stand_nodebox = { - type = "fixed", - fixed = { - {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, -- bottom -- - {-0.5, -0.5, -0.5, -0.35, 1.0, 0.5}, -- side left -- - {0.35, -0.5, -0.5, 0.5, 1.0, 0.5}, -- side right -- - {0.35, -0.5, -0.2, 0.5, 1.2, 0.5}, -- side right -- - {-0.5, -0.5, -0.2, -0.35, 1.2, 0.5}, -- side left -- - - -- side , top , side , side , bottom, side, - - }, - } - cannons.rules = - {{x = 1, y = 0, z = 0}, - {x =-1, y = 0, z = 0}, - {x = 0, y = 0, z = 1}, - {x = 0, y = 0, z =-1}} -function cannons.meseconsfire(pos,node) - cannons.fire(pos,node) -end + function cannons.nodehitparticles(pos,node) if type(minetest.registered_nodes[node.name]) == "table" and type(minetest.registered_nodes[node.name].tiles) == "table" and type(minetest.registered_nodes[node.name].tiles[1])== "string" then local texture = minetest.registered_nodes[node.name].tiles[1] @@ -291,6 +278,82 @@ end function cannons.get_settings(node) return cannons.registered_muni[node].entity end +--++++++++++++++++++++++++++++++++++++ +--+ mesecons stuff + +--++++++++++++++++++++++++++++++++++++ +cannons.rules ={ + {x = 1, y = 0, z = 0}, + {x =-1, y = 0, z = 0}, + {x = 0, y = 0, z = 1}, + {x = 0, y = 0, z =-1} + } + +function cannons.meseconsfire(pos,node) + cannons.fire(pos,node) +end + +cannons.supportMesecons = { + effector = { + rules = cannons.rules, + action_on = cannons.meseconsfire, + } +} + + +--++++++++++++++++++++++++++++++++++++ +--+ cannons.nodeboxes + +--++++++++++++++++++++++++++++++++++++ +cannons.nodeboxes = {} +cannons.nodeboxes.ball = { + type = "fixed", + fixed = { + {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}, + + -- side , top , side , side , bottom, side, + + }, + } +cannons.nodeboxes.ball_stack = { + type = "fixed", + fixed = { + {-0.2, -0.1, -0.2, 0.2, 0.3, 0.2}, -- ball top + {0.1, -0.5, -0.2, 0.2, -0.1, 0.2}, -- ball left + {0.5, -0.5, -0.2, 0.2, -0.1, 0.2}, -- ball left + {-0.2, -0.5, 0.5, 0.0, -0.1, 0.2},-- ball back + {0.0, -0.5, 0.1, -0.4, -0.1, 0.2},--ball back + {-0.2, -0.5, 0.5, -0.4, -0.1, 0.2},-- ball back + {-0.2, -0.5, 0.1, -0.4, -0.1, 0.2},-- ball back + {-0.2, -0.5, -0.1, -0.4, -0.1, -0.5}, + {0.0, -0.5, -0.1, -0.4, -0.1, -0.5}, + + + -- side , top , side , side , bottom, side, + + }, + } +cannons.nodeboxes.cannon = { + type = "fixed", + fixed = { + {-0.2, 0.2, -0.7, 0.2, -0.2, 0.9}, -- barrle -- + {0.53, -0.1, 0.1, -0.53, 0.1, -0.1}, -- plinth -- + + -- side , top hight , depth , side , bottom, side, + + } + } +cannons.nodeboxes.stand = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, -- bottom -- + {-0.5, -0.5, -0.5, -0.35, 1.0, 0.5}, -- side left -- + {0.35, -0.5, -0.5, 0.5, 1.0, 0.5}, -- side right -- + {0.35, -0.5, -0.2, 0.5, 1.2, 0.5}, -- side right -- + {-0.5, -0.5, -0.2, -0.35, 1.2, 0.5}, -- side left -- + + -- side , top , side , side , bottom, side, + + }, + } local apple={ physical = false, diff --git a/items.lua b/items.lua index d27d869..065d0f2 100644 --- a/items.lua +++ b/items.lua @@ -161,7 +161,7 @@ end -- classic cannon -- minetest.register_node("cannons:cannon", { - description = "Cannon", + description = "Cannon", stack_max = 1, tiles = {"cannon_cannon_top.png","cannon_cannon_top.png","cannon_cannon_side.png","cannon_cannon_side.png","cannon_cannon_top.png^cannons_rim.png","cannon_cannon_side.png"}, drawtype = "nodebox", @@ -169,35 +169,15 @@ minetest.register_node("cannons:cannon", { paramtype2 = "facedir", groups = {cracky=1}, sounds = cannons.sound_defaults(), - node_box = cannons.nodebox, - on_place = cannons.on_place, - selection_box = cannons.nodebox, + node_box = cannons.nodeboxes.cannon, on_punch = cannons.punched, - mesecons = {effector = { - rules = cannons.rules, - action_on = cannons.meseconsfire, - } - }, + mesecons = cannons.supportMesecons, on_construct = cannons.on_construct, - can_dig = function(pos,player) - local meta = minetest.get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("gunpowder") then - return false - elseif not inv:is_empty("muni") then - return false - else - return true - end - end, - allow_metadata_inventory_put = cannons.allow_metadata_inventory_put, - - allow_metadata_inventory_move = cannons.allow_metadata_inventory_move, - - on_metadata_inventory_put = cannons.inventory_modified, - - on_metadata_inventory_take = cannons.inventory_modified, - + can_dig = cannons.can_dig, + allow_metadata_inventory_put = cannons.allow_metadata_inventory_put, + allow_metadata_inventory_move = cannons.allow_metadata_inventory_move, + on_metadata_inventory_put = cannons.inventory_modified, + on_metadata_inventory_take = cannons.inventory_modified, on_metadata_inventory_move = cannons.inventory_modified, }) @@ -212,34 +192,15 @@ minetest.register_node("cannons:bronze_canon", { paramtype2 = "facedir", groups = {cracky=1}, sounds = cannons.sound_defaults(), - node_box = cannons.nodebox, - selection_box = cannons.nodebox, + node_box = cannons.nodeboxes.cannon, on_punch = cannons.punched, - mesecons = {effector = { - rules = cannons.rules, - action_on = cannons.meseconsfire, - } - }, + mesecons = cannons.supportMesecons, on_construct = cannons.on_construct, - can_dig = function(pos,player) - local meta = minetest.get_meta(pos); - local inv = meta:get_inventory() - if not inv:is_empty("gunpowder") then - return false - elseif not inv:is_empty("muni") then - return false - else - return true - end - end, + can_dig = cannons.can_dig, allow_metadata_inventory_put = cannons.allow_metadata_inventory_put, - - allow_metadata_inventory_move = cannons.allow_metadata_inventory_move, - - on_metadata_inventory_put = cannons.inventory_modified, - - on_metadata_inventory_take = cannons.inventory_modified, - + allow_metadata_inventory_move = cannons.allow_metadata_inventory_move, + on_metadata_inventory_put = cannons.inventory_modified, + on_metadata_inventory_take = cannons.inventory_modified, on_metadata_inventory_move = cannons.inventory_modified, }) @@ -253,7 +214,7 @@ minetest.register_node("cannons:stand", { paramtype2 = "facedir", groups = {cracky=2,cannonstand=1}, sounds = default.node_sound_wood_defaults(), - node_box = cannons.stand_nodebox, + node_box = cannons.nodeboxes.stand, selection_box = { type = "fixed", fixed = { @@ -271,7 +232,7 @@ minetest.register_node("cannons:stand_wood", { paramtype2 = "facedir", groups = {cracky=2,cannonstand=1}, sounds = default.node_sound_wood_defaults(), - node_box = cannons.stand_nodebox, + node_box = cannons.nodeboxes.stand, selection_box = { type = "fixed", fixed = { @@ -283,6 +244,7 @@ minetest.register_node("cannons:stand_wood", { --+ cannon balls + --++++++++++++++++++++++++++++++++++++ +--wood ball minetest.register_node("cannons:ball_wood", { description = "Cannon Ball Wood", stack_max = 99, @@ -292,23 +254,10 @@ minetest.register_node("cannons:ball_wood", { paramtype2 = "facedir", groups = {cracky=2}, sounds = default.node_sound_wood_defaults(), - node_box = { - type = "fixed", - fixed = { - {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}, - - -- side , top , side , side , bottom, side, - - }, - }, - selection_box = { - type = "fixed", - fixed = { - {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}, - }, - }, + node_box = cannons.nodeboxes.ball, }) +--stone ball minetest.register_node("cannons:ball_stone", { description = "Cannon Ball Stone", stack_max = 99, @@ -318,23 +267,10 @@ minetest.register_node("cannons:ball_stone", { paramtype2 = "facedir", groups = {cracky=2}, sounds = default.node_sound_wood_defaults(), - node_box = { - type = "fixed", - fixed = { - {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}, - - -- side , top , side , side , bottom, side, - - }, - }, - selection_box = { - type = "fixed", - fixed = { - {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}, - }, - }, + node_box = cannons.nodeboxes.ball, }) +--steel ball minetest.register_node("cannons:ball_steel", { description = "Cannon Ball Steel", stack_max = 99, @@ -344,22 +280,10 @@ minetest.register_node("cannons:ball_steel", { paramtype2 = "facedir", groups = {cracky=2}, sounds = default.node_sound_wood_defaults(), - node_box = { - type = "fixed", - fixed = { - {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}, - - -- side , top , side , side , bottom, side, - - }, - }, - selection_box = { - type = "fixed", - fixed = { - {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}, - }, - }, + node_box = cannons.nodeboxes.ball, }) + +--explosion cannon ball if cannons.enable_explosion then minetest.register_node("cannons:ball_exploding", { description = "Exploding Cannon Ball", @@ -370,23 +294,11 @@ minetest.register_node("cannons:ball_exploding", { paramtype2 = "facedir", groups = {cracky=2}, sounds = default.node_sound_wood_defaults(), - node_box = { - type = "fixed", - fixed = { - {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}, - - -- side , top , side , side , bottom, side, - - }, - }, - selection_box = { - type = "fixed", - fixed = { - {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}, - }, - }, + node_box = cannons.nodeboxes.ball, }) end + +--fire cannon ball if cannons.enable_fire then minetest.register_node("cannons:ball_fire", { description = "Burning Cannon Ball", @@ -397,23 +309,11 @@ minetest.register_node("cannons:ball_fire", { paramtype2 = "facedir", groups = {cracky=2}, sounds = default.node_sound_wood_defaults(), - node_box = { - type = "fixed", - fixed = { - {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}, - - -- side , top , side , side , bottom, side, - - }, - }, - selection_box = { - type = "fixed", - fixed = { - {-0.2, -0.5, -0.2, 0.2, -0.1, 0.2}, - }, - }, + node_box = cannons.nodeboxes.ball, }) end + +--ball wood stack minetest.register_node("cannons:ball_wood_stack", { description = "Cannon Ball Wood Stack", stack_max = 99, @@ -424,24 +324,7 @@ minetest.register_node("cannons:ball_wood_stack", { paramtype2 = "facedir", groups = {cracky=2}, sounds = default.node_sound_wood_defaults(), - node_box = { - type = "fixed", - fixed = { - {-0.2, -0.1, -0.2, 0.2, 0.3, 0.2}, -- ball top - {0.1, -0.5, -0.2, 0.2, -0.1, 0.2}, -- ball left - {0.5, -0.5, -0.2, 0.2, -0.1, 0.2}, -- ball left - {-0.2, -0.5, 0.5, 0.0, -0.1, 0.2},-- ball back - {0.0, -0.5, 0.1, -0.4, -0.1, 0.2},--ball back - {-0.2, -0.5, 0.5, -0.4, -0.1, 0.2},-- ball back - {-0.2, -0.5, 0.1, -0.4, -0.1, 0.2},-- ball back - {-0.2, -0.5, -0.1, -0.4, -0.1, -0.5}, - {0.0, -0.5, -0.1, -0.4, -0.1, -0.5}, - - - -- side , top , side , side , bottom, side, - - }, - }, + node_box = cannons.nodeboxes.ball_stack, selection_box = { type = "fixed", fixed = { @@ -450,7 +333,7 @@ minetest.register_node("cannons:ball_wood_stack", { }, }) - +--ball stone stack minetest.register_node("cannons:ball_stone_stack", { description = "Cannon Ball Stone Stack", stack_max = 99, @@ -461,24 +344,7 @@ minetest.register_node("cannons:ball_stone_stack", { paramtype2 = "facedir", groups = {cracky=2}, sounds = default.node_sound_wood_defaults(), - node_box = { - type = "fixed", - fixed = { - {-0.2, -0.1, -0.2, 0.2, 0.3, 0.2}, -- ball top - {0.1, -0.5, -0.2, 0.2, -0.1, 0.2}, -- ball left - {0.5, -0.5, -0.2, 0.2, -0.1, 0.2}, -- ball left - {-0.2, -0.5, 0.5, 0.0, -0.1, 0.2},-- ball back - {0.0, -0.5, 0.1, -0.4, -0.1, 0.2},--ball back - {-0.2, -0.5, 0.5, -0.4, -0.1, 0.2},-- ball back - {-0.2, -0.5, 0.1, -0.4, -0.1, 0.2},-- ball back - {-0.2, -0.5, -0.1, -0.4, -0.1, -0.5}, - {0.0, -0.5, -0.1, -0.4, -0.1, -0.5}, - - - -- side , top , side , side , bottom, side, - - }, - }, + node_box = cannons.nodeboxes.ball_stack, selection_box = { type = "fixed", fixed = { @@ -487,6 +353,7 @@ minetest.register_node("cannons:ball_stone_stack", { }, }) +--ball steel stack minetest.register_node("cannons:canon_ball_steel_stack", { description = "Cannon Ball Steel Stack", stack_max = 99, @@ -497,24 +364,7 @@ minetest.register_node("cannons:canon_ball_steel_stack", { paramtype2 = "facedir", groups = {cracky=2}, sounds = default.node_sound_wood_defaults(), - node_box = { - type = "fixed", - fixed = { - {-0.2, -0.1, -0.2, 0.2, 0.3, 0.2}, -- ball top - {0.1, -0.5, -0.2, 0.2, -0.1, 0.2}, -- ball left - {0.5, -0.5, -0.2, 0.2, -0.1, 0.2}, -- ball left - {-0.2, -0.5, 0.5, 0.0, -0.1, 0.2},-- ball back - {0.0, -0.5, 0.1, -0.4, -0.1, 0.2},--ball back - {-0.2, -0.5, 0.5, -0.4, -0.1, 0.2},-- ball back - {-0.2, -0.5, 0.1, -0.4, -0.1, 0.2},-- ball back - {-0.2, -0.5, -0.1, -0.4, -0.1, -0.5}, - {0.0, -0.5, -0.1, -0.4, -0.1, -0.5}, - - - -- side , top , side , side , bottom, side, - - }, - }, + node_box = cannons.nodeboxes.ball_stack, selection_box = { type = "fixed", fixed = { diff --git a/locks.lua b/locks.lua index 2c347d3..fd666fc 100644 --- a/locks.lua +++ b/locks.lua @@ -12,9 +12,8 @@ minetest.register_node("cannons:shared_locked_cannon", { paramtype2 = "facedir", groups = {cracky=1}, sounds = cannons.sound_defaults(), - node_box = cannons.nodebox, + node_box = cannons.nodeboxes.cannon, on_place = cannons.on_place, - selection_box = cannons.nodebox, on_punch = cannons.punched, on_receive_fields = function(pos, formname, fields, sender) locks:lock_handle_input( pos, formname, fields, sender );