mirror of
https://github.com/minetest-mods/throwing.git
synced 2025-01-09 17:50:25 +01:00
Allow external mod to choose the bow/arrow prefix
This commit is contained in:
parent
1778b89597
commit
a45399bfea
@ -30,7 +30,7 @@ There are two available functions in the mod API:
|
|||||||
```lua
|
```lua
|
||||||
function throwing.register_bow(name, definition)
|
function throwing.register_bow(name, definition)
|
||||||
--[[
|
--[[
|
||||||
Name: Bow name (in second part of the itemstring).
|
Name: Bow name. If it doesn't contain ":", the "throwing:" prefix will be added.
|
||||||
Definition: definition table, containing:
|
Definition: definition table, containing:
|
||||||
* itemcraft (optional, you may want to register your own craft or to make the bow uncraftable): item used to craft the bow.
|
* itemcraft (optional, you may want to register your own craft or to make the bow uncraftable): item used to craft the bow.
|
||||||
* description (highly recommended): description of the bow.
|
* description (highly recommended): description of the bow.
|
||||||
@ -53,7 +53,7 @@ throwing.register_bow("bow_wood", {
|
|||||||
itemcraft, craft_quantity, description, tiles, on_hit_sound, on_hit[, on_throw[, groups]]
|
itemcraft, craft_quantity, description, tiles, on_hit_sound, on_hit[, on_throw[, groups]]
|
||||||
function throwing.register_arrow(name, definition table)
|
function throwing.register_arrow(name, definition table)
|
||||||
--[[
|
--[[
|
||||||
Name: Arrow name (in second part of the itemstring).
|
Name: Arrow name. If it doesn't contain ":", the "throwing:" prefix will be added.
|
||||||
Definition: definition table, containing:
|
Definition: definition table, containing:
|
||||||
* itemcraft (optional, you may want to register your own craft or to make the arrow uncraftable): item used to craft the arrow.
|
* itemcraft (optional, you may want to register your own craft or to make the arrow uncraftable): item used to craft the arrow.
|
||||||
* craft_quantity (optional, defaulting to 1 if itemcraft is non-nil, pointless otherwise): quantity of arrows in the craft output.
|
* craft_quantity (optional, defaulting to 1 if itemcraft is non-nil, pointless otherwise): quantity of arrows in the craft output.
|
||||||
|
16
init.lua
16
init.lua
@ -187,7 +187,11 @@ on_throw(pos, hitter)
|
|||||||
Unlike on_hit, it is optional.
|
Unlike on_hit, it is optional.
|
||||||
]]
|
]]
|
||||||
function throwing.register_arrow(name, def)
|
function throwing.register_arrow(name, def)
|
||||||
table.insert(throwing.arrows, throwing.modname..":"..name)
|
if not string.find(name, ":") then
|
||||||
|
name = throwing.modname..":"..name
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(throwing.arrows, name)
|
||||||
|
|
||||||
local groups = {dig_immediate = 3}
|
local groups = {dig_immediate = 3}
|
||||||
if def.groups then
|
if def.groups then
|
||||||
@ -195,7 +199,7 @@ function throwing.register_arrow(name, def)
|
|||||||
groups[k] = v
|
groups[k] = v
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
minetest.register_node(throwing.modname..":"..name, {
|
minetest.register_node(name, {
|
||||||
drawtype = "nodebox",
|
drawtype = "nodebox",
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
node_box = {
|
node_box = {
|
||||||
@ -241,7 +245,7 @@ function throwing.register_arrow(name, def)
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_entity(throwing.modname..":"..name.."_entity", {
|
minetest.register_entity(name.."_entity", {
|
||||||
physical = false,
|
physical = false,
|
||||||
timer = 0,
|
timer = 0,
|
||||||
visual = "wielditem",
|
visual = "wielditem",
|
||||||
@ -280,12 +284,16 @@ end
|
|||||||
|
|
||||||
---------- Bows -----------
|
---------- Bows -----------
|
||||||
function throwing.register_bow(name, def)
|
function throwing.register_bow(name, def)
|
||||||
|
if not string.find(name, ":") then
|
||||||
|
name = throwing.modname..":"..name
|
||||||
|
end
|
||||||
|
|
||||||
if not def.allow_shot then
|
if not def.allow_shot then
|
||||||
def.allow_shot = function(player, itemstack)
|
def.allow_shot = function(player, itemstack)
|
||||||
return throwing.is_arrow(itemstack)
|
return throwing.is_arrow(itemstack)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
minetest.register_tool(throwing.modname..":"..name, {
|
minetest.register_tool(name, {
|
||||||
description = def.description,
|
description = def.description,
|
||||||
inventory_image = def.texture,
|
inventory_image = def.texture,
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
|
Loading…
Reference in New Issue
Block a user