-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrow.lua
More file actions
114 lines (104 loc) · 3.61 KB
/
arrow.lua
File metadata and controls
114 lines (104 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
minetest.register_craftitem("archer:arrow", {
description = "Arrow",
inventory_image = "archer_arrow.png",
})
-- The arrow appearance
minetest.register_node("archer:arrow_box", {
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
-- Shaft
{-6.5/17, -1.5/17, -1.5/17, 6.5/17, 1.5/17, 1.5/17},
-- Spitze
{-4.5/17, 2.5/17, 2.5/17, -3.5/17, -2.5/17, -2.5/17},
{-8.5/17, 0.5/17, 0.5/17, -6.5/17, -0.5/17, -0.5/17},
-- Federn
{6.5/17, 1.5/17, 1.5/17, 7.5/17, 2.5/17, 2.5/17},
{7.5/17, -2.5/17, 2.5/17, 6.5/17, -1.5/17, 1.5/17},
{7.5/17, 2.5/17, -2.5/17, 6.5/17, 1.5/17, -1.5/17},
{6.5/17, -1.5/17, -1.5/17, 7.5/17, -2.5/17, -2.5/17},
{7.5/17, 2.5/17, 2.5/17, 8.5/17, 3.5/17, 3.5/17},
{8.5/17, -3.5/17, 3.5/17, 7.5/17, -2.5/17, 2.5/17},
{8.5/17, 3.5/17, -3.5/17, 7.5/17, 2.5/17, -2.5/17},
{7.5/17, -2.5/17, -2.5/17, 8.5/17, -3.5/17, -3.5/17},
}
},
tiles = {"archer_arrow.png", "archer_arrow.png", "archer_arrow_back.png", "archer_arrow_front.png", "archer_arrow_2.png", "archer_arrow.png"},
groups = {not_in_creative_inventory = 1},
})
local ARCHER_ARROW_ENTITY = {
physical = false,
timer = 0,
visual = "wielditem",
visual_size = {x = 0.125, y = 0.125},
textures = {"archer:arrow_box"},
lastpos= {},
collisionbox = {0, 0, 0, 0, 0, 0},
}
ARCHER_ARROW_ENTITY.on_step = function(self, dtime)
-- Renew timer
self.timer = self.timer + dtime
-- Get arrow's position
local pos = self.object:getpos()
-- Get current arrow's position node
local node = minetest.get_node(pos)
-- Let 200 milliseconds for the arrow to leave the player
if self.timer > 0.2 then
-- Get an array of the objects that exist 1 block around the arrow
local objs = minetest.get_objects_inside_radius({x = pos.x, y = pos.y, z = pos.z}, 1)
-- Loop through the objects
for k, obj in pairs(objs) do
-- If the object is not player..
if obj:get_luaentity() ~= nil then
-- If the object is not arrow && is not something thrown down..
if obj:get_luaentity().name ~= "archer:arrow_entity" and obj:get_luaentity().name ~= "__builtin:item" then
local damage = 1
-- Use the punch method on the object to cause damage
obj:punch(self.object, 1.0, {
-- Guess: it means it can't cause damage more often than every 1 second
full_punch_interval = 1.0,
-- Guess: It damages only monsters, animals etc. (1 point)
damage_groups= {fleshy = damage},
}, nil)
minetest.sound_play("archer_arrow", {pos = self.lastpos, gain = 0.8})
self.object:remove()
end
else
-- It is player so cause damage exactly as at the previous lines
local damage = 1
obj:punch(self.object, 1.0, {
full_punch_interval = 1.0,
damage_groups= {fleshy = damage},
}, nil)
minetest.sound_play("archer_arrow", {pos = self.lastpos, gain = 0.8})
self.object:remove()
end
end
end
if self.lastpos.x ~= nil then
-- If not in creative mode don't disappear the arrow after the use. Throw it down
if minetest.registered_nodes[node.name].walkable then
-- if not minetest.setting_getbool("creative_mode") then
-- minetest.add_item(self.lastpos, "archer:arrow")
-- end
minetest.sound_play("archer_arrow", {pos = self.lastpos, gain = 0.8})
self.object:remove()
end
end
-- Record the last position
self.lastpos= {x = pos.x, y = pos.y, z = pos.z}
end
minetest.register_entity("archer:arrow_entity", ARCHER_ARROW_ENTITY)
minetest.register_craft({
output = "archer:arrow 16",
recipe = {
{"default:cobble", "group:stick", "group:stick"},
}
})
minetest.register_craft({
output = "archer:arrow 16",
recipe = {
{"group:stick", "group:stick", "default:cobble"},
}
})