mirror of
https://bitbucket.org/kingarthursteam/cannons.git
synced 2024-12-03 12:13:48 +01:00
added mesecons support (#4)
This commit is contained in:
parent
0d670c9e22
commit
c36013665a
@ -1,2 +1,3 @@
|
|||||||
default
|
default
|
||||||
bucket
|
bucket
|
||||||
|
mesecons?
|
||||||
|
@ -115,17 +115,37 @@ 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)
|
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 stack = inv:get_stack("muni", 1)
|
||||||
local muni = stack:to_table()
|
local muni = stack:to_table()
|
||||||
if inv:contains_item("gunpowder","cannons:gunpowder 1")
|
if inv:contains_item("gunpowder","cannons:gunpowder 1")
|
||||||
and muni ~= nil
|
and 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")
|
||||||
|
|
||||||
then
|
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",
|
minetest.sound_play("cannons_shot",
|
||||||
{pos = pos, gain = 1.0, max_hear_distance = 32,})
|
{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("muni", muni.name.." 1")
|
||||||
inv:remove_item("gunpowder", "cannons:gunpowder 1")
|
inv:remove_item("gunpowder", "cannons:gunpowder 1")
|
||||||
cannons.inventory_modified(pos)
|
cannons.inventory_modified(pos)
|
||||||
|
|
||||||
|
|
||||||
local settings = cannons.get_settings(muni.name)
|
local settings = cannons.get_settings(muni.name)
|
||||||
local playerpos=puncher:getpos()
|
|
||||||
local obj=minetest.env:add_entity(pos, cannons.get_entity(muni.name))
|
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: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})
|
obj:setacceleration({x=dir.x*-3, y=-settings.gravity, z=dir.z*-3})
|
||||||
end
|
end
|
||||||
|
10
items.lua
10
items.lua
@ -173,6 +173,11 @@ minetest.register_node("cannons:cannon", {
|
|||||||
on_place = cannons.on_place,
|
on_place = cannons.on_place,
|
||||||
selection_box = cannons.nodebox,
|
selection_box = cannons.nodebox,
|
||||||
on_punch = cannons.punched,
|
on_punch = cannons.punched,
|
||||||
|
mesecons = {effector = {
|
||||||
|
rules = cannons.rules,
|
||||||
|
action_on = cannons.meseconsfire,
|
||||||
|
}
|
||||||
|
},
|
||||||
on_construct = cannons.on_construct,
|
on_construct = cannons.on_construct,
|
||||||
can_dig = function(pos,player)
|
can_dig = function(pos,player)
|
||||||
local meta = minetest.get_meta(pos);
|
local meta = minetest.get_meta(pos);
|
||||||
@ -210,6 +215,11 @@ minetest.register_node("cannons:bronze_canon", {
|
|||||||
node_box = cannons.nodebox,
|
node_box = cannons.nodebox,
|
||||||
selection_box = cannons.nodebox,
|
selection_box = cannons.nodebox,
|
||||||
on_punch = cannons.punched,
|
on_punch = cannons.punched,
|
||||||
|
mesecons = {effector = {
|
||||||
|
rules = cannons.rules,
|
||||||
|
action_on = cannons.meseconsfire,
|
||||||
|
}
|
||||||
|
},
|
||||||
on_construct = cannons.on_construct,
|
on_construct = cannons.on_construct,
|
||||||
can_dig = function(pos,player)
|
can_dig = function(pos,player)
|
||||||
local meta = minetest.get_meta(pos);
|
local meta = minetest.get_meta(pos);
|
||||||
|
Loading…
Reference in New Issue
Block a user