mirror of
https://bitbucket.org/kingarthursteam/cannons.git
synced 2025-01-25 11:11:25 +01:00
new registration system
This commit is contained in:
parent
b2feb0d29c
commit
fd6ecf70d9
@ -38,7 +38,7 @@ local exploding={
|
|||||||
|
|
||||||
}
|
}
|
||||||
if cannons.config:get("enable_explosion") == "true" then
|
if cannons.config:get("enable_explosion") == "true" then
|
||||||
cannons.register_muni("cannons:ball_exploding",exploding)
|
cannons.register_muni("cannons:ball_exploding_stack_1",exploding)
|
||||||
end
|
end
|
||||||
local fire={
|
local fire={
|
||||||
physical = false,
|
physical = false,
|
||||||
@ -74,14 +74,14 @@ local fire={
|
|||||||
|
|
||||||
}
|
}
|
||||||
if cannons.config:get("enable_fire")=="true" then
|
if cannons.config:get("enable_fire")=="true" then
|
||||||
cannons.register_muni("cannons:ball_fire",fire)
|
cannons.register_muni("cannons:ball_fire_stack_1",fire)
|
||||||
end
|
end
|
||||||
|
|
||||||
--++++++++++++++++++++++++++++++++++++
|
--++++++++++++++++++++++++++++++++++++
|
||||||
--+ Wooden Cannon ball +
|
--+ Wooden Cannon ball +
|
||||||
--++++++++++++++++++++++++++++++++++++
|
--++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
cannons.register_muni("cannons:ball_wood",{
|
cannons.register_muni("cannons:ball_wood_stack_1",{
|
||||||
physical = false,
|
physical = false,
|
||||||
timer=0,
|
timer=0,
|
||||||
textures = {"cannons_wood_bullet.png"},
|
textures = {"cannons_wood_bullet.png"},
|
||||||
@ -131,7 +131,7 @@ cannons.register_muni("cannons:ball_wood",{
|
|||||||
--+ Stone Cannon ball +
|
--+ Stone Cannon ball +
|
||||||
--++++++++++++++++++++++++++++++++++++
|
--++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
cannons.register_muni("cannons:ball_stone",{
|
cannons.register_muni("cannons:ball_stone_stack_1",{
|
||||||
physical = false,
|
physical = false,
|
||||||
timer=0,
|
timer=0,
|
||||||
textures = {"cannons_bullet.png"},
|
textures = {"cannons_bullet.png"},
|
||||||
@ -181,7 +181,7 @@ cannons.register_muni("cannons:ball_stone",{
|
|||||||
--+ Steel Cannon ball +
|
--+ Steel Cannon ball +
|
||||||
--++++++++++++++++++++++++++++++++++++
|
--++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
cannons.register_muni("cannons:ball_steel",{
|
cannons.register_muni("cannons:ball_steel_stack_1",{
|
||||||
physical = false,
|
physical = false,
|
||||||
timer=0,
|
timer=0,
|
||||||
textures = {"cannons_bullet_iron.png"},
|
textures = {"cannons_bullet_iron.png"},
|
||||||
|
121
functions.lua
121
functions.lua
@ -30,8 +30,8 @@ end
|
|||||||
function cannons.inventory_modified(pos)
|
function cannons.inventory_modified(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local stack = inv:get_stack("muni", 1)
|
local muni = inv:get_stack("muni", 1):to_table()
|
||||||
local muni = stack:to_table()
|
local gunpowder = inv:get_stack("gunpowder", 1):to_table();
|
||||||
local addition = ""
|
local addition = ""
|
||||||
if meta:get_string("owner") ~="" then
|
if meta:get_string("owner") ~="" then
|
||||||
addition = " (owned by "..meta:get_string("owner")..")"
|
addition = " (owned by "..meta:get_string("owner")..")"
|
||||||
@ -41,8 +41,12 @@ function cannons.inventory_modified(pos)
|
|||||||
else
|
else
|
||||||
muni = cannons.is_muni(muni.name)
|
muni = cannons.is_muni(muni.name)
|
||||||
end
|
end
|
||||||
|
if gunpowder == nil then
|
||||||
|
gunpowder = false;
|
||||||
|
else
|
||||||
|
gunpowder = cannons.is_gunpowder(gunpowder.name)
|
||||||
|
end
|
||||||
|
|
||||||
local gunpowder = inv:contains_item("gunpowder","cannons:gunpowder 1")
|
|
||||||
if not muni and not gunpowder then
|
if not muni and not gunpowder then
|
||||||
meta:set_string("infotext","Cannon has no muni and no gunpowder"..addition)
|
meta:set_string("infotext","Cannon has no muni and no gunpowder"..addition)
|
||||||
|
|
||||||
@ -65,7 +69,7 @@ cannons.allow_metadata_inventory_put = function(pos, listname, index, stack, pla
|
|||||||
end
|
end
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
stack = stack:to_table()
|
stack = stack:to_table()
|
||||||
if listname == "gunpowder" and stack.name == "cannons:gunpowder" then
|
if listname == "gunpowder" and cannons.is_gunpowder(stack.name) then
|
||||||
return stack.count
|
return stack.count
|
||||||
elseif listname == "muni" and cannons.is_muni(stack.name) then
|
elseif listname == "muni" and cannons.is_muni(stack.name) then
|
||||||
return stack.count
|
return stack.count
|
||||||
@ -83,7 +87,7 @@ cannons.allow_metadata_inventory_move = function(pos, from_list, from_index, to_
|
|||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local stack = inv:get_stack(from_list, from_index)
|
local stack = inv:get_stack(from_list, from_index)
|
||||||
stack = stack:to_table()
|
stack = stack:to_table()
|
||||||
if to_list == "gunpowder" and stack.name == "cannons:gunpowder" then
|
if to_list == "gunpowder" and cannons.is_gunpowder(stack.name) then
|
||||||
return count
|
return count
|
||||||
|
|
||||||
elseif to_list == "muni" and cannons.is_muni(stack.name) then
|
elseif to_list == "muni" and cannons.is_muni(stack.name) then
|
||||||
@ -205,13 +209,16 @@ end
|
|||||||
function cannons.fire(pos,node,puncher)
|
function cannons.fire(pos,node,puncher)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local stack = inv:get_stack("muni", 1)
|
local muni = inv:get_stack("muni", 1):to_table();
|
||||||
local muni = stack:to_table()
|
local gunpowder = inv:get_stack("gunpowder", 1):to_table();
|
||||||
local dir = {}
|
local dir = {}
|
||||||
if inv:contains_item("gunpowder","cannons:gunpowder 1")
|
--print(muni ~= nil,cannons.is_muni(muni.name),inv:contains_item("muni",muni.name.." 1"),gunpowder ~= nil ,cannons.is_gunpowder(gunpowder.name),inv:contains_item("gunpowder",gunpowder.name.." 1"))
|
||||||
and muni ~= nil
|
if muni ~= nil
|
||||||
and cannons.is_muni(muni.name)
|
and cannons.is_muni(muni.name)
|
||||||
and inv:contains_item("muni",muni.name.." 1")
|
and inv:contains_item("muni",muni.name.." 1")
|
||||||
|
and gunpowder ~= nil
|
||||||
|
and cannons.is_gunpowder(gunpowder.name)
|
||||||
|
and inv:contains_item("gunpowder",gunpowder.name.." 1")
|
||||||
|
|
||||||
then
|
then
|
||||||
if puncher ~= nil then
|
if puncher ~= nil then
|
||||||
@ -228,7 +235,7 @@ function cannons.fire(pos,node,puncher)
|
|||||||
|
|
||||||
|
|
||||||
inv:remove_item("muni", muni.name.." 1")
|
inv:remove_item("muni", muni.name.." 1")
|
||||||
inv:remove_item("gunpowder", "cannons:gunpowder 1")
|
inv:remove_item("gunpowder", gunpowder.name.." 1")
|
||||||
cannons.inventory_modified(pos)
|
cannons.inventory_modified(pos)
|
||||||
|
|
||||||
|
|
||||||
@ -261,7 +268,7 @@ function cannons.punched(pos, node, puncher)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--++++++++++++++++++++++++++++++++++++
|
--++++++++++++++++++++++++++++++++++++
|
||||||
--+ cannons.register_muni +
|
--+ cannons.register_muni +
|
||||||
--++++++++++++++++++++++++++++++++++++
|
--++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
cannons.registered_muni = {}
|
cannons.registered_muni = {}
|
||||||
@ -290,7 +297,7 @@ function cannons.register_muni(node,entity)
|
|||||||
self.on_player_hit(self,pos,player)
|
self.on_player_hit(self,pos,player)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif node.name ~=air then
|
elseif node.name ~= "air" then
|
||||||
self.on_node_hit(self,pos,node)
|
self.on_node_hit(self,pos,node)
|
||||||
end
|
end
|
||||||
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
|
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
|
||||||
@ -301,14 +308,96 @@ function cannons.register_muni(node,entity)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function cannons.is_muni(node)
|
function cannons.is_muni(node)
|
||||||
return cannons.registered_muni[node] ~= nil
|
return cannons.registered_muni[node] ~= nil
|
||||||
end
|
end
|
||||||
function cannons.get_entity(node)
|
function cannons.get_entity(node)
|
||||||
return cannons.registered_muni[node].obj
|
return cannons.registered_muni[node].obj
|
||||||
end
|
end
|
||||||
function cannons.get_settings(node)
|
function cannons.get_settings(node)
|
||||||
return cannons.registered_muni[node].entity
|
return cannons.registered_muni[node].entity
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--++++++++++++++++++++++++++++++++++++
|
||||||
|
--+ cannons.register_gunpowder +
|
||||||
|
--++++++++++++++++++++++++++++++++++++
|
||||||
|
cannons.registered_gunpowder = {}
|
||||||
|
function cannons.register_gunpowder(node)
|
||||||
|
cannons.registered_gunpowder[node] = true;
|
||||||
|
end
|
||||||
|
|
||||||
|
function cannons.is_gunpowder(node)
|
||||||
|
return cannons.registered_gunpowder[node] ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--++++++++++++++++++++++++++++++++++++
|
||||||
|
--+ cannons ball stack +
|
||||||
|
--++++++++++++++++++++++++++++++++++++
|
||||||
|
function cannons.on_ball_punch(pos, node, puncher, pointed_thing)
|
||||||
|
if not puncher or not puncher:is_player() then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local nodearr = string.split(node.name,"_stack_");
|
||||||
|
local item = nodearr[1];
|
||||||
|
local level = tonumber(nodearr[2]);
|
||||||
|
puncher:get_inventory():add_item('main', item)
|
||||||
|
if level > 1 then
|
||||||
|
node.name = item.."_stack_"..level-1
|
||||||
|
minetest.swap_node(pos,node);
|
||||||
|
else
|
||||||
|
minetest.remove_node(pos);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function cannons.on_ball_rightclick(pos, node, player, itemstack, pointed_thing)
|
||||||
|
if not player or not player:is_player() then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local basename = string.split(itemstack:get_name(),"_stack_")[1];
|
||||||
|
local nodearr = string.split(node.name,"_stack_");
|
||||||
|
local item = nodearr[1];
|
||||||
|
local level = tonumber(nodearr[2]);
|
||||||
|
if basename == item then
|
||||||
|
if level < 5 then
|
||||||
|
itemstack:take_item(1)
|
||||||
|
node.name = item.."_stack_"..level+1
|
||||||
|
minetest.swap_node(pos,node);
|
||||||
|
return itemstack;
|
||||||
|
else
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function cannons.generate_and_register_ball_node(name,nodedef)
|
||||||
|
minetest.register_alias(name, name.."_stack_1");
|
||||||
|
nodedef.drawtype = "nodebox";
|
||||||
|
nodedef.selection_box = nil;
|
||||||
|
nodedef.on_punch = cannons.on_ball_punch;
|
||||||
|
nodedef.on_rightclick = cannons.on_ball_rightclick;
|
||||||
|
local nodebox = {
|
||||||
|
type = "fixed",
|
||||||
|
fixed = {},
|
||||||
|
}; --initialize empty nodebox
|
||||||
|
|
||||||
|
for number = 1, 5, 1 do
|
||||||
|
nodebox.fixed[number] = cannons.nodeboxes.ball_stack.fixed[number];--copy a part to nodebox
|
||||||
|
nodedef.node_box = nodebox;--add nodebox to nodedef
|
||||||
|
nodedef.selection_box = table.copy(nodebox);
|
||||||
|
nodedef["drop"] = name.."_stack_1 "..number;--set drop
|
||||||
|
nodedef.name = name.."_stack_"..number;--set name
|
||||||
|
|
||||||
|
minetest.register_node(nodedef.name, table.copy(nodedef))--register node
|
||||||
|
end
|
||||||
|
--register craft, to allow craft 5-stacks
|
||||||
|
minetest.register_craft({
|
||||||
|
type = "shapeless",
|
||||||
|
output = name.."_stack_5",
|
||||||
|
recipe = { name,name,name,name,name},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
--++++++++++++++++++++++++++++++++++++
|
--++++++++++++++++++++++++++++++++++++
|
||||||
--+ mesecons stuff +
|
--+ mesecons stuff +
|
||||||
--++++++++++++++++++++++++++++++++++++
|
--++++++++++++++++++++++++++++++++++++
|
||||||
|
98
items.lua
98
items.lua
@ -7,6 +7,7 @@ minetest.register_craftitem("cannons:gunpowder", {
|
|||||||
description = "Gunpowder",
|
description = "Gunpowder",
|
||||||
inventory_image = "cannons_gunpowder.png"
|
inventory_image = "cannons_gunpowder.png"
|
||||||
})
|
})
|
||||||
|
cannons.register_gunpowder("cannons:gunpowder");
|
||||||
|
|
||||||
minetest.register_craftitem("cannons:salt", {
|
minetest.register_craftitem("cannons:salt", {
|
||||||
description = "Salt",
|
description = "Salt",
|
||||||
@ -89,29 +90,7 @@ minetest.register_craft({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
|
||||||
type = "shapeless",
|
|
||||||
output = 'cannons:ball_steel_stack',
|
|
||||||
recipe = {
|
|
||||||
"cannons:ball_steel", "cannons:ball_steel", "cannons:ball_steel", "cannons:ball_steel"
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_craft({
|
|
||||||
type = "shapeless",
|
|
||||||
output = 'cannons:ball_stone_stack',
|
|
||||||
recipe = {
|
|
||||||
"cannons:ball_stone", "cannons:ball_stone", "cannons:ball_stone", "cannons:ball_stone"
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_craft({
|
|
||||||
type = "shapeless",
|
|
||||||
output = 'cannons:ball_wood_stack',
|
|
||||||
recipe = {
|
|
||||||
"cannons:ball_wood", "cannons:ball_wood", "cannons:ball_wood", "cannons:ball_wood"
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = 'cannons:ball_wood 5',
|
output = 'cannons:ball_wood 5',
|
||||||
@ -354,7 +333,7 @@ minetest.register_node("cannons:wood_stand_with_cannon_bronze", {
|
|||||||
--++++++++++++++++++++++++++++++++++++
|
--++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
--wood ball
|
--wood ball
|
||||||
minetest.register_node("cannons:ball_wood", {
|
cannons.generate_and_register_ball_node("cannons:ball_wood", {
|
||||||
description = "Cannon Ball Wood",
|
description = "Cannon Ball Wood",
|
||||||
stack_max = 99,
|
stack_max = 99,
|
||||||
tiles = {"default_wood.png"},
|
tiles = {"default_wood.png"},
|
||||||
@ -367,7 +346,7 @@ minetest.register_node("cannons:ball_wood", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
--stone ball
|
--stone ball
|
||||||
minetest.register_node("cannons:ball_stone", {
|
cannons.generate_and_register_ball_node("cannons:ball_stone", {
|
||||||
description = "Cannon Ball Stone",
|
description = "Cannon Ball Stone",
|
||||||
stack_max = 99,
|
stack_max = 99,
|
||||||
tiles = {"default_stone.png"},
|
tiles = {"default_stone.png"},
|
||||||
@ -380,7 +359,7 @@ minetest.register_node("cannons:ball_stone", {
|
|||||||
})
|
})
|
||||||
|
|
||||||
--steel ball
|
--steel ball
|
||||||
minetest.register_node("cannons:ball_steel", {
|
cannons.generate_and_register_ball_node("cannons:ball_steel", {
|
||||||
description = "Cannon Ball Steel",
|
description = "Cannon Ball Steel",
|
||||||
stack_max = 99,
|
stack_max = 99,
|
||||||
tiles = {"cannons_steel_top.png"},
|
tiles = {"cannons_steel_top.png"},
|
||||||
@ -388,13 +367,13 @@ minetest.register_node("cannons:ball_steel", {
|
|||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
groups = {cracky=2},
|
groups = {cracky=2},
|
||||||
|
--diggable = false,
|
||||||
sounds = cannons.sound_defaults(),
|
sounds = cannons.sound_defaults(),
|
||||||
node_box = cannons.nodeboxes.ball,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
--explosion cannon ball
|
--explosion cannon ball
|
||||||
if cannons.config:get("enable_explosion") == "true" then
|
if cannons.config:get("enable_explosion") == "true" then
|
||||||
minetest.register_node("cannons:ball_exploding", {
|
cannons.generate_and_register_ball_node("cannons:ball_exploding", {
|
||||||
description = "Exploding Cannon Ball",
|
description = "Exploding Cannon Ball",
|
||||||
stack_max = 99,
|
stack_max = 99,
|
||||||
tiles = {"default_mese_block.png"},
|
tiles = {"default_mese_block.png"},
|
||||||
@ -403,13 +382,12 @@ minetest.register_node("cannons:ball_exploding", {
|
|||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
groups = {cracky=2},
|
groups = {cracky=2},
|
||||||
sounds = default.node_sound_wood_defaults(),
|
sounds = default.node_sound_wood_defaults(),
|
||||||
node_box = cannons.nodeboxes.ball,
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
--fire cannon ball
|
--fire cannon ball
|
||||||
if cannons.config:get("enable_fire") == "true" then
|
if cannons.config:get("enable_fire") == "true" then
|
||||||
minetest.register_node("cannons:ball_fire", {
|
cannons.generate_and_register_ball_node("cannons:ball_fire", {
|
||||||
description = "Burning Cannon Ball",
|
description = "Burning Cannon Ball",
|
||||||
stack_max = 99,
|
stack_max = 99,
|
||||||
tiles = {"default_tree.png"},
|
tiles = {"default_tree.png"},
|
||||||
@ -422,65 +400,3 @@ minetest.register_node("cannons:ball_fire", {
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
--ball wood stack
|
|
||||||
minetest.register_node("cannons:ball_wood_stack", {
|
|
||||||
description = "Cannon Ball Wood Stack",
|
|
||||||
stack_max = 99,
|
|
||||||
tiles = {"default_wood.png"},
|
|
||||||
drawtype = "nodebox",
|
|
||||||
drop = 'cannons:ball_wood 4',
|
|
||||||
paramtype = "light",
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
groups = {cracky=2},
|
|
||||||
sounds = default.node_sound_wood_defaults(),
|
|
||||||
node_box = cannons.nodeboxes.ball_stack,
|
|
||||||
selection_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = {
|
|
||||||
{-0.4, -0.5, -0.5, 0.5, 0.3, 0.5},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
--ball stone stack
|
|
||||||
minetest.register_node("cannons:ball_stone_stack", {
|
|
||||||
description = "Cannon Ball Stone Stack",
|
|
||||||
stack_max = 99,
|
|
||||||
tiles = {"default_stone.png"},
|
|
||||||
drawtype = "nodebox",
|
|
||||||
drop = 'cannons:ball_stone 4',
|
|
||||||
paramtype = "light",
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
groups = {cracky=2},
|
|
||||||
sounds = default.node_sound_stone_defaults(),
|
|
||||||
node_box = cannons.nodeboxes.ball_stack,
|
|
||||||
selection_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = {
|
|
||||||
{-0.4, -0.5, -0.5, 0.5, 0.3, 0.5},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
--ball steel stack
|
|
||||||
minetest.register_node("cannons:ball_steel_stack", {
|
|
||||||
description = "Cannon Ball Steel Stack",
|
|
||||||
stack_max = 99,
|
|
||||||
tiles = {"cannons_steel_top.png"},
|
|
||||||
drawtype = "nodebox",
|
|
||||||
drop = 'cannons:ball_steel 4',
|
|
||||||
paramtype = "light",
|
|
||||||
paramtype2 = "facedir",
|
|
||||||
groups = {cracky=2},
|
|
||||||
sounds = cannons.sound_defaults(),
|
|
||||||
node_box = cannons.nodeboxes.ball_stack,
|
|
||||||
selection_box = {
|
|
||||||
type = "fixed",
|
|
||||||
fixed = {
|
|
||||||
{-0.4, -0.5, -0.5, 0.5, 0.3, 0.5},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
minetest.register_alias("cannons:canon_ball_steel_stack", "cannons:ball_steel_stack")
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user