-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathnssm_spears.lua
258 lines (231 loc) · 7.69 KB
/
nssm_spears.lua
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
--function
function spears_shot (itemstack, player)
local spear = itemstack:get_name() .. '_entity'
local playerpos = player:getpos()
local obj = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, spear)
local dir = player:get_look_dir()
if spear == "nssm:spear_of_peace_entity" then
sp = 32
gravity = 9.8
else
sp = 16
gravity = 9.8
end
local dr = .3
obj:setvelocity({x=dir.x*sp, y=dir.y*sp, z=dir.z*sp})
obj:setacceleration({x=-dir.x*dr, y=-gravity, z=-dir.z*dr})
obj:setyaw(player:get_look_yaw()+math.pi)
minetest.sound_play("spears_sound", {pos=playerpos})
obj:get_luaentity().wear = itemstack:get_wear()
return true
end
function spears_set_entity(kind, eq, toughness)
local SPEAR_ENTITY={
physical = false,
timer=0,
visual = "wielditem",
visual_size = {x=0.15, y=0.1},
textures = {"nssm:spear_" .. kind},
lastpos={},
collisionbox = {0,0,0,0,0,0},
on_punch = function(self, puncher)
if puncher then
if puncher:is_player() then
local stack = {name='nssm:spear_' .. kind, wear=self.wear+65535/toughness}
local inv = puncher:get_inventory()
if inv:room_for_item("main", stack) then
inv:add_item("main", stack)
self.object:remove()
end
end
end
end,
}
SPEAR_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime
local pos = self.object:getpos()
local node = minetest.get_node(pos)
if not self.wear then
self.object:remove()
return
end
if self.lastpos.x~=nil then
if node.name ~= "air" and not (string.find(node.name, 'grass') and not string.find(node.name, 'dirt')) and not string.find(node.name, 'flowers:') and not string.find(node.name, 'farming:') then
self.object:remove()
if self.wear+65535/toughness < 65535 then
minetest.add_item(self.lastpos, {name='nssm:spear_' .. kind, wear=self.wear+65535/toughness})
end
elseif self.timer>0.2 then
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1)
for k, obj in pairs(objs) do
if obj:get_luaentity() ~= nil then
if obj:get_luaentity().name ~= "nssm:spear_" .. kind .. "_entity" and obj:get_luaentity().name ~= "__builtin:item" then
local speed = vector.length(self.object:getvelocity())
local damage = (speed + eq)^1.12-20
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=damage},
}, nil)
self.object:remove()
if self.wear+65535/toughness < 65535 then
minetest.add_item(self.lastpos, {name='nssm:spear_' .. kind, wear=self.wear+65535/toughness})
end
end
end
end
end
end
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
end
return SPEAR_ENTITY
end
--Tools
function spears_register_spear(kind, desc, eq, toughness, material)
minetest.register_tool("nssm:spear_" .. kind, {
description = desc .. " Spear",
wield_image = "spear_" .. kind .. ".png",
inventory_image = "spear_" .. kind .. ".png^[transform4",
wield_scale= {x=2,y=1,z=1},
on_drop = function(itemstack, user, pointed_thing)
spears_shot(itemstack, user)
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
end
return itemstack
end,
on_place = function(itemstack, user, pointed_thing)
minetest.add_item(pointed_thing.above, itemstack)
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
end
return itemstack
end,
tool_capabilities = {
full_punch_interval = 1.3,
max_drop_level=1,
groupcaps={
snappy = {times={[3]=0.2, [2]=0.2, [1]=0.2}, uses=toughness, maxlevel=1},
},
damage_groups = {fleshy=eq},
}
})
SPEAR_ENTITY=spears_set_entity(kind, eq, toughness)
minetest.register_entity("nssm:spear_" .. kind .. "_entity", SPEAR_ENTITY)
minetest.register_craft({
output = 'nssm:spear_' .. kind,
recipe = {
{'group:wood', 'group:wood', material},
}
})
minetest.register_craft({
output = 'nssm:spear_' .. kind,
recipe = {
{material, 'group:wood', 'group:wood'},
}
})
end
spears_register_spear('ant', 'Ant', 6, 25, 'nssm:ant_mandible')
spears_register_spear('mantis', 'Mantis', 6, 10, 'nssm:mantis_claw')
spears_register_spear('manticore', 'Manticore', 8, 8, 'nssm:manticore_spine')
spears_register_spear('ice_tooth', 'Ice Tooth', 16, 200, 'nssm:ice_tooth')
spears_register_spear('little_ice_tooth', 'Little Ice Tooth', 7, 10, 'nssm:little_ice_tooth')
spears_register_spear('duck_beak', 'Duck Beak', 5, 6, 'nssm:duck_beak')
spears_register_spear('felucco_horn', 'Felucco Horn', 7, 9, 'nssm:felucco_horn')
--Spear of peace
minetest.register_tool("nssm:spear_of_peace", {
description = "Spear of Peace",
wield_image = "spear_of_peace.png",
inventory_image = "spear_of_peace.png^[transform4",
wield_scale= {x=4,y=2,z=2},
on_drop = function(itemstack, user, pointed_thing)
spears_shot(itemstack, user)
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
end
return itemstack
end,
on_place = function(itemstack, user, pointed_thing)
minetest.add_item(pointed_thing.above, itemstack)
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
end
return itemstack
end,
tool_capabilities = {
full_punch_interval = 0.7,
max_drop_level=1,
groupcaps={
snappy = {times={[3]=0.2, [2]=0.2, [1]=0.2}, uses=500, maxlevel=1},
},
damage_groups = {fleshy=18},
}
})
function spears_set_sentity(kind, eq, toughness)
local SUPERSPEAR_ENTITY={
physical = false,
timer=0,
visual = "wielditem",
visual_size = {x=0.15, y=0.1},
textures = {"nssm:spear_" .. kind},
lastpos={},
collisionbox = {0,0,0,0,0,0},
on_punch = function(self, puncher)
if puncher then
if puncher:is_player() then
local stack = {name='nssm:spear_' .. kind, wear=self.wear+65535/toughness}
local inv = puncher:get_inventory()
if inv:room_for_item("main", stack) then
inv:add_item("main", stack)
self.object:remove()
end
end
end
end,
}
SUPERSPEAR_ENTITY.on_step = function(self, dtime)
self.timer=self.timer+dtime
local pos = self.object:getpos()
local node = minetest.get_node(pos)
if not self.wear then
self.object:remove()
return
end
if self.lastpos.x~=nil then
if node.name ~= "air" and not (string.find(node.name, 'grass') and not string.find(node.name, 'dirt')) and not string.find(node.name, 'flowers:') and not string.find(node.name, 'farming:') then
self.object:remove()
if self.wear+65535/toughness < 65535 then
minetest.add_item(self.lastpos, {name='nssm:spear_' .. kind, wear=self.wear+65535/toughness})
end
elseif self.timer>0.2 then
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1)
for k, obj in pairs(objs) do
if obj:get_luaentity() ~= nil then
if obj:get_luaentity().name ~= "nssm:spear_" .. kind .. "_entity" and obj:get_luaentity().name ~= "__builtin:item" then
local speed = vector.length(self.object:getvelocity())
--minetest.chat_send_all(speed)
local damage = (speed + eq)^1.12-20
obj:punch(self.object, 1.0, {
full_punch_interval=1.0,
damage_groups={fleshy=damage},
}, nil)
self.object:remove()
if self.wear+65535/toughness < 65535 then
minetest.add_item(self.lastpos, {name='nssm:spear_' .. kind, wear=self.wear+65535/toughness})
end
end
end
end
end
end
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
end
return SUPERSPEAR_ENTITY
end
SUPERSPEAR_ENTITY=spears_set_sentity("of_peace", 30, 300)
minetest.register_entity("nssm:spear_of_peace_entity", SUPERSPEAR_ENTITY)
minetest.register_craft({
output = 'nssm:spear_of_peace',
recipe = {
{'nssm:wrathful_moranga', 'group:wood', 'group:wood'},
}
})