Update throwing & throwing_arrows

master
upsilon 2019-08-30 17:38:36 +02:00
parent 68e1d25c55
commit 0277ffacd8
No known key found for this signature in database
GPG Key ID: A80DAE1F266E1C3C
15 changed files with 57 additions and 23 deletions

View File

@ -1,12 +1,12 @@
# Throwing
## Developped by the Mynetest team
## Developed by the Eurythmia team
This mod is an API for registering throwing and throwable things.
Mods based on this API:
* [throwing_arrows](https://github.com/MT-Eurythmia/throwing_arrows) is a compatible replacement for the throwing mod by PilzAdam.
* [sling](https://github.com/tacotexmex/sling) is a mod written by @tacotexmex that enables item stack and single item throwing of any item.
* [throwing_arrows](https://github.com/minetest-mods/throwing_arrows) is a compatible replacement for the throwing mod by PilzAdam.
* [sling](https://github.com/minetest-mods/sling) is a mod written by @tacotexmex that enables item stack and single item throwing of any item.
## Configuration
@ -46,6 +46,8 @@ Definition: definition table, containing:
* throw_itself (optional): whether the bow should throw itself instead of the arrow next to it in the inventory.
If present, allow_shot is ignored.
Default is false.
*Warning*: this field is not known to be currently used by a mod. If you encounter bugs using it, please open
an issue!
* cooldown: bow cooldown. Default is setting throwing.bow_cooldown
* function spawn_arrow_entity(position, arrow, player): defaults to throwing.spawn_arrow_entity
* sound: sound to be played when the bow is used
@ -108,6 +110,6 @@ throwing.register_arrow("arrow", {
})
```
If the item to throw is an arrow registered using `minetest.register_arrow`, the entity used will be the registered entity.
Otherwise, if its definition contains a `throwing_entity` field, this field will be used as the entity name if it is a string, otherwise it will be called as a function(pos, player) that has to make the object to spawn and to return the corresponding ObjectRef.
If the item is neither an arrow nor has any `throwing_entity` field, the corresponding `__builtin:item` will be used.
If the item to throw is an arrow registered using `throwing.register_arrow`, the entity used will be the entity automatically registered by this function.
Otherwise, if its definition contains a `throwing_entity` field, this field will be used as the entity name if it is a string, otherwise it will be called as a `function(pos, player)` that has to spawn the object and return the corresponding ObjectRef.
If the item is neither an arrow nor has a `throwing_entity` field, the corresponding `__builtin:item` will be used.

View File

@ -1,2 +1 @@
mesecons?
mesecons_button?
wielded_light?

View File

@ -10,12 +10,7 @@ throwing.modname = minetest.get_current_modname()
--------- Arrows functions ---------
function throwing.is_arrow(itemstack)
for _, arrow in ipairs(throwing.arrows) do
if (type(itemstack) == "string" and itemstack or itemstack:get_name()) == arrow then
return true
end
end
return false
return throwing.arrows[ItemStack(itemstack):get_name()]
end
function throwing.spawn_arrow_entity(pos, arrow, player)
@ -165,7 +160,7 @@ local function arrow_step(self, dtime)
self.object:remove()
logging("reached ignore. Removing.")
return
elseif node.name ~= "air" then
elseif (minetest.registered_items[node.name] or {}).drawtype ~= "airlike" then
if self.target ~= throwing.target_object then -- throwing.target_both, nil, throwing.target_node, or any invalid value
if hit(pos, node, nil) ~= false then
self.object:remove()
@ -200,6 +195,10 @@ local function arrow_step(self, dtime)
end
end
-- Support for shining items using wielded light
if minetest.global_exists("wielded_light") and self.object then
wielded_light.update_light_by_item(self.item, self.object:get_pos())
end
self.last_pos = pos -- Used by the build arrow
end
@ -222,7 +221,7 @@ on_throw(pos, hitter)
Unlike on_hit, it is optional.
]]
function throwing.register_arrow(name, def)
table.insert(throwing.arrows, name)
throwing.arrows[name] = true
local registration_name = name
if name:sub(1,9) == "throwing:" then

View File

@ -1 +1,3 @@
name = throwing
optional_depends = wielded_light
description = Throwing library: provides an API for registering throwing and throwable things

View File

@ -8,6 +8,7 @@ The settings are the following:
```
throwing.enable_arrow = true
throwing.enable_golden_arrow = true
throwing.enable_diamond_arrow = true
throwing.enable_fire_arrow = true
throwing.enable_teleport_arrow = true
throwing.enable_dig_arrow = true

View File

@ -63,6 +63,7 @@ if get_setting("arrow") then
if object then
object:punch(hitter, 1, {
full_punch_interval = 1,
max_drop_level = 1,
damage_groups = {fleshy = 3}
})
elseif node then
@ -86,12 +87,32 @@ if get_setting("golden_arrow") then
on_hit = function(self, pos, _, _, object, hitter)
object:punch(hitter, 1, {
full_punch_interval = 1,
max_drop_level = 1,
damage_groups = {fleshy = 5}
})
end
})
end
if get_setting("diamond_arrow") then
throwing.register_arrow("throwing:arrow_diamond", {
itemcraft = "default:diamond",
craft_quantity = 4,
description = "Diamond Arrow",
tiles = {"throwing_arrow_diamond.png", "throwing_arrow_diamond.png", "throwing_arrow_diamond_back.png", "throwing_arrow_diamond_front.png", "throwing_arrow_diamond_2.png", "throwing_arrow_diamond.png"},
target = throwing.target_object,
allow_protected = true,
on_hit_sound = "throwing_arrow",
on_hit = function(self, pos, _, _, object, hitter)
object:punch(hitter, 1, {
full_punch_interval = 1,
max_drop_level = 1,
damage_groups = {fleshy = 7}
})
end
})
end
if get_setting("dig_arrow") then
throwing.register_arrow("throwing:arrow_dig", {
itemcraft = "default:pick_wood",
@ -119,7 +140,7 @@ end
if get_setting("teleport_arrow") then
throwing.register_arrow("throwing:arrow_teleport", {
itemcraft = "default:diamond",
itemcraft = "default:mese_crystal",
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,
@ -173,17 +194,24 @@ if get_setting("build_arrow") then
description = "Build Arrow",
tiles = {"throwing_arrow_build.png", "throwing_arrow_build.png", "throwing_arrow_build_back.png", "throwing_arrow_build_front.png", "throwing_arrow_build_2.png", "throwing_arrow_build.png"},
on_hit_sound = "throwing_build_arrow",
on_hit = function(self, _, last_pos, _, _, hitter)
on_hit = function(self, pos, last_pos, _, _, hitter)
if minetest.get_node(last_pos).name ~= "air" then
minetest.log("warning", "[throwing] BUG: node at last_pos was not air")
return
end
local playername = hitter:get_player_name()
if minetest.is_protected(last_pos, playername) then
minetest.record_protection_violation(last_pos, playername)
return false, "protected position"
local r_pos = vector.round(pos)
local r_last_pos = vector.round(last_pos)
-- Make sure that only one key is different
if r_pos.y ~= r_last_pos.y then
r_last_pos.x = r_pos.x
r_last_pos.z = r_pos.z
elseif r_pos.x ~= r_last_pos.x then
r_last_pos.y = r_pos.y
r_last_pos.z = r_pos.z
end
return minetest.place_node(last_pos, {name="default:obsidian_glass"})
minetest.registered_items["default:obsidian_glass"].on_place(ItemStack("default:obsidian_glass"), hitter,
{type="node", under=r_pos, above=r_last_pos})
end
})
end

View File

@ -1 +1,4 @@
name = throwing_arrows
depends = throwing, default
optional_depends = mesecons, mesecons_button
description = Bows and Arrows for the throwing mod

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 139 B

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 141 B

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 141 B

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 119 B

After

Width:  |  Height:  |  Size: 1.7 KiB