added mesecons support (#4)

This commit is contained in:
adrido 2013-11-29 18:44:41 +01:00
parent 0d670c9e22
commit c36013665a
3 changed files with 38 additions and 7 deletions

@ -1,2 +1,3 @@
default
bucket
mesecons?

@ -115,6 +115,14 @@ cannons.stand_nodebox = {
},
}
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.fire(pos,node,puncher)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
@ -126,6 +134,18 @@ function cannons.fire(pos,node,puncher)
and inv:contains_item("muni",muni.name.." 1")
then
if puncher ~= nil then
dir=puncher:get_look_dir()
meta:set_string("dir", minetest.serialize(dir))
pr(dir)
else
dir = {}
dir = minetest.deserialize(meta:get_string("dir"));
if dir == nil then
return
end
pr(dir)
end
minetest.sound_play("cannons_shot",
{pos = pos, gain = 1.0, max_hear_distance = 32,})
@ -133,10 +153,10 @@ function cannons.fire(pos,node,puncher)
inv:remove_item("muni", muni.name.." 1")
inv:remove_item("gunpowder", "cannons:gunpowder 1")
cannons.inventory_modified(pos)
local settings = cannons.get_settings(muni.name)
local playerpos=puncher:getpos()
local obj=minetest.env:add_entity(pos, cannons.get_entity(muni.name))
local dir=puncher:get_look_dir()
obj:setvelocity({x=dir.x*settings.velocity, y=-1, z=dir.z*settings.velocity})
obj:setacceleration({x=dir.x*-3, y=-settings.gravity, z=dir.z*-3})
end

@ -173,6 +173,11 @@ minetest.register_node("cannons:cannon", {
on_place = cannons.on_place,
selection_box = cannons.nodebox,
on_punch = cannons.punched,
mesecons = {effector = {
rules = cannons.rules,
action_on = cannons.meseconsfire,
}
},
on_construct = cannons.on_construct,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
@ -210,6 +215,11 @@ minetest.register_node("cannons:bronze_canon", {
node_box = cannons.nodebox,
selection_box = cannons.nodebox,
on_punch = cannons.punched,
mesecons = {effector = {
rules = cannons.rules,
action_on = cannons.meseconsfire,
}
},
on_construct = cannons.on_construct,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);