Improve api, respect entity on_blast callbacks

This commit is contained in:
stujones11 2019-03-23 19:17:18 +00:00
parent b5984a231f
commit 0eb5049218
2 changed files with 48 additions and 29 deletions

View file

@ -10,11 +10,11 @@ Crafting
### Gunpowder
1 x Coal Lump + 1 x Clay Lump = 5 x Gunpowder (shapeless)
1 x Coal Lump + 1 x Clay Lump = 5 x Gunpowder
```
output = "shooter:gunpowder 5",
type = "shapeless",
recipe = {"default:coal_lump", "default:clay_lump"},
output = "shooter:gunpowder 5",
type = "shapeless",
recipe = {"default:coal_lump", "default:clay_lump"},
```
Configuration
-------------
@ -119,8 +119,14 @@ API Documentation
* `shooter.spawn_particles(pos, particles)`: Adds particles at the specified position
* `particles` is an optional table of overrides for `shooter.default_particles`
* `shooter.play_node_sound(node, pos)`: Plays the registered 'dug' sound for the node at `pos`
* `shooter.punch_node(pos, spec)`: Punches the node at `pos` with the `spec` group capabilities
* `shooter.is_valid_object(object)`: Returns `true` if the object can be damaged
* `shooter.punch_node(pos, spec)`: Punches the node at `pos` with the `spec` group capabilities
* `shooter.punch_object(object, tool_caps, dir, on_blast)`: Punches the object
* Returns `true` if the object is damaged
* `object`: Object to punched, not checked for validity!
* `tool_caps`: Tool capabilities of the weapon uesd -- See "Weapon Definition"
* `dir`: Unit vector pointing from the source of the punch to the object
* `on_blast`: Respect entity `on_blast` damage callback
* `shooter.fire_weapon(player, itemstack, spec)`: Adds a 'round' with `spec` to the processing que
* `shooter.blast(pos, radius, fleshy, distance, user)`: Create explosion at `pos`
* `radius`: Blast radius in nodes
@ -156,7 +162,7 @@ Used by `shooter.register_weapon`
-- `name`: Name of the weapon item, eg. `shooter_guns:rifle`
-- `user`: Name of the player that fired the weapon
-- `origin`: Initial starting position of the shot
-- `dir`: Direction of the virtual shot before impact
-- `dir`: Unit vector direction of the virtual shot before impact
end,
spec = {
-- Weapon specifications

View file

@ -160,6 +160,20 @@ shooter.play_node_sound = function(node, pos)
end
end
shooter.is_valid_object = function(object)
if object then
if object:is_player() == true then
return config.allow_players
end
if config.allow_entities == true then
local luaentity = object:get_luaentity()
if luaentity then
return luaentity.name ~= "__builtin:item"
end
end
end
end
shooter.punch_node = function(pos, spec)
local node = minetest.get_node(pos)
if not node then
@ -185,24 +199,25 @@ shooter.punch_node = function(pos, spec)
shooter.spawn_particles(pos, {texture=item.tiles[1]})
end
end
break
return true
end
end
end
end
shooter.is_valid_object = function(object)
if object then
if object:is_player() == true then
return config.allow_players
end
if config.allow_entities == true then
local luaentity = object:get_luaentity()
if luaentity then
return luaentity.name ~= "__builtin:item"
end
shooter.punch_object = function(object, tool_caps, dir, on_blast)
local do_damage = true
if on_blast then
local ent = object:get_luaentity()
local def = minetest.registered_entities[ent.name]
if def.on_blast then
do_damage = def.on_blast(ent, tool_caps.fleshy)
end
end
if do_damage then
object:punch(object, nil, tool_caps, dir)
return true
end
end
local function process_hit(pointed_thing, spec, dir)
@ -217,15 +232,12 @@ local function process_hit(pointed_thing, spec, dir)
shooter.punch_node(pos, spec)
elseif pointed_thing.type == "object" then
local object = pointed_thing.ref
if shooter.is_valid_object(object) == true then
local player = minetest.get_player_by_name(spec.user)
if player then
object:punch(player, nil, spec.tool_caps, dir)
local pos = pointed_thing.intersection_point or object:get_pos()
local groups = object:get_armor_groups() or {}
if groups.fleshy then
shooter.spawn_particles(pos, spec.particles)
end
if shooter.is_valid_object(object) and
shooter.punch_object(object, spec.tool_caps, dir) then
local pos = pointed_thing.intersection_point or object:get_pos()
local groups = object:get_armor_groups() or {}
if groups.fleshy then
shooter.spawn_particles(pos, spec.particles)
end
end
end
@ -364,11 +376,12 @@ shooter.blast = function(pos, radius, fleshy, distance, user)
if dist ~= 0 then
obj_pos.y = obj_pos.y + 1
local blast_pos = {x=pos.x, y=pos.y + 4, z=pos.z}
if minetest.line_of_sight(obj_pos, blast_pos, 1) then
obj:punch(user, 1.0, {
if shooter.is_valid_object(obj) and
minetest.line_of_sight(obj_pos, blast_pos, 1) then
shooter.punch_object(obj, {
full_punch_interval = 1.0,
damage_groups = {fleshy=damage},
})
}, nil, true)
end
end
end