This file is indexed.

/usr/share/games/minetest/mods/animalmaterials/animal_resources/weapons.lua is in minetest-mod-animalmaterials 0.1.3-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
-------------------------------------------------------------------------------
-- Animal Resources Mod by Sapier
--
--! @file weapons.lua
--! @brief definition of some weapons used by animals modpack
--! @copyright Sapier
--! @author Sapier
--! @date 2012-08-09
--
--! @defgroup weapons Weapons
--! @brief weapon entitys examples used by animals modpack
--
-- Contact sapier a t gmx net
-------------------------------------------------------------------------------
assert(weapons_spacer == nil)
local weapons_spacer = {} --unused to fix lua doxygen bug only

-------------------------------------------------------------------------------
-- name: do_area_damage(pos,immune,damage_groups,range)
--
--! @brief damage all objects within a certain range
--
--! @param pos cennter of damage area
--! @param immune object immune to damage
--! @param damage_groups list of damage groups to do damage to
--! @param range range around pos
-------------------------------------------------------------------------------
local function do_area_damage(pos,immune,damage_groups,range)
	--damage objects within inner blast radius
	assert(type(range) ~= "table")

	local objs = minetest.get_objects_inside_radius(pos, range)
	for k, obj in pairs(objs) do

		--don't do damage to issuer
		if obj ~= immune and obj ~= nil then

			--TODO as long as minetest still crashes without puncher use this workaround

			local worst_damage = 0
			if type(damage_groups) == "table" then
				for k,v in pairs(damage_groups) do
					if v > worst_damage then
						worst_damage = v
					end
				end
			elseif type(damage_groups) == "number" then
				worst_damage =  damage_groups
			else
				assert("invalid damage_groups" == "selected")
			end


			local current_hp = obj:get_hp()
			obj:set_hp(current_hp - worst_damage)

			--punch
			--obj:punch(nil, 1.0, {
			--	full_punch_interval=1.0,
			--	damage_groups = damage_groups,
			--}, nil)
		end
	end
end


-------------------------------------------------------------------------------
-- name: do_node_damage(pos,immune_list,range,chance)
--
--! @brief damage all nodes within a certain range
--
--! @param pos center of area
--! @param immune_list list of nodes immune to damage
--! @param range range to do damage
--! @param chance chance damage is done to a node
-------------------------------------------------------------------------------
local function do_node_damage(pos,immune_list,range,chance)
	--do node damage
	for i=pos.x-range, pos.x+range, 1 do
		for j=pos.y-range, pos.y+range, 1 do
			for k=pos.z-range,pos.z+range,1 do
				--TODO create a little bit more sophisticated blast resistance
				if math.random() < chance then
					local toremove = core.get_node({x=i,y=j,z=k})

					if toremove ~= nil then
						local immune = false

						if immune_list ~= nil then
							for i,v in ipairs(immune_list) do
								if (toremove.name == v) then
									immune = true
								end
							end
						end


						if immune ~= true then
							core.remove_node({x=i,y=j,z=k})
						end
					end
				end
			end
		end
	end
end

--! @class AR_FIREBALL_ENTITY
--! @ingroup weapons
--! @brief a fireball weapon entity
local AR_FIREBALL_ENTITY = {
	physical = false,
	textures = {"animal_resources_fireball.png"},
	collisionbox = {0,0,0,0,0,0},

	damage_range = 4,
	velocity = 3,
	gravity = -0.01,

	damage_outer = {
					fleshy=4,
					},
	damage_inner = {
					fleshy=8,
					},

	owner = 0,
	lifetime = 30,
	created = -1,
}


-------------------------------------------------------------------------------
-- name: AR_FIREBALL_ENTITY.on_activate = function(self, staticdata)
--
--! @brief onactivate callback for fireball
--! @memberof AR_FIREBALL_ENTITY
--! @private
--
--! @param self fireball itself
--! @param staticdata
-------------------------------------------------------------------------------
function AR_FIREBALL_ENTITY.on_activate(self,staticdata)
	self.created = os.clock()
end

-------------------------------------------------------------------------------
-- name: AR_FIREBALL_ENTITY.surfacefire = function(self, staticdata)
--
--! @brief place fire on surfaces around pos
--! @memberof AR_FIREBALL_ENTITY
--! @private
--
--! @param pos position to place fire around
--! @param range square around pos to set on fire
-------------------------------------------------------------------------------
function AR_FIREBALL_ENTITY.surfacefire(pos,range)

	if mobf_rtd ~= nil and mobf_rtd.fire_enabled then
		--start fire on any surface within inner damage range
		for i=pos.x-range/2, pos.x+range/2, 1 do
		for j=pos.y-range/2, pos.y+range/2, 1 do
		for k=pos.z-range/2, pos.z+range/2, 1 do

			local current = core.get_node({x=i,y=j,z=k})
			local ontop  = core.get_node({x=i,y=j+1,z=k})

			--print("put fire? " .. printpos({x=i,y=j,z=k}) .. " " .. current.name .. " " ..ontop.name)

			if (current.name ~= "air") and
				(current.name ~= "fire:basic_flame") and
				(ontop.name == "air") then
				core.set_node({x=i,y=j+1,z=k}, {name="fire:basic_flame"})
			end

		end
		end
		end
	else
		core.log("error","AMR: A fireball without fire mod??!? You're kidding!!")
	end
end

-------------------------------------------------------------------------------
-- name: AR_FIREBALL_ENTITY.on_step = function(self, dtime)
--
--! @brief onstep callback for fireball
--! @memberof AR_FIREBALL_ENTITY
--! @private
--
--! @param self fireball itself
--! @param dtime time since last callback
-------------------------------------------------------------------------------
function AR_FIREBALL_ENTITY.on_step(self, dtime)
	local pos = self.object:getpos()
	local node = core.get_node(pos)


	--detect hit
	local objs=core.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1)

	local hit = false

	for k, obj in pairs(objs) do
		if obj:get_entity_name() ~= "animal_resources:fireball_entity" and
			obj ~= self.owner then
			hit=true
		end
	end


	if hit then
		--damage objects within inner blast radius
		do_area_damage(pos,self.owner,self.damage_outer,self.damage_range/4)

		--damage all objects within blast radius
		do_area_damage(pos,self.owner,self.damage_inner,self.damage_range/2)

		AR_FIREBALL_ENTITY.surfacefire(pos,self.damage_range)

		self.object:remove()
	end

	-- vanish when hitting a node
	if node.name ~= "air" then
		AR_FIREBALL_ENTITY.surfacefire(pos,self.damage_range)
		self.object:remove()
	end

	--remove after lifetime has passed
	if self.created > 0 and
		self.created + self.lifetime < os.clock() then
		self.object:remove()
	end
end

--! @class AR_PLASMABALL_ENTITY
--! @ingroup weapons
--! @brief a plasmaball weapon entity
local AR_PLASMABALL_ENTITY = {
	physical = false,
	textures = {"animal_resources_plasmaball.png"},
	lastpos={},
	collisionbox = {0,0,0,0,0,0},

	damage_range = 2,
	velocity = 4,
	gravity = -0.001,

	damage = {
			fleshy=4,
			},

	damage_pass = {
			fleshy=2,
			},

	owner = 0,
	lifetime = 30,
	created = -1,
}

-------------------------------------------------------------------------------
-- name: AR_PLASMABALL_ENTITY.on_activate = function(self, staticdata)
--
--! @brief onactivate callback for plasmaball
--! @memberof AR_PLASMABALL_ENTITY
--! @private
--
--! @param self fireball itself
--! @param staticdata
-------------------------------------------------------------------------------
function AR_PLASMABALL_ENTITY.on_activate(self,staticdata)
	self.created = os.clock()
end


-------------------------------------------------------------------------------
-- name: AR_PLASMABALL_ENTITY.on_step = function(self, dtime)
--
--! @brief onstep callback for plasmaball
--! @memberof AR_PLASMABALL_ENTITY
--! @private
--
--! @param self plasmaball itself
--! @param dtime time since last callback
-------------------------------------------------------------------------------
function AR_PLASMABALL_ENTITY.on_step(self, dtime)
	local pos = self.object:getpos()
	local node = core.get_node(pos)


	--detect hit
	local objs=core.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1)

	local hit = false

	for k, obj in pairs(objs) do
		if obj:get_entity_name() ~= "animal_resources:plasmaball_entity" and
			obj ~= self.owner then
			hit=true
		end
	end

	--damage all objects not hit but at least passed
	do_area_damage(pos,self.owner,self.damage_pass,2)

	if hit then
		--damage objects within inner blast radius
		do_area_damage(pos,self.owner,self.damage,self.damage_range/4)

		--damage all objects within blast radius
		do_area_damage(pos,self.owner,self.damage,self.damage_range/2)
	end

	-- vanish when hitting a node
	if node.name ~= "air" or
		hit then

		--replace this loop by minetest.find_node_near?
		--do node damage
		for i=pos.x-1, pos.x+1, 1 do
			for j=pos.y-1, pos.y+1, 1 do
				for k=pos.z-1,pos.z+1,1 do
					--TODO create a little bit more sophisticated blast resistance
					if math.random() < 0.5 then
						local toremove = minetest.get_node({x=i,y=j,z=k})

						if toremove ~= nil and
							toremove.name ~= "default:stone" and
							toremove.name ~= "default:cobble" then

							core.remove_node({x=i,y=j,z=k})
						end
					end
				end
			end
		end

		self.object:remove()
	end

	--remove after lifetime has passed
	if self.created > 0 and
		self.created + self.lifetime < mobf_get_current_time() then
		self.object:remove()
	end
end

-- -----------------------------------------------------------------------------
-- Code Below is by far extent taken from throwing mod by PilzAdam
-- -----------------------------------------------------------------------------
--! @class AR_ARROW_ENTITY
--! @ingroup weapons
--! @brief a arrow entity
local AR_ARROW_ENTITY={
	physical = false,
	timer=0,
	visual = "wielditem",
	visual_size = {x=0.1, y=0.1},
	textures = {"animal_resources:arrow_box"},
	lastpos={},
	collisionbox = {0,0,0,0,0,0},

	velocity =6,
	damage_groups = {
					fleshy=3,
					daemon=1.5
					},
	gravity  =9.81,
}

-------------------------------------------------------------------------------
-- name: AR_ARROW_ENTITY.on_step = function(self, dtime)
--
--! @brief onstep callback for arrow
--! @memberof AR_ARROW_ENTITY
--! @private
--
--! @param self arrow itself
--! @param dtime time since last callback
-------------------------------------------------------------------------------
AR_ARROW_ENTITY.on_step = function(self, dtime)
	self.timer=self.timer+dtime
	local pos = self.object:getpos()
	local node = core.get_node(pos)

	if self.timer>0.2 then
		local objs = core.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2)
		for k, obj in pairs(objs) do
			if obj:get_luaentity() ~= nil and
				obj ~= self.owner then
				if obj:get_luaentity().name ~= "animal_resources:arrow_entity" and
					obj:get_luaentity().name ~= "__builtin:item" then
					obj:punch(self.object, 1.0, {
						full_punch_interval=1.0,
						damage_groups = self.damage_groups,
					}, nil)
					self.object:remove()
				end
			else
				--punch a player
				obj:punch(self.object, 1.0, {
					full_punch_interval=1.0,
					damage_groups = self.damage_groups,
				}, nil)
				self.object:remove()
			end
		end
	end

	if self.lastpos.x~=nil then
		if node.name ~= "air" then
			core.add_item(self.lastpos, 'animal_resources:arrow')
			self.object:remove()
		end
	end
	self.lastpos={x=pos.x, y=pos.y, z=pos.z}
end

-------------------------------------------------------------------------------
-- name: ar_init_weapons = function(self, dtime)
--
--! @brief initialize weapons handled by mobf mod
--
-------------------------------------------------------------------------------
function ar_init_weapons()
	core.register_entity(":animal_resources:fireball_entity", AR_FIREBALL_ENTITY)
	core.register_entity(":animal_resources:plasmaball_entity", AR_PLASMABALL_ENTITY)
	core.register_entity(":animal_resources:arrow_entity", AR_ARROW_ENTITY)
end


-- moved due to doxygen problems
core.register_node("animal_resources: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 = {"animal_resources_arrow.png", "animal_resources_arrow.png",
			"animal_resources_arrow_back.png", "animal_resources_arrow_front.png",
			 "animal_resources_arrow_2.png", "animal_resources_arrow.png"},
	groups = {not_in_creative_inventory=1},
})

local mods = core.get_modnames()

for i,v in ipairs(mods) do
	if v == element then
		print("AR: throwing mod found!")
		core.register_alias("animal_resources:arrow", "throwing:arrow")
	end
end