2017-07-13 12:33:00 +00:00
|
|
|
minetest.register_craftitem("shooter_flaregun:flare", {
|
2014-07-26 20:18:10 +00:00
|
|
|
description = "Flare",
|
|
|
|
inventory_image = "shooter_flare_inv.png",
|
|
|
|
})
|
|
|
|
|
2017-07-13 12:33:00 +00:00
|
|
|
minetest.register_node("shooter_flaregun:flare_light", {
|
2014-07-26 20:18:10 +00:00
|
|
|
drawtype = "glasslike",
|
|
|
|
tiles = {"shooter_flare_light.png"},
|
|
|
|
paramtype = "light",
|
|
|
|
groups = {not_in_creative_inventory=1},
|
|
|
|
drop = "",
|
|
|
|
walkable = false,
|
|
|
|
buildable_to = true,
|
|
|
|
sunlight_propagates = true,
|
2019-03-15 17:55:37 +00:00
|
|
|
light_source = 14,
|
2014-07-26 20:18:10 +00:00
|
|
|
pointable = false,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_abm({
|
2017-07-13 12:33:00 +00:00
|
|
|
nodenames = "shooter_flaregun:flare_light",
|
2014-07-26 20:18:10 +00:00
|
|
|
interval = 5,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node)
|
|
|
|
local time = os.time()
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local init_time = meta:get_int("init_time") or 0
|
|
|
|
if time > init_time + 30 then
|
|
|
|
local id = meta:get_int("particle_id")
|
|
|
|
if id then
|
|
|
|
minetest.delete_particlespawner(id)
|
|
|
|
end
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2017-07-13 12:33:00 +00:00
|
|
|
minetest.register_entity("shooter_flaregun:flare_entity", {
|
2014-07-26 20:18:10 +00:00
|
|
|
physical = true,
|
|
|
|
timer = 0,
|
|
|
|
visual = "cube",
|
|
|
|
visual_size = {x=1/8, y=1/8},
|
|
|
|
textures = {
|
|
|
|
"shooter_flare.png",
|
|
|
|
"shooter_flare.png",
|
|
|
|
"shooter_flare.png",
|
|
|
|
"shooter_flare.png",
|
|
|
|
"shooter_flare.png",
|
|
|
|
"shooter_flare.png",
|
|
|
|
},
|
2019-03-15 17:55:37 +00:00
|
|
|
glow = 14,
|
2014-07-26 20:18:10 +00:00
|
|
|
collisionbox = {-1/16,-1/16,-1/16, 1/16,1/16,1/16},
|
|
|
|
on_activate = function(self, staticdata)
|
|
|
|
if staticdata == "expired" then
|
|
|
|
self.object:remove()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
on_step = function(self, dtime)
|
|
|
|
self.timer = self.timer + dtime
|
|
|
|
if self.timer > 0.2 then
|
2019-03-15 17:55:37 +00:00
|
|
|
local pos = self.object:get_pos()
|
2014-07-26 20:18:10 +00:00
|
|
|
local below = {x=pos.x, y=pos.y - 1, z=pos.z}
|
|
|
|
local node = minetest.get_node(below)
|
|
|
|
if node.name ~= "air" then
|
2019-03-15 17:55:37 +00:00
|
|
|
self.object:set_velocity({x=0, y=-10, z=0})
|
|
|
|
self.object:set_acceleration({x=0, y=0, z=0})
|
2014-07-26 20:18:10 +00:00
|
|
|
if minetest.get_node(pos).name == "air" and
|
|
|
|
node.name ~= "default:water_source" and
|
|
|
|
node.name ~= "default:water_flowing" then
|
2017-07-13 12:33:00 +00:00
|
|
|
minetest.place_node(pos, {name="shooter_flaregun:flare_light"})
|
2014-07-26 20:18:10 +00:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
pos.y = pos.y - 0.1
|
2019-03-15 17:55:37 +00:00
|
|
|
local id = minetest.add_particlespawner({
|
|
|
|
amount = 1000,
|
|
|
|
time = 30,
|
|
|
|
minpos = pos,
|
|
|
|
maxpos = pos,
|
|
|
|
minvel = {x=-1, y=1, z=-1},
|
|
|
|
maxvel = {x=1, y=1, z=1},
|
|
|
|
minacc = {x=2, y=-2, z=-2},
|
|
|
|
maxacc = {x=2, y=-2, z=2},
|
|
|
|
minexptime = 0.1,
|
|
|
|
maxexptime = 0.75,
|
|
|
|
minsize = 1,
|
|
|
|
maxsize = 8,
|
|
|
|
collisiondetection = false,
|
|
|
|
texture = "shooter_flare_particle.png",
|
|
|
|
glow = 14,
|
|
|
|
})
|
2016-09-25 16:46:30 +00:00
|
|
|
meta:set_int("particle_id", id)
|
|
|
|
meta:set_int("init_time", os.time())
|
2014-07-26 20:18:10 +00:00
|
|
|
local sound = minetest.sound_play("shooter_flare_burn", {
|
2019-03-15 17:55:37 +00:00
|
|
|
pos = pos,
|
2014-07-26 20:18:10 +00:00
|
|
|
loop = true,
|
2019-03-15 17:55:37 +00:00
|
|
|
max_hear_distance = 8,
|
2014-07-26 20:18:10 +00:00
|
|
|
})
|
|
|
|
minetest.after(30, function(sound)
|
|
|
|
minetest.sound_stop(sound)
|
|
|
|
end, sound)
|
|
|
|
end
|
|
|
|
self.object:remove()
|
|
|
|
end
|
|
|
|
self.timer = 0
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
get_staticdata = function(self)
|
|
|
|
return "expired"
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2017-07-13 12:33:00 +00:00
|
|
|
minetest.register_tool("shooter_flaregun:flaregun", {
|
2014-07-26 20:18:10 +00:00
|
|
|
description = "Flare Gun",
|
|
|
|
inventory_image = "shooter_flaregun.png",
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
local inv = user:get_inventory()
|
2017-07-13 12:33:00 +00:00
|
|
|
if not inv:contains_item("main", "shooter_flaregun:flare") then
|
2014-07-26 20:18:10 +00:00
|
|
|
minetest.sound_play("shooter_click", {object=user})
|
|
|
|
return itemstack
|
|
|
|
end
|
|
|
|
if not minetest.setting_getbool("creative_mode") then
|
|
|
|
inv:remove_item("main", "shooter:flare 1")
|
2019-03-15 17:55:37 +00:00
|
|
|
itemstack:add_wear(65535 / 100)
|
2014-07-26 20:18:10 +00:00
|
|
|
end
|
2019-03-15 17:55:37 +00:00
|
|
|
local pos = user:get_pos()
|
2014-07-26 20:18:10 +00:00
|
|
|
local dir = user:get_look_dir()
|
2019-03-15 17:55:37 +00:00
|
|
|
local yaw = user:get_look_horizontal()
|
2014-07-26 20:18:10 +00:00
|
|
|
if pos and dir and yaw then
|
|
|
|
pos.y = pos.y + 1.5
|
2017-07-13 12:33:00 +00:00
|
|
|
local obj = minetest.add_entity(pos, "shooter_flaregun:flare_entity")
|
2014-07-26 20:18:10 +00:00
|
|
|
if obj then
|
|
|
|
minetest.sound_play("shooter_flare_fire", {object=obj})
|
2019-03-15 17:55:37 +00:00
|
|
|
obj:set_velocity(vector.multiply(dir, 16))
|
|
|
|
obj:set_acceleration({x=dir.x * -3, y=-10, z=dir.z * -3})
|
|
|
|
obj:set_yaw(yaw + math.pi / 2)
|
2014-07-26 20:18:10 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return itemstack
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2018-01-05 20:02:18 +00:00
|
|
|
if shooter.config.enable_crafting == true then
|
2014-07-26 20:18:10 +00:00
|
|
|
minetest.register_craft({
|
2017-07-13 12:33:00 +00:00
|
|
|
output = "shooter_flaregun:flare",
|
2014-07-26 20:18:10 +00:00
|
|
|
recipe = {
|
|
|
|
{"tnt:gunpowder", "wool:red"},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
minetest.register_craft({
|
2017-07-13 12:33:00 +00:00
|
|
|
output = "shooter_flaregun:flaregun",
|
2014-07-26 20:18:10 +00:00
|
|
|
recipe = {
|
|
|
|
{"wool:red", "wool:red", "wool:red"},
|
|
|
|
{"", "", "default:steel_ingot"}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2017-07-13 12:33:00 +00:00
|
|
|
--Backwards compatibility
|
|
|
|
minetest.register_alias("shooter:flaregun", "shooter_flaregun:flaregun")
|
|
|
|
minetest.register_alias("shooter:flare", "shooter_flaregun:flare")
|