mirror of
https://github.com/minetest-mods/throwing.git
synced 2024-11-14 06:30:22 +01:00
Add a allow_protected definition parameter
This commit is contained in:
parent
33bc0b5f69
commit
4fe2a0c88c
|
@ -21,6 +21,7 @@ throwing.horizontal_acceleration_factor = -3
|
|||
throwing.vertical_acceleration = -10
|
||||
|
||||
throwing.allow_arrow_placing = false
|
||||
throwing.arrow_teleport_in_protected = true
|
||||
```
|
||||
|
||||
## API
|
||||
|
@ -53,6 +54,7 @@ Definition: definition table, containing:
|
|||
* craft_quantity (optional, defaulting to 1 if itemcraft is non-nil, pointless otherwise): quantity of arrows in the craft output.
|
||||
* tiles (essential): tiles of the arrow.
|
||||
* target (optional, defaulting to throwing.target_both): what the arrow is able to hit (throwing.target_node, throwing.target_object, throwing.target_both).
|
||||
* allow_protected (optional, defaulting to false): whether the arrow can be throw in a protected area
|
||||
* on_hit_sound (optional): sound played when the arrow hits a node or an object.
|
||||
* on_hit(pos, last_pos, node, object, hitter, data, self) (must exist, will crash if nil): callback function:
|
||||
- pos: the position of the hit node or object.
|
||||
|
|
3
init.lua
3
init.lua
|
@ -88,7 +88,7 @@ local function arrow_step(self, dtime)
|
|||
return
|
||||
end
|
||||
|
||||
if node and minetest.is_protected(pos, self.player) then -- Forbid hitting nodes in protected areas
|
||||
if node and minetest.is_protected(pos, self.player) and not self.allow_protected then -- Forbid hitting nodes in protected areas
|
||||
minetest.record_protection_violation(pos, self.player)
|
||||
logging("hitted a node into a protected area")
|
||||
return
|
||||
|
@ -241,6 +241,7 @@ function throwing.register_arrow(name, def)
|
|||
on_hit_sound = def.on_hit_sound,
|
||||
on_throw_sound = def.on_throw_sound,
|
||||
on_throw = def.on_throw,
|
||||
allow_protected = def.allow_protected,
|
||||
target = def.target,
|
||||
on_hit_fails = def.on_hit_fails,
|
||||
node = throwing.modname..":"..name,
|
||||
|
|
|
@ -45,6 +45,7 @@ if get_setting("arrow") then
|
|||
description = "Arrow",
|
||||
tiles = {"throwing_arrow.png", "throwing_arrow.png", "throwing_arrow_back.png", "throwing_arrow_front.png", "throwing_arrow_2.png", "throwing_arrow.png"},
|
||||
target = throwing.target_both,
|
||||
allow_protected = true,
|
||||
on_hit_sound = "throwing_arrow",
|
||||
on_hit = function(pos, _, node, object, hitter)
|
||||
if object then
|
||||
|
@ -68,6 +69,7 @@ if get_setting("golden_arrow") then
|
|||
description = "Golden Arrow",
|
||||
tiles = {"throwing_arrow_gold.png", "throwing_arrow_gold.png", "throwing_arrow_gold_back.png", "throwing_arrow_gold_front.png", "throwing_arrow_gold_2.png", "throwing_arrow_gold.png"},
|
||||
target = throwing.target_object,
|
||||
allow_protected = true,
|
||||
on_hit_sound = "throwing_arrow",
|
||||
on_hit = function(pos, _, _, object, hitter)
|
||||
object:punch(hitter, 1, {
|
||||
|
@ -108,6 +110,7 @@ if get_setting("teleport_arrow") then
|
|||
itemcraft = "default:diamond",
|
||||
description = "Teleport Arrow",
|
||||
tiles = {"throwing_arrow_teleport.png", "throwing_arrow_teleport.png", "throwing_arrow_teleport_back.png", "throwing_arrow_teleport_front.png", "throwing_arrow_teleport_2.png", "throwing_arrow_teleport.png"},
|
||||
allow_protected = true,
|
||||
on_hit_sound = "throwing_teleport_arrow",
|
||||
on_hit = function(_, last_pos, _, _, hitter)
|
||||
if minetest.get_node(last_pos).name ~= "air" then
|
||||
|
@ -115,6 +118,10 @@ if get_setting("teleport_arrow") then
|
|||
return
|
||||
end
|
||||
|
||||
if minetest.setting_getbool("throwing.allow_teleport_in_protected") == false then
|
||||
return false
|
||||
end
|
||||
|
||||
hitter:moveto(last_pos)
|
||||
end
|
||||
})
|
||||
|
@ -170,6 +177,7 @@ if get_setting("drop_arrow") then
|
|||
description = "Drop Arrow",
|
||||
tiles = {"throwing_arrow_drop.png", "throwing_arrow_drop.png", "throwing_arrow_drop_back.png", "throwing_arrow_drop_front.png", "throwing_arrow_drop_2.png", "throwing_arrow_drop.png"},
|
||||
on_hit_sound = "throwing_build_arrow",
|
||||
allow_protected = true,
|
||||
on_throw = function(_, thrower, next_index, data)
|
||||
data.itemstack = thrower:get_inventory():get_stack("main", next_index)
|
||||
data.index = next_index
|
||||
|
|
Loading…
Reference in New Issue
Block a user