More minor corrections

This commit is contained in:
stujones11 2019-03-24 15:06:10 +00:00
parent 70dac6ef64
commit 20405958da
2 changed files with 16 additions and 11 deletions

View file

@ -155,6 +155,11 @@ Used by `shooter.register_weapon`
description = "My Awesome Gun (Unloaded)",
inventory_image = "my_awesome_gun_unloaded.png",
},
on_use = function(itemstack, user, pointed_thing)
-- Called before the built-in tool `one_use` handler
-- Should return a valid `ItemStack` or `nil` to cancel the shot
return itemstack
end,
on_hit = function(pointed_thing, spec, dir)
-- May be used for arbitary shot effects like knock-back, etc.
-- Return `true` to override built-in damage effects

View file

@ -59,7 +59,6 @@ local config = shooter.config
local server_step = minetest.settings:get("dedicated_server_step")
shooter.register_weapon = function(name, def)
shooter.registered_weapons[name] = def
-- Fix definition table
def.sounds = def.sounds or {}
def.sounds.reload = def.sounds.reload or "shooter_reload"
@ -73,6 +72,7 @@ shooter.register_weapon = function(name, def)
description = def.description.." (unloaded)",
inventory_image = def.inventory_image,
}
shooter.registered_weapons[name] = table.copy(def)
-- Register loaded item tool
minetest.register_tool(name.."_loaded", {
description = def.description,
@ -81,6 +81,7 @@ shooter.register_weapon = function(name, def)
if type(def.on_use) == "function" then
itemstack = def.on_use(itemstack, user, pointed_thing)
end
if itemstack then
local spec = table.copy(def.spec)
if shooter.fire_weapon(user, itemstack, spec) then
itemstack:add_wear(def.spec.wear)
@ -88,6 +89,7 @@ shooter.register_weapon = function(name, def)
itemstack:replace(def.unloaded_item.name)
end
end
end
return itemstack
end,
on_hit = def.on_hit,
@ -175,6 +177,9 @@ shooter.is_valid_object = function(object)
end
shooter.punch_node = function(pos, spec)
if config.enable_protection and minetest.is_protected(pos, spec.user) then
return
end
local node = minetest.get_node(pos)
if not node then
return
@ -183,11 +188,6 @@ shooter.punch_node = function(pos, spec)
if not item then
return
end
if config.enable_protection then
if minetest.is_protected(pos, spec.user) then
return
end
end
if item.groups then
for k, v in pairs(spec.groups) do
local level = item.groups[k] or 0