Update sneeker mod to v1.0...

https://github.com/AntumMT/mod-sneeker/releases/tag/v1.0
This commit is contained in:
Jordan Irwin 2021-05-08 21:50:55 -07:00
parent 518d915dde
commit 5c0a102ee2
25 changed files with 1039 additions and 875 deletions

View File

@ -90,11 +90,11 @@ The game includes the mods from the default [minetest_game](https://github.com/m
* [ghost][creatures] ([Zlib][lic.creatures] / [CC BY-SA][lic.ccbysa3.0]) -- version: [dd22520 Git][ver.ghost] *2021-05-05*
* [horse][] ([MIT][lic.horse]) -- version: [9c5c857 Git][ver.horse] *2021-05-05*
* [monsters_aggressive][] (see individual mods for licensing) -- version: [89a8187 Git][ver.monsters_aggressive] *2017-08-30*
* [sneeker][] ([CC0][lic.cc0]) -- version: [7c05c4d Git][ver.sneeker] *2021-04-19*
* [monsters_passive][] (see individual mods for licensing) -- version: [b07fe19 Git][ver.monsters_passive] *2017-08-09*
* [oerkki][creatures] ([Zlib][lic.creatures] / [CC BY-SA][lic.ccbysa3.0]) -- version: [70410fe Git][ver.oerkki] *2021-05-05*
* [shark][] ([CC0 / CC BY-SA][lic.shark]) -- version: [ef2507b Git][ver.shark] *2021-05-05*
* [sheep][creatures] ([Zlib][lic.creatures] / [CC BY-SA][lic.ccbysa3.0]) -- version: [7c91aaf Git][ver.sheep] *2021-05-05*
* [sneeker][] ([MIT][lic.sneeker]) -- version: [1.0][ver.sneeker] *2021-05-08*
* [zombie][creatures] ([Zlib][lic.creatures] / [CC BY-SA][lic.ccbysa3.0]) -- version: [4edb18e Git][ver.zombie] *2021-05-05*
* [painting][] (???) -- version [8961849 Git][ver.painting] *2016-05-05*
* [pipeworks][] ([LGPL][lic.lgpl3.0]) -- version: [2021-02-19][ver.pipeworks]
@ -344,7 +344,7 @@ The game includes the mods from the default [minetest_game](https://github.com/m
[signs_lib]: https://forum.minetest.net/viewtopic.php?f=11&t=13762
[simple_protection]: https://forum.minetest.net/viewtopic.php?t=9035
[slingshot]: https://github.com/AntumMT/mod-slingshot
[sneeker]: https://github.com/AntumMT/mod-sneeker
[sneeker]: https://forum.minetest.net/viewtopic.php?t=26685
[snowdrift]: https://forum.minetest.net/viewtopic.php?t=6854
[asm_spawneggs]: https://forum.minetest.net/viewtopic.php?t=26676
[spectator_mode]: https://forum.minetest.net/viewtopic.php?t=13718
@ -424,6 +424,7 @@ The game includes the mods from the default [minetest_game](https://github.com/m
[lic.shark]: mods/mobiles/shark/LICENSE.txt
[lic.signs_lib]: mods/signs/signs_lib/copyright.txt
[lic.slingshot]: mods/equipment/slingshot/LICENSE.txt
[lic.sneeker]: mods/mobiles/sneeker/LICENSE.txt
[lic.snowdrift]: mods/weather/snowdrift/license.txt
[lic.asm_spawneggs]: mods/spawning/asm_spawneggs/LICENSE.txt
[lic.spectator_mode]: mods/admin/spectator_mode/LICENSE
@ -573,7 +574,7 @@ The game includes the mods from the default [minetest_game](https://github.com/m
[ver.signs_lib]: https://gitlab.com/VanessaE/signs_lib/tree/2021-03-04-2
[ver.simple_protection]: https://github.com/SmallJoker/simple_protection/tree/3630fe9
[ver.slingshot]: https://github.com/AntumMT/mod-slingshot/tree/bb77525
[ver.sneeker]: https://github.com/AntumMT/mod-sneeker/tree/7c05c4d
[ver.sneeker]: https://github.com/AntumMT/mod-sneeker/releases/tag/v1.0
[ver.snowdrift]: https://github.com/paramat/snowdrift/tree/3342939
[ver.asm_spawneggs]: https://github.com/AntumMT/mod-asm_spawneggs/tree/8579eac
[ver.spectator_mode]: https://github.com/minetest-mods/spectator_mode/tree/3648371

View File

@ -1,121 +0,0 @@
Creative Commons Legal Code
CC0 1.0 Universal
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
HEREUNDER.
Statement of Purpose
The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator
and subsequent owner(s) (each and all, an "owner") of an original work of
authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for
the purpose of contributing to a commons of creative, cultural and
scientific works ("Commons") that the public can reliably and without fear
of later claims of infringement build upon, modify, incorporate in other
works, reuse and redistribute as freely as possible in any form whatsoever
and for any purposes, including without limitation commercial purposes.
These owners may contribute to the Commons to promote the ideal of a free
culture and the further production of creative, cultural and scientific
works, or to gain reputation or greater distribution for their Work in
part through the use and efforts of others.
For these and/or other purposes and motivations, and without any
expectation of additional consideration or compensation, the person
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
is an owner of Copyright and Related Rights in the Work, voluntarily
elects to apply CC0 to the Work and publicly distribute the Work under its
terms, with knowledge of his or her Copyright and Related Rights in the
Work and the meaning and intended legal effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights ("Copyright and
Related Rights"). Copyright and Related Rights include, but are not
limited to, the following:
i. the right to reproduce, adapt, distribute, perform, display,
communicate, and translate a Work;
ii. moral rights retained by the original author(s) and/or performer(s);
iii. publicity and privacy rights pertaining to a person's image or
likeness depicted in a Work;
iv. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(a), below;
v. rights protecting the extraction, dissemination, use and reuse of data
in a Work;
vi. database rights (such as those arising under Directive 96/9/EC of the
European Parliament and of the Council of 11 March 1996 on the legal
protection of databases, and under any national implementation
thereof, including any amended or successor version of such
directive); and
vii. other similar, equivalent or corresponding rights throughout the
world based on applicable law or treaty, and any national
implementations thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention
of, applicable law, Affirmer hereby overtly, fully, permanently,
irrevocably and unconditionally waives, abandons, and surrenders all of
Affirmer's Copyright and Related Rights and associated claims and causes
of action, whether now known or unknown (including existing as well as
future claims and causes of action), in the Work (i) in all territories
worldwide, (ii) for the maximum duration provided by applicable law or
treaty (including future time extensions), (iii) in any current or future
medium and for any number of copies, and (iv) for any purpose whatsoever,
including without limitation commercial, advertising or promotional
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
member of the public at large and to the detriment of Affirmer's heirs and
successors, fully intending that such Waiver shall not be subject to
revocation, rescission, cancellation, termination, or any other legal or
equitable action to disrupt the quiet enjoyment of the Work by the public
as contemplated by Affirmer's express Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason
be judged legally invalid or ineffective under applicable law, then the
Waiver shall be preserved to the maximum extent permitted taking into
account Affirmer's express Statement of Purpose. In addition, to the
extent the Waiver is so judged Affirmer hereby grants to each affected
person a royalty-free, non transferable, non sublicensable, non exclusive,
irrevocable and unconditional license to exercise Affirmer's Copyright and
Related Rights in the Work (i) in all territories worldwide, (ii) for the
maximum duration provided by applicable law or treaty (including future
time extensions), (iii) in any current or future medium and for any number
of copies, and (iv) for any purpose whatsoever, including without
limitation commercial, advertising or promotional purposes (the
"License"). The License shall be deemed effective as of the date CC0 was
applied by Affirmer to the Work. Should any part of the License for any
reason be judged legally invalid or ineffective under applicable law, such
partial invalidity or ineffectiveness shall not invalidate the remainder
of the License, and in such case Affirmer hereby affirms that he or she
will not (i) exercise any of his or her remaining Copyright and Related
Rights in the Work or (ii) assert any associated claims and causes of
action with respect to the Work, in either case contrary to Affirmer's
express Statement of Purpose.
4. Limitations and Disclaimers.
a. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
b. Affirmer offers the Work as-is and makes no representations or
warranties of any kind concerning the Work, express, implied,
statutory or otherwise, including without limitation warranties of
title, merchantability, fitness for a particular purpose, non
infringement, or the absence of latent or other defects, accuracy, or
the present or absence of errors, whether or not discoverable, all to
the greatest extent permissible under applicable law.
c. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without
limitation any person's Copyright and Related Rights in the Work.
Further, Affirmer disclaims responsibility for obtaining any necessary
consents, permissions or other rights required for any use of the
Work.
d. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to
this CC0 or use of the Work.

View File

@ -1,17 +0,0 @@
# Sneeker mobile mod for Minetest
Adds some explosive nuisance.
## Forum Topic
- Original thread: https://forum.minetest.net/viewtopic.php?t=11891
## License
- **Code:**
- Original by Rui: [WTFPL][lic.wtfpl]
- AntumDeluge: [CC0][lic.cc0]
[lic.cc0]: LICENSE.txt
[lic.wtfpl]: LICENSE-wtfpl.txt

View File

@ -1,30 +0,0 @@
-- Functions for sneeker mod
local log_mods = core.settings:get_bool('log_mods')
-- Displays a message in log output
function sneeker.log(message)
if log_mods then
core.log('action', '[' .. sneeker.modname .. '] ' .. message)
end
end
-- Displays a message in log output only if 'sneeker.debug' is set to 'true'
function sneeker.log_debug(message)
if sneeker.debug then
sneeker.log('DEBUG: ' .. message)
end
end
-- Spawns a sneeker entity
function sneeker.spawn(pos)
core.add_entity(pos, sneeker.mob_name)
sneeker.log_debug('Spawned entity "' .. sneeker.mob_name .. '" at ' .. tostring(pos.x) .. ',' .. tostring(pos.y))
end
-- Retrieves pos coordinates in string value
function sneeker.get_pos_string(pos)
return 'x=' .. tostring(pos.x) .. ', y=' .. tostring(pos.y) .. ', z=' .. tostring(pos.z)
end

View File

@ -1,373 +0,0 @@
-- Original code by Rui: WTFPL
sneeker = {}
sneeker.modname = core.get_current_modname()
sneeker.modpath = core.get_modpath(sneeker.modname)
if core.settings:get_bool('log_mods') then
core.log('action', 'Loading mod "' .. sneeker.modname .. '" ...')
end
dofile(sneeker.modpath .. '/settings.lua')
dofile(sneeker.modpath .. '/functions.lua')
sneeker.log_debug('Debugging is on')
sneeker.mob_name = sneeker.modname .. ':' .. sneeker.modname
sneeker.spawnegg_name = sneeker.modname .. ':spawnegg'
local scripts = {
'tnt_function',
'spawn',
}
for I in pairs(scripts) do
dofile(sneeker.modpath .. '/' .. scripts[I] .. '.lua')
end
local function jump(self,pos,direction)
local velocity = self.object:get_velocity()
if core.registered_nodes[core.get_node(pos).name].climbable then
self.object:set_velocity({x=velocity.x,y=4,z=velocity.z})
return
end
local spos = {x=pos.x+direction.x,y=pos.y,z=pos.z+direction.z}
local node = core.get_node_or_nil(spos)
spos.y = spos.y+1
local node2 = core.get_node_or_nil(spos)
local def,def2 = {}
if node and node.name then
def = core.registered_items[node.name]
end
if node2 and node2.name then
def2 = core.registered_items[node2.name]
end
if def and def.walkable
and def2 and not def2.walkable
and def.drawtype ~= 'fencelike' then
self.object:set_velocity({
x=velocity.x*2.2,
y=self.jump_height,
z=velocity.z*2.2
})
end
end
local function random_turn(self)
if self.turn_timer > math.random(2,5) then
local select_turn = math.random(1,3)
if select_turn == 1 then
self.turn = 'left'
elseif select_turn == 2 then
self.turn = 'right'
elseif select_turn == 3 then
self.turn = 'straight'
end
self.turn_timer = 0
self.turn_speed = 0.05*math.random()
end
end
local def = {
hp_max = 20,
physical = true,
collisionbox = {-0.25,-0.7,-0.25, 0.25,0.8,0.25},
visual = 'mesh',
mesh = 'character.b3d',
textures = {'sneeker.png'},
makes_footstep_sound = false,
-- Original
animation = {
stand_START = 0,
stand_END = 79,
walk_START = 168,
walk_END = 187
},
walk_speed = 1.5,
jump_height = 5,
animation_speed = 30,
knockback_level = 2
}
def.on_activate = function(self,staticdata)
self.yaw = 0
self.anim = 1
self.timer = 0
self.visualx = 1
self.jump_timer = 0
self.turn_timer = 0
self.turn_speed = 0
self.powered = false
self.knockback = false
self.state = math.random(1,2)
self.old_y = self.object:get_pos().y
local data = core.deserialize(staticdata)
if data and type(data) == 'table' then
if data.powered == true then
self.powered = true
self.object:set_properties({textures = {'sneeker_powered.png'}})
end
else
if math.random(0,20) == 20 then
self.powered = true
self.object:set_properties({textures = {'sneeker_powered.png'}})
end
end
end
def.on_step = function(self, dtime)
if self.knockback then
return
end
local ANIM_STAND = 1
local ANIM_WALK = 2
local pos = self.object:get_pos()
local yaw = self.object:get_yaw()
local inside = core.get_objects_inside_radius(pos,10)
local walk_speed = self.walk_speed
local animation = self.animation
local anim_speed = self.animation_speed
local velocity = self.object:get_velocity()
self.timer = self.timer+0.01
self.turn_timer = self.turn_timer+0.01
self.jump_timer = self.jump_timer+0.01
if not self.chase
and self.timer > math.random(2,5) then
if math.random() > 0.8 then
self.state = 'stand'
else
self.state = 'walk'
end
self.timer = 0
end
if self.turn == 'right' then
self.yaw = self.yaw+self.turn_speed
self.object:set_yaw(self.yaw)
elseif self.turn == 'left' then
self.yaw = self.yaw-self.turn_speed
self.object:set_yaw(self.yaw)
end
if self.chase and self.visualx < 2 then
if self.hiss == false then
core.sound_play('sneeker_hiss',{pos=pos,gain=1.5,max_hear_distance=2*64})
end
self.visualx = self.visualx+0.05
self.object:set_properties({
visual_size = {x=self.visualx,y=1}
})
self.hiss = true
elseif self.visualx > 1 then
self.visualx = self.visualx-0.05
self.object:set_properties({
visual_size = {x=self.visualx,y=1}
})
self.hiss = false
end
self.chase = false
for _,object in ipairs(inside) do
if object:is_player() then
self.state = 'chase'
end
end
if self.state == 'stand' then
if self.anim ~= ANIM_STAND then
self.object:set_animation({x=animation.stand_START,y=animation.stand_END},anim_speed,0)
self.anim = ANIM_STAND
end
random_turn(self)
if velocity.x ~= 0
or velocity.z ~= 0 then
self.object:set_velocity({x=0,y=velocity.y,z=0})
end
end
if self.state == 'walk' then
if self.anim ~= ANIM_WALK then
self.object:set_animation({x=animation.walk_START,y=animation.walk_END},anim_speed,0)
self.anim = ANIM_WALK
end
self.direction = {x=math.sin(yaw)*-1,y=-10,z=math.cos(yaw)}
if self.direction then
self.object:set_velocity({x=self.direction.x*walk_speed,y=velocity.y,z=self.direction.z*walk_speed})
end
random_turn(self)
local velocity = self.object:get_velocity()
if self.turn_timer > 1 then
local direction = self.direction
local npos = {x=pos.x+direction.x,y=pos.y+0.2,z=pos.z+direction.z}
if velocity.x == 0 or velocity.z == 0
or core.registered_nodes[core.get_node(npos).name].walkable then
local select_turn = math.random(1,2)
if select_turn == 1 then
self.turn = 'left'
elseif select_turn == 2 then
self.turn = 'right'
end
self.turn_timer = 0
self.turn_speed = 0.05*math.random()
end
end
-- Jump
if self.jump_timer > 0.2 then
jump(self,pos,self.direction)
end
end
if self.state == 'chase' then
if self.anim ~= ANIM_WALK then
self.object:set_animation({x=animation.walk_START,y=animation.walk_END},anim_speed,0)
self.anim = ANIM_WALK
end
self.turn = 'straight'
local inside_2 = core.get_objects_inside_radius(pos,2)
-- Boom
if #inside_2 ~= 0 then
for _,object in ipairs(inside_2) do
if object:is_player() and object:get_hp() ~= 0 then
self.chase = true
if self.visualx >= 2 then
self.object:remove()
sneeker.boom(pos,self.powered)
core.sound_play('sneeker_explode',{pos=pos,gain=1.5,max_hear_distance=2*64})
end
end
end
end
if #inside ~= 0 then
for _,object in ipairs(inside) do
if object:is_player() and object:get_hp() ~= 0 then
if #inside_2 ~= 0 then
for _,object in ipairs(inside_2) do
-- Stop move
if object:is_player() then
if self.anim ~= ANIM_STAND then
self.object:set_animation({x=animation.stand_START,y=animation.stand_END},anim_speed,0)
self.anim = ANIM_STAND
end
self.object:set_velocity({x=0,y=velocity.y,z=0})
return
end
end
end
local ppos = object:get_pos()
self.vec = {x=ppos.x-pos.x,y=ppos.y-pos.y,z=ppos.z-pos.z}
self.yaw = math.atan(self.vec.z/self.vec.x)+math.pi^2
if ppos.x > pos.x then
self.yaw = self.yaw+math.pi
end
self.yaw = self.yaw-2
self.object:set_yaw(self.yaw)
self.direction = {x=math.sin(self.yaw)*-1,y=0,z=math.cos(self.yaw)}
local direction = self.direction
self.object:set_velocity({x=direction.x*2.5,y=velocity.y,z=direction.z*2.5})
-- Jump
if self.jump_timer > 0.2 then
jump(self,pos,direction)
end
end
end
else
self.state = 'stand'
end
end
-- Swim
local node = core.get_node(pos)
if core.get_item_group(node.name,'water') ~= 0 then
self.object:set_acceleration({x=0,y=1,z=0})
local velocity = self.object:get_velocity()
if self.object:get_velocity().y > 5 then
self.object:set_velocity({x=0,y=velocity.y-velocity.y/2,z=0})
else
self.object:set_velocity({x=0,y=velocity.y+1,z=0})
end
else
self.object:set_acceleration({x=0,y=-10,z=0})
end
end
def.on_punch = function(self,puncher,time_from_last_punch,tool_capabilities,dir)
if self.knockback == false then
local knockback_level = self.knockback_level
self.object:set_velocity({x=dir.x*knockback_level,y=3,z=dir.z*knockback_level})
self.knockback = true
core.after(0.6,function()
self.knockback = false
end)
end
if self.object:get_hp() < 1 then
local pos = self.object:get_pos()
local x = 1/math.random(1,5)*dir.x
local z = 1/math.random(1,5)*dir.z
local p = {x=pos.x+x,y=pos.y,z=pos.z+z}
local node = core.get_node_or_nil(p)
if node == nil or not node.name or node.name ~= 'air' then
p = pos
end
local obj = core.add_item(p, {name='tnt:gunpowder',count=math.random(0,2)})
end
end
def.get_staticdata = function(self)
return core.serialize({
powered = self.powered
})
end
core.register_entity(sneeker.mob_name, def)
if core.get_modpath('spawneggs') and core.get_modpath('tnt') then
core.register_craftitem(sneeker.spawnegg_name, {
description = 'Sneeker Spawn Egg',
inventory_image = 'sneeker_spawnegg.png',
stack_max = 64,
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type == 'node' then
local pos = pointed_thing.above
pos.y = pos.y+1
core.add_entity(pos, sneeker.mob_name)
if not core.settings:get_bool('creative_mode') then
itemstack:take_item()
end
return itemstack
end
end
})
core.register_craft({
output = sneeker.spawnegg_name,
type = 'shapeless',
recipe = {
'spawneggs:egg', 'tnt:tnt',
},
})
core.register_alias('spawneggs:sneeker', sneeker.spawnegg_name)
end

View File

@ -1,4 +0,0 @@
name = sneeker
description = An explosive nuisance.
depends = default,nether
optional_depends = spawneggs,tnt

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

View File

@ -1,4 +0,0 @@
-- Settings for sneeker mod
sneeker.debug = core.settings:get_bool('enable_debug_mods') or false

View File

@ -1,20 +0,0 @@
# Sets maximum number of spawns that can exist in world.
sneeker.spawn_cap (Sneeker maximum spawns) int 10
# Sets possibility for spawn.
sneeker.spawn_chance (Sneeker spawn chance) int 1000
# Sets frequency of spawn chance. Default 240 is equivalent to 4 minutes (60 * 4).
sneeker.spawn_interval (Sneeker spawn interval) int 240
# Sets the minimum light required for spawn to occur.
sneeker.spawn_minlight (Sneeker min light for spawn) int -1
# Sets the maximum light that a node can have for spawn to occur.
sneeker.spawn_maxlight (Sneeker max light for spawn) int 4
# Sets the lowest position at which sneeker can spawn.
sneeker.spawn_minheight (Sneeker min spawn height) int -31000
# Sets the highest position at which sneeker can spawn.
sneeker.spawn_maxheight (Sneeker max spawn height) int 31000

View File

@ -1,90 +0,0 @@
-- Original code by Rui: WTFPL
local time_min = 60
local time_hr = time_min * 60
local time_day = time_hr * 24
local spawn_cap = tonumber(core.settings:get('sneeker.spawn_cap')) or 10 -- Maximum number of spawns active at one time
local spawn_chance = tonumber(core.settings:get('sneeker.spawn_chance')) or 1000 -- 1/1000 chance of spawn
local spawn_interval = tonumber(core.settings:get('sneeker.spawn_interval')) or time_min * 4 -- Default interval is 4 minutes
local spawn_minlight = tonumber(core.settings:get('sneeker.spawn_minlight')) or -1 -- Minimum light of node required for spawn
local spawn_maxlight = tonumber(core.settings:get('sneeker.spawn_maxlight')) or 4 -- Maximum light of node allowed for spawn
local spawn_minheight = tonumber(core.settings:get('sneeker.spawn_minheight')) or -31000 -- Minimum height allowed for spawn
local spawn_maxheight = tonumber(core.settings:get('sneeker.spawn_maxheight')) or 31000 -- Maximum height allowed for spawn
-- Display spawn chance as percentage in log
local spawn_chance_percent = math.floor(1 / spawn_chance * 100)
if spawn_chance_percent < 1 then
spawn_chance_percent = 'Less than 1%'
else
spawn_chance_percent = tostring(spawn_chance_percent) .. '%'
end
sneeker.log('Spawn cap: ' .. tostring(spawn_cap))
sneeker.log('Spawn chance: ' .. spawn_chance_percent)
sneeker.log('Spawn interval: ' .. tostring(spawn_interval) .. ' (' .. tostring(spawn_interval/60) .. ' minute(s))')
sneeker.log('Maximum light value for spawn: ' .. tostring(spawn_maxlight))
core.register_abm({
nodenames = {'nether:rack'},
neighbors = {'air'},
interval = spawn_interval,
chance = spawn_chance,
action = function(pos, node, _, active_object_count_wider)
if active_object_count_wider > 5 then
return
end
-- Check light value of node
pos.y = pos.y+1
local node_light = core.get_node_light(pos)
-- Debugging spawning
sneeker.log_debug('Node light level at ' .. sneeker.get_pos_string(pos) .. ': ' .. tostring(node_light))
-- Node light level
if not node_light or node_light > spawn_maxlight then
sneeker.log_debug('Node not dark enough for spawn')
return
elseif node_light < spawn_minlight then
sneeker.log_debug('Node too dark for spawn')
return
end
-- Spawn range
if spawn_minheight ~= nil and pos.y < spawn_minheight then
sneeker.log_debug('Position is too low for spawn')
return
elseif pos.y > spawn_maxheight then
sneeker.log_debug('Position is too high for spawn')
return
end
-- Node must be touching air
if core.get_node(pos).name ~= 'air' then
return
end
pos.y = pos.y+1
if core.get_node(pos).name ~= 'air' then
return
end
-- Get total count of sneekers in world
local count = 0
for I in pairs(core.luaentities) do
if core.luaentities[I].name == sneeker.mob_name then
count = count + 1
end
end
sneeker.log_debug('Current active spawns: ' .. tostring(count) .. '/' .. tostring(spawn_cap))
if count >= spawn_cap then
sneeker.log_debug('Max spawns reached')
return
end
sneeker.spawn(pos)
end
})

View File

@ -1,198 +0,0 @@
-- Original code by Rui: WTFPL
-- From TNT
local cid_data = {}
local radius = tonumber(core.settings:get('tnt_radius') or 3)
local large_radius = 5
local loss_prob = {
['default:cobble'] = 3,
['default:dirt'] = 4,
}
core.after(0, function()
for name, def in pairs(core.registered_nodes) do
cid_data[core.get_content_id(name)] = {
name = name,
drops = def.drops,
flammable = def.groups.flammable,
}
end
end)
local function rand_pos(center, pos, radius)
pos.x = center.x + math.random(-radius, radius)
pos.z = center.z + math.random(-radius, radius)
end
local function eject_drops(drops, pos, radius)
local drop_pos = vector.new(pos)
for _, item in pairs(drops) do
local count = item:get_count()
local max = item:get_stack_max()
if count > max then
item:set_count(max)
end
while count > 0 do
if count < max then
item:set_count(count)
end
rand_pos(pos, drop_pos, radius)
local obj = core.add_item(drop_pos, item)
if obj then
obj:get_luaentity().collect = true
obj:set_acceleration({x=0, y=-10, z=0})
obj:set_velocity({x=math.random(-3, 3), y=10,
z=math.random(-3, 3)})
end
count = count - max
end
end
end
local function add_drop(drops, item)
item = ItemStack(item)
local name = item:get_name()
if loss_prob[name] ~= nil and math.random(1, loss_prob[name]) == 1 then
return
end
local drop = drops[name]
if drop == nil then
drops[name] = item
else
drop:set_count(drop:get_count() + item:get_count())
end
end
local function destroy(drops, pos, cid)
if core.is_protected(pos, '') then
return
end
local def = cid_data[cid]
if def and def.on_blast then
def.on_blast(vector.new(pos), 1)
return
end
core.remove_node(pos)
if def then
local node_drops = core.get_node_drops(def.name, '')
for _, item in ipairs(node_drops) do
add_drop(drops, item)
end
end
end
local function calc_velocity(pos1, pos2, old_vel, power)
local vel = vector.direction(pos1, pos2)
vel = vector.normalize(vel)
vel = vector.multiply(vel, power)
-- Divide by distance
local dist = vector.distance(pos1, pos2)
dist = math.max(dist, 1)
vel = vector.divide(vel, dist)
-- Add old velocity
vel = vector.add(vel, old_vel)
return vel
end
local function entity_physics(pos, radius)
-- Make the damage radius larger than the destruction radius
radius = radius * 2
local objs = core.get_objects_inside_radius(pos, radius)
for _, obj in pairs(objs) do
local obj_pos = obj:get_pos()
local obj_vel = obj:get_velocity()
local dist = math.max(1, vector.distance(pos, obj_pos))
if obj_vel ~= nil then
obj:set_velocity(calc_velocity(pos, obj_pos,
obj_vel, radius * 10))
end
local damage = (5 / dist) * radius
obj:set_hp(obj:get_hp() - damage)
end
end
local function add_effects(pos, radius)
core.add_particlespawner({
amount = 128,
time = 1,
minpos = vector.subtract(pos, radius / 2),
maxpos = vector.add(pos, radius / 2),
minvel = {x=-20, y=-20, z=-20},
maxvel = {x=20, y=20, z=20},
minacc = vector.new(),
maxacc = vector.new(),
minexptime = 1,
maxexptime = 3,
minsize = 8,
maxsize = 16,
texture = 'sneeker_smoke.png',
})
end
local function explode(pos, radius)
local pos = vector.round(pos)
local vm = VoxelManip()
local pr = PseudoRandom(os.time())
local p1 = vector.subtract(pos, radius)
local p2 = vector.add(pos, radius)
local minp, maxp = vm:read_from_map(p1, p2)
local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
local data = vm:get_data()
local drops = {}
local p = {}
local c_air = core.get_content_id('air')
local c_tnt = core.get_content_id('tnt:tnt')
local c_tnt_burning = core.get_content_id('tnt:tnt_burning')
local c_gunpowder = core.get_content_id('tnt:gunpowder')
local c_gunpowder_burning = core.get_content_id('tnt:gunpowder_burning')
local c_boom = core.get_content_id('tnt:boom')
for z = -radius, radius do
for y = -radius, radius do
local vi = a:index(pos.x + (-radius), pos.y + y, pos.z + z)
for x = -radius, radius do
if (x * x) + (y * y) + (z * z) <=
(radius * radius) + pr:next(-radius, radius) then
local cid = data[vi]
p.x = pos.x + x
p.y = pos.y + y
p.z = pos.z + z
if cid == c_tnt or cid == c_gunpowder then
burn(p)
elseif cid ~= c_tnt_burning and
cid ~= c_gunpowder_burning and
cid ~= c_air and
cid ~= c_boom then
destroy(drops, p, cid)
end
end
vi = vi + 1
end
end
end
return drops
end
function sneeker.boom(pos,large)
local radius = radius
if large then
radius = large_radius
end
core.sound_play('sneeker_explode', {pos=pos, gain=1.5, max_hear_distance=2*64})
core.set_node(pos, {name='tnt:boom'})
core.get_node_timer(pos):start(0.5)
local drops = explode(pos, radius)
entity_physics(pos, radius)
eject_drops(drops, pos, radius)
add_effects(pos, radius)
end

View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright © 2021 Jordan Irwin (AntumDeluge)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,432 @@
sneeker = {}
sneeker.modname = core.get_current_modname()
sneeker.modpath = core.get_modpath(sneeker.modname)
local debugging = core.settings:get_bool("enable_debug_mods", false)
sneeker.log = function(lvl, msg)
if lvl == "debug" and not debugging then return end
if msg == nil then
msg = lvl
lvl = nil
end
msg = "[" .. sneeker.modname .. "] " .. msg
if lvl == "debug" then
msg = "[DEBUG]" .. msg
lvl = nil;
end
if not lvl then
core.log(msg)
else
core.log(lvl, msg)
end
end
local scripts = {
"settings",
"tnt_function",
"spawn",
}
for _, script in ipairs(scripts) do
dofile(sneeker.modpath .. "/" .. script .. ".lua")
end
local function jump(self, pos, direction)
local velocity = self.object:get_velocity()
if core.registered_nodes[core.get_node(pos).name].climbable then
self.object:set_velocity({x=velocity.x, y=4, z=velocity.z})
return
end
local spos = {x=pos.x+direction.x, y=pos.y, z=pos.z+direction.z}
local node = core.get_node_or_nil(spos)
spos.y = spos.y+1
local node2 = core.get_node_or_nil(spos)
local def, def2 = {}
if node and node.name then
def = core.registered_items[node.name]
end
if node2 and node2.name then
def2 = core.registered_items[node2.name]
end
if def and def.walkable
and def2 and not def2.walkable
and def.drawtype ~= "fencelike" then
self.object:set_velocity({
x = velocity.x*2.2,
y = self.jump_height,
z = velocity.z*2.2
})
end
end
local function random_turn(self)
if self.turn_timer > math.random(2, 5) then
local select_turn = math.random(1, 3)
if select_turn == 1 then
self.turn = "left"
elseif select_turn == 2 then
self.turn = "right"
elseif select_turn == 3 then
self.turn = "straight"
end
self.turn_timer = 0
self.turn_speed = 0.05*math.random()
end
end
local def = {
hp_max = 20,
physical = true,
collisionbox = {-0.25, -0.7, -0.25, 0.25, 0.8, 0.25},
visual = "mesh",
mesh = "character.b3d",
textures = {"sneeker.png"},
makes_footstep_sound = false,
-- Original
animation = {
stand_START = 0,
stand_END = 79,
walk_START = 168,
walk_END = 187
},
walk_speed = 1.5,
jump_height = 5,
animation_speed = 30,
knockback_level = 2
}
def.on_activate = function(self, staticdata)
self.yaw = 0
self.anim = 1
self.timer = 0
self.visualx = 1
self.jump_timer = 0
self.turn_timer = 0
self.turn_speed = 0
self.powered = false
self.knockback = false
self.state = math.random(1, 2)
self.old_y = self.object:get_pos().y
-- despawning
self.lifetime = sneeker.lifetime
self.lifetimer = 0
self.check_despawn_player_distance = true
local data = core.deserialize(staticdata)
if data and type(data) == "table" then
if data.powered == true then
self.powered = true
self.object:set_properties({textures = {"sneeker_powered.png"}})
end
else
if math.random(0, 20) == 20 then
self.powered = true
self.object:set_properties({textures = {"sneeker_powered.png"}})
end
end
end
local function isnan(n)
return tostring(n) == tostring((-1)^.5)
end
def.on_step = function(self, dtime)
-- update lifetime timer
-- FIXME: this is longer than realtime
self.lifetimer = self.lifetimer + dtime
if self.lifetimer >= self.lifetime then
-- TODO: should have a death animation
self.object:remove()
return true
end
if self.knockback then
return false
end
local ANIM_STAND = 1
local ANIM_WALK = 2
local pos = self.object:get_pos()
if sneeker.despawn_player_far then
-- run check about once per 60 seconds
local interval_reached = math.floor(self.lifetimer % 60) == 0
if not interval_reached and not self.check_despawn_player_distance then
self.check_despawn_player_distance = true
end
if interval_reached and self.check_despawn_player_distance then
local player_nearby = false
for _, entity in ipairs(core.get_objects_inside_radius(pos, sneeker.despawn_player_radius)) do
if entity:is_player() then
player_nearby = true
break
end
end
if not player_nearby then
self.object:remove()
return true
end
-- set flag to not check again until next interval
self.check_despawn_player_distance = false
end
end
local yaw = self.object:get_yaw()
local inside = core.get_objects_inside_radius(pos, 10)
local walk_speed = self.walk_speed
local animation = self.animation
local anim_speed = self.animation_speed
local velocity = self.object:get_velocity()
self.timer = self.timer+0.01
self.turn_timer = self.turn_timer+0.01
self.jump_timer = self.jump_timer+0.01
if not self.chase
and self.timer > math.random(2, 5) then
if math.random() > 0.8 then
self.state = "stand"
else
self.state = "walk"
end
self.timer = 0
end
if self.turn == "right" then
self.yaw = self.yaw+self.turn_speed
self.object:set_yaw(self.yaw)
elseif self.turn == "left" then
self.yaw = self.yaw-self.turn_speed
self.object:set_yaw(self.yaw)
end
if self.chase and self.visualx < 2 then
if self.hiss == false then
core.sound_play("sneeker_hiss", {pos=pos, gain=1.5, max_hear_distance=2*64})
end
self.visualx = self.visualx+0.05
self.object:set_properties({
visual_size = {x=self.visualx, y=1}
})
self.hiss = true
elseif self.visualx > 1 then
self.visualx = self.visualx-0.05
self.object:set_properties({
visual_size = {x=self.visualx, y=1}
})
self.hiss = false
end
self.chase = false
for _, object in ipairs(inside) do
if object:is_player() then
self.state = "chase"
end
end
if self.state == "stand" then
if self.anim ~= ANIM_STAND then
self.object:set_animation({x=animation.stand_START, y=animation.stand_END}, anim_speed, 0)
self.anim = ANIM_STAND
end
random_turn(self)
if velocity.x ~= 0
or velocity.z ~= 0 then
self.object:set_velocity({x=0, y=velocity.y, z=0})
end
end
if self.state == "walk" then
if self.anim ~= ANIM_WALK then
self.object:set_animation({x=animation.walk_START, y=animation.walk_END}, anim_speed, 0)
self.anim = ANIM_WALK
end
self.direction = {x=math.sin(yaw)*-1, y=-10, z=math.cos(yaw)}
if self.direction then
self.object:set_velocity({x=self.direction.x*walk_speed, y=velocity.y, z=self.direction.z*walk_speed})
end
random_turn(self)
local velocity = self.object:get_velocity()
if self.turn_timer > 1 then
local direction = self.direction
local npos = {x=pos.x+direction.x, y=pos.y+0.2, z=pos.z+direction.z}
if velocity.x == 0 or velocity.z == 0
or core.registered_nodes[core.get_node(npos).name].walkable then
local select_turn = math.random(1, 2)
if select_turn == 1 then
self.turn = "left"
elseif select_turn == 2 then
self.turn = "right"
end
self.turn_timer = 0
self.turn_speed = 0.05*math.random()
end
end
-- Jump
if self.jump_timer > 0.2 then
jump(self, pos, self.direction)
end
end
if self.state == "chase" then
if self.anim ~= ANIM_WALK then
self.object:set_animation({x=animation.walk_START, y=animation.walk_END}, anim_speed, 0)
self.anim = ANIM_WALK
end
self.turn = "straight"
local inside_2 = core.get_objects_inside_radius(pos, 2)
-- Boom
if #inside_2 ~= 0 then
for _, object in ipairs(inside_2) do
if object:is_player() and object:get_hp() ~= 0 then
self.chase = true
if self.visualx >= 2 then
self.object:remove()
sneeker.boom(pos, self.powered)
core.sound_play("sneeker_explode", {pos=pos, gain=sneeker.boom_gain, max_hear_distance=2*64})
return true
end
end
end
end
if #inside ~= 0 then
for _, object in ipairs(inside) do
if object:is_player() and object:get_hp() ~= 0 then
if #inside_2 ~= 0 then
for _, object in ipairs(inside_2) do
-- Stop move
if object:is_player() then
if self.anim ~= ANIM_STAND then
self.object:set_animation({x=animation.stand_START, y=animation.stand_END}, anim_speed, 0)
self.anim = ANIM_STAND
end
self.object:set_velocity({x=0, y=velocity.y, z=0})
return
end
end
end
local ppos = object:get_pos()
self.vec = {x=ppos.x-pos.x, y=ppos.y-pos.y, z=ppos.z-pos.z}
self.yaw = math.atan(self.vec.z/self.vec.x)+math.pi^2
if ppos.x > pos.x then
self.yaw = self.yaw+math.pi
end
self.yaw = self.yaw-2
self.object:set_yaw(self.yaw)
self.direction = {x=math.sin(self.yaw)*-1, y=0, z=math.cos(self.yaw)}
local direction = self.direction
-- FIXME: hack
local can_set = true
for _, c in ipairs({direction.x*2.5, direction.z*2.5}) do
if isnan(c) then
can_set = false
break
end
end
if can_set then
self.object:set_velocity({x=direction.x*2.5, y=velocity.y, z=direction.z*2.5})
end
-- Jump
if self.jump_timer > 0.2 then
jump(self, pos, direction)
end
end
end
else
self.state = "stand"
end
end
-- Swim
local node = core.get_node(pos)
if core.get_item_group(node.name, "water") ~= 0 then
self.object:set_acceleration({x=0, y=1, z=0})
local velocity = self.object:get_velocity()
if self.object:get_velocity().y > 5 then
self.object:set_velocity({x=0, y=velocity.y-velocity.y/2, z=0})
else
self.object:set_velocity({x=0, y=velocity.y+1, z=0})
end
else
self.object:set_acceleration({x=0, y=-10, z=0})
end
return true
end
def.on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
if self.knockback == false then
local knockback_level = self.knockback_level
self.object:set_velocity({x=dir.x*knockback_level, y=3, z=dir.z*knockback_level})
self.knockback = true
core.after(0.6, function()
self.knockback = false
end)
end
if self.object:get_hp() < 1 then
local pos = self.object:get_pos()
local x = 1/math.random(1, 5)*dir.x
local z = 1/math.random(1, 5)*dir.z
local p = {x=pos.x+x, y=pos.y, z=pos.z+z}
local node = core.get_node_or_nil(p)
if node == nil or not node.name or node.name ~= "air" then
p = pos
end
local obj = core.add_item(p, {name="tnt:gunpowder", count=math.random(0, 2)})
end
end
def.get_staticdata = function(self)
return core.serialize({
powered = self.powered
})
end
core.register_entity("sneeker:sneeker", def)
core.register_craftitem("sneeker:spawnegg", {
description = "Sneeker Spawn Egg",
inventory_image = "sneeker_spawnegg.png",
stack_max = 64,
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.type == "node" then
local pos = pointed_thing.above
pos.y = pos.y+1
core.add_entity(pos, "sneeker:sneeker")
if not core.settings:get_bool("creative_mode", false) then
itemstack:take_item()
end
return itemstack
end
end
})

View File

@ -0,0 +1,7 @@
name = sneeker
title = Sneeker
description = An explosive nuisance.
version = 1.0
author = Rui
depends = default, tnt
optional_depends = nether

View File

@ -0,0 +1,108 @@
--- Settings for sneeker mod.
--
-- @module settings.lua
local time_min = 60
--- How long (in seconds) sneeker remains in world after spawn.
--
-- @setting sneeker.lifespan
-- @settype int
-- @default 900 (15 minutes)
sneeker.lifetime = tonumber(core.settings:get("sneeker.lifetime") or time_min * 15)
--- Loudness of explosion.
--
-- @setting sneeker.boom_gain
-- @settype float
-- @default 1.5
sneeker.boom_gain = tonumber(core.settings:get("sneeker.boom_gain") or 1.5)
--- Determines whether or not a player must be close for spawn to occur.
--
-- @setting sneeker.spawn_require_player_nearby
-- @settype bool
-- @default true
sneeker.spawn_require_player_nearby = core.settings:get_bool("sneeker.spawn_require_player_nearby", true)
--- Distance in nodes a player must be for spawn to occur.
--
-- Only used if `sneeker.spawn_require_player_nearby` enabled.
--
-- @setting sneeker.spawn_player_radius
-- @settype int
-- @default 100
sneeker.spawn_player_radius = tonumber(core.settings:get("sneeker.spawn_player_radius") or 100)
--- If enabled, mobs not near any players will despawn.
--
-- @setting sneeker.despawn_player_far
-- @settype bool
-- @default true
sneeker.despawn_player_far = core.settings:get_bool("sneeker.despawn_player_far", true)
--- Distance determining if a player is near enough to prevent despawn.
--
-- Only used if `sneeker.despawn_player_far` enabled.
--
-- @setting sneeker.despawn_player_radius
-- @settype int
-- @default 500
sneeker.despawn_player_radius = tonumber(core.settings:get("sneeker.despawn_player_radius") or 500)
--- Sets possibility for spawn.
--
-- Inverted value (e.g. 10000 = 1/10000).
--
-- @setting sneeker.spawn_chance
-- @settype int
-- @default 10000
sneeker.spawn_chance = tonumber(core.settings:get("sneeker.spawn_chance") or 10000)
--- Sets frequency of spawn chance.
--
-- @setting sneeker.spawn_interval
-- @settype int
-- @default 240 (4 minutes)
sneeker.spawn_interval = tonumber(core.settings:get("sneeker.spawn_interval") or time_min * 4)
--- Sets the minimum light that a node must have for spawn to occur.
--
-- Value can be set between 0 (no light) & 15 (max light).
--
-- @setting sneeker.spawn_minlight
-- @settype int
-- @default 0
sneeker.spawn_minlight = tonumber(core.settings:get("sneeker.spawn_minlight") or 0)
--- Sets the maximum light that a node can have for spawn to occur.
--
-- Value can be set between 0 (no light) & 15 (max light).
--
-- @setting sneeker.spawn_maxlight
-- @settype int
-- @default 4
sneeker.spawn_maxlight = tonumber(core.settings:get("sneeker.spawn_maxlight") or 4)
--- Sets the lowest position at which sneeker can spawn.
--
-- @setting sneeker.spawn_minheight
-- @settype int
-- @default -31000
sneeker.spawn_minheight = tonumber(core.settings:get("sneeker.spawn_minheight") or -31000)
--- Sets the highest position at which sneeker can spawn.
--
-- @setting sneeker.spawn_maxheight
-- @settype int
-- @default 31000
sneeker.spawn_maxheight = tonumber(core.settings:get("sneeker.spawn_maxheight") or 31000)
--- Limits the number of entities that can spawn per mapblock (16x16x16).
--
-- @setting sneeker.spawn_mapblock_limit
-- @settype int
-- @default 1
sneeker.spawn_mapblock_limit = tonumber(core.settings:get("sneeker.spawn_mapblock_limit") or 1)

View File

@ -0,0 +1,52 @@
# Extra debugging messages.
enable_debug_mods (Mod debugging) bool false
# How long (in seconds) sneeker remains in world after spawn.
#
# Default: 900 (15 minutes)
sneeker.lifetime (Sneeker lifetime) int 900
# Loudness of explosion.
#
# Those with a weak heart might want to turn it down.
sneeker.boom_gain (Boom volume) float 1.5
# Determines whether or not a player must be close for spawn to occur.
sneeker.spawn_require_player_nearby (Require player nearby for spawn) bool true
# Distance in nodes a player must be for spawn to occur.
#
# Only used if `sneeker.spawn_require_player_nearby` enabled.
sneeker.spawn_player_radius (Player spawn detect radius) int 100
# If enabled, mobs not near any players will despawn.
sneeker.despawn_player_far (Despawn sneekers not near players) bool true
# Distance determining if a player is near enough to prevent despawn.
#
# Only used if `sneeker.despawn_player_far` enabled.
sneeker.despawn_player_radius (Player despawn detect radius) int 500
# Sets possibility for spawn.
#
# Rate is the inverted value (e.g. 1/value).
sneeker.spawn_chance (Sneeker spawn chance) int 10000
# Sets frequency of spawn chance. Default 240 is equivalent to 4 minutes (60 * 4).
sneeker.spawn_interval (Sneeker spawn interval) int 240
# Sets the minimum light that a node must have for spawn to occur.
sneeker.spawn_minlight (Sneeker min light for spawn) int 0 0 15
# Sets the maximum light that a node can have for spawn to occur.
sneeker.spawn_maxlight (Sneeker max light for spawn) int 4 0 15
# Sets the lowest position at which sneeker can spawn.
sneeker.spawn_minheight (Sneeker min spawn height) int -31000
# Sets the highest position at which sneeker can spawn.
sneeker.spawn_maxheight (Sneeker max spawn height) int 31000
# Limits the number of entities that can spawn per mapblock (16x16x16).
sneeker.spawn_mapblock_limit (Sneeker spawn limit) int 1

View File

@ -0,0 +1,70 @@
local spawn_nodes = {
"default:dirt_with_dry_grass",
"default:dry_dirt",
"default:dry_dirt_with_dry_grass",
"default:desert_sand",
}
if core.global_exists("nether") then
table.insert(spawn_nodes, "nether:rack")
end
for _, node_name in ipairs(spawn_nodes) do
if not core.registered_nodes[node_name] then
sneeker.log("warning", "Invalid node for spawn: " .. node_name)
end
end
core.register_abm({
nodenames = spawn_nodes,
neighbors = {"air"},
interval = sneeker.spawn_interval,
chance = sneeker.spawn_chance,
action = function(pos, node, aoc, aocw)
if aoc >= sneeker.spawn_mapblock_limit then return end
-- check above target node
pos.y = pos.y+1
local pos_string = tostring(math.floor(pos.x))
.. "," .. tostring(math.floor(pos.y))
.. "," .. tostring(math.floor(pos.z))
if sneeker.spawn_require_player_nearby then
local player_nearby = false
for _, entity in ipairs(core.get_objects_inside_radius(pos, sneeker.spawn_player_radius)) do
if entity:is_player() then
player_nearby = true
break
end
end
if not player_nearby then return end
end
if pos.y > sneeker.spawn_maxheight or pos.y < sneeker.spawn_minheight then
return
end
-- needs two vertical air nodes to spawn
for _, node_pos in ipairs({pos, {x=pos.x, y=pos.y+1, z=pos.z}}) do
if core.get_node(node_pos).name ~= "air" then
return
end
end
local llevel = core.get_node_light(pos)
if not llevel or llevel > sneeker.spawn_maxlight or llevel < sneeker.spawn_minlight then
return
end
local spawned = core.add_entity(pos, "sneeker:sneeker")
if not spawned then
sneeker.log("warning", "Failed to spawn at: " .. pos_string)
else
sneeker.log("debug", "Spawned at: " .. pos_string)
end
end
})

View File

Before

Width:  |  Height:  |  Size: 353 B

After

Width:  |  Height:  |  Size: 353 B

View File

Before

Width:  |  Height:  |  Size: 355 B

After

Width:  |  Height:  |  Size: 355 B

View File

Before

Width:  |  Height:  |  Size: 139 B

After

Width:  |  Height:  |  Size: 139 B

View File

Before

Width:  |  Height:  |  Size: 249 B

After

Width:  |  Height:  |  Size: 249 B

View File

@ -0,0 +1,302 @@
--[[ From TNT
License of source code
----------------------
The MIT License (MIT)
Copyright (C) 2014-2016 PilzAdam
Copyright (C) 2014-2016 ShadowNinja
Copyright (C) 2016 sofar (sofar@foo-projects.org)
Copyright (C) 2014-2016 Various Minetest developers and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
For more details:
https://opensource.org/licenses/MIT
===================================
Licenses of media
-----------------
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
Copyright (C) 2014-2016 BlockMen
Copyright (C) 2014-2016 ShadowNinja
Copyright (C) 2015-2016 Wuzzy
Copyright (C) 2016 sofar (sofar@foo-projects.org)
Copyright (C) 2018 paramat
You are free to:
Share copy and redistribute the material in any medium or format.
Adapt remix, transform, and build upon the material for any purpose, even commercially.
The licensor cannot revoke these freedoms as long as you follow the license terms.
Under the following terms:
Attribution You must give appropriate credit, provide a link to the license, and
indicate if changes were made. You may do so in any reasonable manner, but not in any way
that suggests the licensor endorses you or your use.
ShareAlike If you remix, transform, or build upon the material, you must distribute
your contributions under the same license as the original.
No additional restrictions You may not apply legal terms or technological measures that
legally restrict others from doing anything the license permits.
Notices:
You do not have to comply with the license for elements of the material in the public
domain or where your use is permitted by an applicable exception or limitation.
No warranties are given. The license may not give you all of the permissions necessary
for your intended use. For example, other rights such as publicity, privacy, or moral
rights may limit how you use the material.
For more details:
http://creativecommons.org/licenses/by-sa/3.0/
====================================================
CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
for audio files (found in sounds folder)
TumeniNodes
steveygos93
theneedle.tv
frankelmedico
No Copyright
The person who associated a work with this deed has dedicated the work to the public domain
by waiving all of his or her rights to the work worldwide under copyright law, including all
related and neighboring rights, to the extent allowed by law.
You can copy, modify, distribute and perform the work, even for commercial purposes, all
without asking permission. See Other Information below.
In no way are the patent or trademark rights of any person affected by CC0, nor are the
rights that other persons may have in the work or in how the work is used, such as publicity
or privacy rights.
Unless expressly stated otherwise, the person who associated a work with this deed makes no
warranties about the work, and disclaims liability for all uses of the work, to the fullest
extent permitted by applicable law.
When using or citing the work, you should not imply endorsement by the author or the affirmer.
This license is acceptable for Free Cultural Works.
For more Information:
https://creativecommons.org/publicdomain/zero/1.0/
]]
local cid_data = {}
local radius = tonumber(core.settings:get("tnt_radius") or 3)
local large_radius = 5
local loss_prob = {
["default:cobble"] = 3,
["default:dirt"] = 4,
}
core.after(0, function()
for name, def in pairs(core.registered_nodes) do
cid_data[core.get_content_id(name)] = {
name = name,
drops = def.drops,
flammable = def.groups.flammable,
}
end
end)
local function rand_pos(center, pos, radius)
pos.x = center.x + math.random(-radius, radius)
pos.z = center.z + math.random(-radius, radius)
end
local function eject_drops(drops, pos, radius)
local drop_pos = vector.new(pos)
for _, item in pairs(drops) do
local count = item:get_count()
local max = item:get_stack_max()
if count > max then
item:set_count(max)
end
while count > 0 do
if count < max then
item:set_count(count)
end
rand_pos(pos, drop_pos, radius)
local obj = core.add_item(drop_pos, item)
if obj then
obj:get_luaentity().collect = true
obj:set_acceleration({x=0, y=-10, z=0})
obj:set_velocity({x=math.random(-3, 3), y=10,
z=math.random(-3, 3)})
end
count = count - max
end
end
end
local function add_drop(drops, item)
item = ItemStack(item)
local name = item:get_name()
if loss_prob[name] ~= nil and math.random(1, loss_prob[name]) == 1 then
return
end
local drop = drops[name]
if drop == nil then
drops[name] = item
else
drop:set_count(drop:get_count() + item:get_count())
end
end
local function destroy(drops, pos, cid)
if core.is_protected(pos, "") then
return
end
local def = cid_data[cid]
if def and def.on_blast then
def.on_blast(vector.new(pos), 1)
return
end
core.remove_node(pos)
if def then
local node_drops = core.get_node_drops(def.name, "")
for _, item in ipairs(node_drops) do
add_drop(drops, item)
end
end
end
local function calc_velocity(pos1, pos2, old_vel, power)
local vel = vector.direction(pos1, pos2)
vel = vector.normalize(vel)
vel = vector.multiply(vel, power)
-- Divide by distance
local dist = vector.distance(pos1, pos2)
dist = math.max(dist, 1)
vel = vector.divide(vel, dist)
-- Add old velocity
vel = vector.add(vel, old_vel)
return vel
end
local function entity_physics(pos, radius)
-- Make the damage radius larger than the destruction radius
radius = radius * 2
local objs = core.get_objects_inside_radius(pos, radius)
for _, obj in pairs(objs) do
local obj_pos = obj:get_pos()
local obj_vel = obj:get_velocity()
local dist = math.max(1, vector.distance(pos, obj_pos))
if obj_vel ~= nil then
obj:set_velocity(calc_velocity(pos, obj_pos,
obj_vel, radius * 10))
end
local damage = (5 / dist) * radius
obj:set_hp(obj:get_hp() - damage)
end
end
local function add_effects(pos, radius)
core.add_particlespawner({
amount = 128,
time = 1,
minpos = vector.subtract(pos, radius / 2),
maxpos = vector.add(pos, radius / 2),
minvel = {x=-20, y=-20, z=-20},
maxvel = {x=20, y=20, z=20},
minacc = vector.new(),
maxacc = vector.new(),
minexptime = 1,
maxexptime = 3,
minsize = 8,
maxsize = 16,
texture = "sneeker_smoke.png",
})
end
local function explode(pos, radius)
local pos = vector.round(pos)
local vm = VoxelManip()
local pr = PseudoRandom(os.time())
local p1 = vector.subtract(pos, radius)
local p2 = vector.add(pos, radius)
local minp, maxp = vm:read_from_map(p1, p2)
local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
local data = vm:get_data()
local drops = {}
local p = {}
local c_air = core.get_content_id("air")
local c_tnt = nil
if core.settings:get_bool("enable_tnt", false) then
c_tnt = core.get_content_id("tnt:tnt")
end
local c_tnt_burning = core.get_content_id("tnt:tnt_burning")
local c_gunpowder = core.get_content_id("tnt:gunpowder")
local c_gunpowder_burning = core.get_content_id("tnt:gunpowder_burning")
local c_boom = core.get_content_id("tnt:boom")
for z = -radius, radius do
for y = -radius, radius do
local vi = a:index(pos.x + (-radius), pos.y + y, pos.z + z)
for x = -radius, radius do
if (x * x) + (y * y) + (z * z) <=
(radius * radius) + pr:next(-radius, radius) then
local cid = data[vi]
p.x = pos.x + x
p.y = pos.y + y
p.z = pos.z + z
if cid == c_tnt or cid == c_gunpowder then
burn(p)
elseif cid ~= c_tnt_burning and
cid ~= c_gunpowder_burning and
cid ~= c_air and
cid ~= c_boom then
destroy(drops, p, cid)
end
end
vi = vi + 1
end
end
end
return drops
end
function sneeker.boom(pos, large)
local radius = radius
if large then
radius = large_radius
end
core.sound_play("sneeker_explode", {pos=pos, gain=1.5, max_hear_distance=2*64})
core.set_node(pos, {name="tnt:boom"})
core.get_node_timer(pos):start(0.5)
local drops = explode(pos, radius)
entity_physics(pos, radius)
eject_drops(drops, pos, radius)
add_effects(pos, radius)
end

View File

@ -576,29 +576,57 @@ slingshot.require_rubber_band (Require rubber band in craft recipe) bool true
[*sneeker]
# Sets maximum number of spawns that can exist in world.
sneeker.spawn_cap (Maximum spawns) int 10
# Extra debugging messages.
enable_debug_mods (Mod debugging) bool false
# How long (in seconds) sneeker remains in world after spawn.
#
# Default: 900 (15 minutes)
sneeker.lifetime (Sneeker lifetime) int 900
# Loudness of explosion.
#
# Those with a weak heart might want to turn it down.
sneeker.boom_gain (Boom volume) float 1.5
# Determines whether or not a player must be close for spawn to occur.
sneeker.spawn_require_player_nearby (Require player nearby for spawn) bool true
# Distance in nodes a player must be for spawn to occur.
#
# Only used if `sneeker.spawn_require_player_nearby` enabled.
sneeker.spawn_player_radius (Player spawn detect radius) int 100
# If enabled, mobs not near any players will despawn.
sneeker.despawn_player_far (Despawn sneekers not near players) bool true
# Distance determining if a player is near enough to prevent despawn.
#
# Only used if `sneeker.despawn_player_far` enabled.
sneeker.despawn_player_radius (Player despawn detect radius) int 500
# Sets possibility for spawn.
sneeker.spawn_chance (Spawn chance) int 1000
#
# Rate is the inverted value (e.g. 1/value).
sneeker.spawn_chance (Sneeker spawn chance) int 10000
# Sets frequency of spawn chance.
# Default 2400 is equivalent to 2 minutes (60 * 4).
sneeker.spawn_interval (Spawn interval) int 2400
# Sets frequency of spawn chance. Default 240 is equivalent to 4 minutes (60 * 4).
sneeker.spawn_interval (Sneeker spawn interval) int 240
# Sets the minimum light that a node must have for spawn to occur.
sneeker.spawn_minlight (Sneeker min light for spawn) int 0 0 15
# Sets the maximum light that a node can have for spawn to occur.
sneeker.spawn_maxlight (Max node light for spawn) int 5
sneeker.spawn_maxlight (Sneeker max light for spawn) int 4 0 15
# Sets the lowest position at which sneeker can spawn.
sneeker.spawn_minheight (Sneeker min spawn height) int -31000
[*spawneggs]
# Sets the highest position at which sneeker can spawn.
sneeker.spawn_maxheight (Sneeker max spawn height) int 31000
spawneggs.egg_interval (Spawn interval) int 600
spawneggs.egg_chance (Spawn chance) int 3000
spawneggs.grass_interval (Grass interval) int 600
spawneggs.grass_chance (Grass chance) int 3000
# Allow eggs to spawn randomly in the world.
spawneggs.enable_node_spawn (Enable node spawn) bool true
# Limits the number of entities that can spawn per mapblock (16x16x16).
sneeker.spawn_mapblock_limit (Sneeker spawn limit) int 1
[*trampoline]