Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
22e81d5d27 | ||
|
8e32772287 | ||
|
c599620e9d | ||
|
8ab2107d37 | ||
|
c8757c94a0 | ||
|
e6ff7a1b70 | ||
|
12e6bd79db | ||
|
4b8452538e | ||
|
031664d275 | ||
|
1321b3092f | ||
|
ef962fcc12 | ||
|
7bf5b9a927 | ||
|
be4da85462 | ||
|
776bd77a61 | ||
|
ab748fdecb | ||
|
ad2786131c | ||
|
8e2bef6127 | ||
|
dc2f803cff | ||
|
40d0ba9301 | ||
|
f51fa72f59 | ||
|
b4e1acc75e | ||
|
a12b8eb0dd | ||
|
b133b86d34 | ||
|
b020b803b2 | ||
|
56fdaac34f | ||
|
3a3acc8dae |
12
CHANGES.txt
12
CHANGES.txt
@@ -1,12 +0,0 @@
|
|||||||
|
|
||||||
1.0
|
|
||||||
- Forked & renamed from Rui's original "creeper" mod.
|
|
||||||
- Updated for Minetest 5.x API.
|
|
||||||
- Changed to MIT license.
|
|
||||||
- Changed spawn nodes:
|
|
||||||
- default:dirt_with_dry_grass
|
|
||||||
- default:dry_dirt
|
|
||||||
- default:dry_dirt_with_dry_grass
|
|
||||||
- default:desert_sand
|
|
||||||
- Spawns on "nether:rack" if nether mod available.
|
|
||||||
- Spawning attributes can now be set in configuration file.
|
|
78
README.md
78
README.md
@@ -1,82 +1,40 @@
|
|||||||
## Sneeker mod for Minetest
|
## Sneeker mod for Minetest
|
||||||
|
|
||||||
---
|
|
||||||
### Description:
|
### Description:
|
||||||
|
|
||||||
An explosive nuisance for [Minetest](http://minetest.net/).
|
An explosive nuisance for [Minetest](http://minetest.net/).
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
---
|
|
||||||
### Licensing:
|
### Licensing:
|
||||||
|
|
||||||
- Code: [MIT](LICENSE.txt)
|
- Code: [MIT](LICENSE.txt)
|
||||||
- Original by Rui: WTFPL
|
- Original by Rui: WTFPL
|
||||||
- tnt_function code: [MIT](tnt_function.lua)
|
- tnt_function code: [MIT](tnt_function.lua)
|
||||||
|
|
||||||
---
|
|
||||||
### Usage:
|
### Usage:
|
||||||
|
|
||||||
Settings:
|
Settings documented in [reference][].
|
||||||
- ***sneeker.lifetime***
|
|
||||||
- How long (in seconds) sneeker remains in world after spawn.
|
### Requirements:
|
||||||
- type: int
|
|
||||||
- default: 900 (15 minutes)
|
- Depends: default, tnt
|
||||||
- ***sneeker.boom_gain***
|
- Optional depends: nether, sounds, simple_protection
|
||||||
- Loudness of explosion.
|
|
||||||
- type: float
|
|
||||||
- default: 1.5
|
|
||||||
- ***sneeker.spawn_require_player_nearby***
|
|
||||||
- Determines whether or not a player must be close for spawn to occur.
|
|
||||||
- type: bool
|
|
||||||
- default: true
|
|
||||||
- ***sneeker.spawn_player_radius***
|
|
||||||
- Distance a player must be within for spawn to occur.
|
|
||||||
- type: int
|
|
||||||
- default: 100
|
|
||||||
- ***sneeker.despawn_player_far***
|
|
||||||
- If enabled, mobs not near any players will despawn.
|
|
||||||
- type: bool
|
|
||||||
- default: true
|
|
||||||
- ***sneeker.despawn_player_radius***
|
|
||||||
- Distance determining if a player is near enough to prevent despawn.
|
|
||||||
- type: int
|
|
||||||
- default: 500
|
|
||||||
- ***sneeker.spawn_chance***
|
|
||||||
- Sets possibility for spawn.
|
|
||||||
- type: int
|
|
||||||
- default: 10000
|
|
||||||
- ***sneeker.spawn_interval***
|
|
||||||
- Sets frequency of spawn chance.
|
|
||||||
- type: int
|
|
||||||
- default: 240 (4 minutes)
|
|
||||||
- ***sneeker.spawn_minlight***
|
|
||||||
- Sets the minimum light that a node must have for spawn to occur.
|
|
||||||
- type: int
|
|
||||||
- default: 0
|
|
||||||
- ***sneeker.spawn_maxlight***
|
|
||||||
- Sets the maximum light that a node can have for spawn to occur.
|
|
||||||
- type: int
|
|
||||||
- default: 4
|
|
||||||
- ***sneeker.spawn_minheight***
|
|
||||||
- Sets the maximum light that a node can have for spawn to occur.
|
|
||||||
- type: int
|
|
||||||
- default: -31000
|
|
||||||
- ***sneeker.spawn_maxheight***
|
|
||||||
- Sets the lowest position at which sneeker can spawn.
|
|
||||||
- type: int
|
|
||||||
- default 31000
|
|
||||||
- ***sneeker.spawn_mapblock_limit***
|
|
||||||
- Limits the number of entities that can spawn per mapblock (16x16x16).
|
|
||||||
- type: int
|
|
||||||
- default: 1
|
|
||||||
|
|
||||||
---
|
|
||||||
### Links:
|
### Links:
|
||||||
|
|
||||||
|
- [](https://content.minetest.net/packages/AntumDeluge/sneeker/)
|
||||||
- [Forum thread](https://forum.minetest.net/viewtopic.php?t=26685)
|
- [Forum thread](https://forum.minetest.net/viewtopic.php?t=26685)
|
||||||
- [Original forum thread](https://forum.minetest.net/viewtopic.php?t=11891)
|
|
||||||
- [Git repo](https://github.com/AntumMT/mod-sneeker)
|
- [Git repo](https://github.com/AntumMT/mod-sneeker)
|
||||||
- [Reference](https://antummt.github.io/mod-sneeker/docs/api.html)
|
- [Reference][reference]
|
||||||
- [Changelog](CHANGES.txt)
|
- [Changelog](changelog.txt)
|
||||||
- [TODO](TODO.txt)
|
- [TODO](TODO.txt)
|
||||||
|
|
||||||
|
Rui's original mod:
|
||||||
|
|
||||||
|
- Forum thread (deleted: `t=11891`)
|
||||||
|
- [Final version](https://github.com/AntumMT/mod-sneeker/releases/tag/Rui)
|
||||||
|
- [Updated for Minetest 5.x](https://github.com/AntumMT/mod-sneeker/releases/tag/5.x)
|
||||||
|
|
||||||
|
|
||||||
|
[reference]: https://antummt.github.io/mod-sneeker/docs/reference/
|
||||||
|
3
TODO.txt
3
TODO.txt
@@ -1,2 +1,5 @@
|
|||||||
|
|
||||||
TODO:
|
TODO:
|
||||||
|
- add version using mobs_redo API
|
||||||
|
- add version using cmer API
|
||||||
|
- add griefing option
|
||||||
|
21
changelog.txt
Normal file
21
changelog.txt
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
v1.1
|
||||||
|
----
|
||||||
|
- added sound when hit
|
||||||
|
- fixed entity vertical positioning
|
||||||
|
- fixed tnt:boom node left after explosion
|
||||||
|
- added setting to customize spawn nodes
|
||||||
|
- added simple_protection support
|
||||||
|
|
||||||
|
v1.0
|
||||||
|
----
|
||||||
|
- forked & renamed from Rui's original "creeper" mod
|
||||||
|
- updated for Minetest 5.x API
|
||||||
|
- changed to MIT license
|
||||||
|
- changed spawn nodes:
|
||||||
|
- default:dirt_with_dry_grass
|
||||||
|
- default:dry_dirt
|
||||||
|
- default:dry_dirt_with_dry_grass
|
||||||
|
- default:desert_sand
|
||||||
|
- spawns on "nether:rack" if nether mod available
|
||||||
|
- spawning attributes can now be set in configuration file
|
@@ -1,13 +1,13 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
DOCS="$(dirname $(readlink -f $0))"
|
docs="$(dirname $(readlink -f $0))"
|
||||||
ROOT="$(dirname ${DOCS})"
|
root="$(dirname ${docs})"
|
||||||
CONFIG="${DOCS}/config.ld"
|
config="${docs}/config.ld"
|
||||||
|
|
||||||
cd "${ROOT}"
|
cd "${root}"
|
||||||
|
|
||||||
# Clean old files
|
# Clean old files
|
||||||
rm -rf "${DOCS}/api.html" "${DOCS}/scripts" "${DOCS}/modules"
|
rm -rf "${docs}/reference"
|
||||||
|
|
||||||
# Create new files
|
# Create new files
|
||||||
ldoc -c "${CONFIG}" -d "${DOCS}" -o "api" "${ROOT}"
|
ldoc -c "${config}" -d "${docs}/reference" "${root}"
|
||||||
|
@@ -104,6 +104,10 @@
|
|||||||
<td class="name" nowrap><a href="#sneeker.spawn_mapblock_limit">sneeker.spawn_mapblock_limit</a></td>
|
<td class="name" nowrap><a href="#sneeker.spawn_mapblock_limit">sneeker.spawn_mapblock_limit</a></td>
|
||||||
<td class="summary">Limits the number of entities that can spawn per mapblock (16x16x16).</td>
|
<td class="summary">Limits the number of entities that can spawn per mapblock (16x16x16).</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="name" nowrap><a href="#sneeker.spawn_nodes">sneeker.spawn_nodes</a></td>
|
||||||
|
<td class="summary">Comma-separated list of nodes on which sneeker can spawn.</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
@@ -201,7 +205,7 @@
|
|||||||
<dd>
|
<dd>
|
||||||
Distance in nodes a player must be for spawn to occur. </p>
|
Distance in nodes a player must be for spawn to occur. </p>
|
||||||
|
|
||||||
<p> Only used if <a href="api.html#sneeker.spawn_require_player_nearby">sneeker.spawn_require_player_nearby</a> enabled.
|
<p> Only used if <a href="index.html#sneeker.spawn_require_player_nearby">sneeker.spawn_require_player_nearby</a> enabled.
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -257,7 +261,7 @@
|
|||||||
<dd>
|
<dd>
|
||||||
Distance determining if a player is near enough to prevent despawn. </p>
|
Distance determining if a player is near enough to prevent despawn. </p>
|
||||||
|
|
||||||
<p> Only used if <a href="api.html#sneeker.despawn_player_far">sneeker.despawn_player_far</a> enabled.
|
<p> Only used if <a href="index.html#sneeker.despawn_player_far">sneeker.despawn_player_far</a> enabled.
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -473,6 +477,33 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
<a name = "sneeker.spawn_nodes"></a>
|
||||||
|
<strong>sneeker.spawn_nodes</strong>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
Comma-separated list of nodes on which sneeker can spawn.
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
</ul>
|
||||||
|
</ul>
|
||||||
|
</ul>
|
||||||
|
<h3>Type:</h3>
|
||||||
|
<ul>
|
||||||
|
<i>string</i>
|
||||||
|
</ul>
|
||||||
|
<h3>Default:</h3>
|
||||||
|
<ul>
|
||||||
|
<i>default:dirt_with_dry_grass,default:dry_dirt,default:dry_dirt_with_dry_grass,default:desert_sand,nether:rack</i>
|
||||||
|
</ul>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
@@ -480,8 +511,8 @@
|
|||||||
</div> <!-- id="content" -->
|
</div> <!-- id="content" -->
|
||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/AntumDeluge/LDoc">LDoc 1.4.6-antum-2</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
||||||
<i style="float:right;">Last updated 2021-05-08 21:15:42 </i>
|
<i style="float:right;">Last updated 2021-07-20 11:23:32 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
443
entity.lua
Normal file
443
entity.lua
Normal file
@@ -0,0 +1,443 @@
|
|||||||
|
|
||||||
|
local hit_sound
|
||||||
|
|
||||||
|
if core.get_modpath("default") then
|
||||||
|
hit_sound = "player_damage"
|
||||||
|
elseif core.get_modpath("sounds") then
|
||||||
|
hit_sound = "sounds_entity_hit"
|
||||||
|
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 walk_speed = 1.5
|
||||||
|
|
||||||
|
local def = {
|
||||||
|
hp_max = 20,
|
||||||
|
physical = true,
|
||||||
|
collisionbox = {-0.25, 0.3, -0.25, 0.25, 1.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 = walk_speed,
|
||||||
|
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
|
||||||
|
|
||||||
|
local function expand(self)
|
||||||
|
if self.chase and self.visualx < 2 then
|
||||||
|
if self.hiss == false then
|
||||||
|
core.sound_play("sneeker_hiss", {object=self.object, 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
|
||||||
|
end
|
||||||
|
|
||||||
|
local function explode(self, pos)
|
||||||
|
self.object:remove()
|
||||||
|
sneeker.boom(pos, self.powered)
|
||||||
|
core.sound_play("sneeker_explode", {object=self.object, gain=sneeker.boom_gain, max_hear_distance=2*64})
|
||||||
|
end
|
||||||
|
|
||||||
|
local function h_collides(pos, collision_info, touching_ground)
|
||||||
|
if not touching_ground or type(collision_info) ~= "table" or #collision_info == 0 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local pos_y = math.floor(pos.y)
|
||||||
|
local h_col
|
||||||
|
|
||||||
|
for _, col in ipairs(collision_info) do
|
||||||
|
local npos = col.node_pos
|
||||||
|
if npos and col.type == "node" then
|
||||||
|
-- exclude ground collisions
|
||||||
|
if math.floor(npos.y) > pos_y then
|
||||||
|
h_col = col
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not h_col then return false end
|
||||||
|
|
||||||
|
local h_vel = {
|
||||||
|
x = math.floor(h_col.new_velocity.x * 10) / 10,
|
||||||
|
z = math.floor(h_col.new_velocity.z * 10) / 10,
|
||||||
|
}
|
||||||
|
|
||||||
|
return h_vel.x < walk_speed and h_vel.z < walk_speed, h_col.node_pos
|
||||||
|
end
|
||||||
|
|
||||||
|
def.on_step = function(self, dtime, moveresult)
|
||||||
|
-- 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
|
||||||
|
|
||||||
|
if self.chase or self.state == "chase" or self.state == "walk" then
|
||||||
|
local collided, npos = h_collides(pos, moveresult.collisions, moveresult.touching_ground)
|
||||||
|
if collided then
|
||||||
|
jump(self, npos, self.direction)
|
||||||
|
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
|
||||||
|
|
||||||
|
expand(self)
|
||||||
|
|
||||||
|
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
|
||||||
|
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
|
||||||
|
explode(self, pos)
|
||||||
|
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
|
||||||
|
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 hit_sound then
|
||||||
|
core.sound_play(hit_sound, {object=self.object}, parameters, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
})
|
397
init.lua
397
init.lua
@@ -29,404 +29,9 @@ local scripts = {
|
|||||||
"settings",
|
"settings",
|
||||||
"tnt_function",
|
"tnt_function",
|
||||||
"spawn",
|
"spawn",
|
||||||
|
"entity",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, script in ipairs(scripts) do
|
for _, script in ipairs(scripts) do
|
||||||
dofile(sneeker.modpath .. "/" .. script .. ".lua")
|
dofile(sneeker.modpath .. "/" .. script .. ".lua")
|
||||||
end
|
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
|
|
||||||
})
|
|
||||||
|
4
mod.conf
4
mod.conf
@@ -1,7 +1,7 @@
|
|||||||
name = sneeker
|
name = sneeker
|
||||||
title = Sneeker
|
title = Sneeker
|
||||||
description = An explosive nuisance.
|
description = An explosive nuisance.
|
||||||
version = 1.0
|
version = 1.1
|
||||||
author = Rui
|
author = Rui
|
||||||
depends = default, tnt
|
depends = default, tnt
|
||||||
optional_depends = nether
|
optional_depends = nether, sounds, simple_protection
|
||||||
|
@@ -106,3 +106,11 @@ sneeker.spawn_maxheight = tonumber(core.settings:get("sneeker.spawn_maxheight")
|
|||||||
-- @settype int
|
-- @settype int
|
||||||
-- @default 1
|
-- @default 1
|
||||||
sneeker.spawn_mapblock_limit = tonumber(core.settings:get("sneeker.spawn_mapblock_limit") or 1)
|
sneeker.spawn_mapblock_limit = tonumber(core.settings:get("sneeker.spawn_mapblock_limit") or 1)
|
||||||
|
|
||||||
|
--- Comma-separated list of nodes on which sneeker can spawn.
|
||||||
|
--
|
||||||
|
-- @setting sneeker.spawn_nodes
|
||||||
|
-- @settype string
|
||||||
|
-- @default default:dirt_with_dry_grass,default:dry_dirt,default:dry_dirt_with_dry_grass,default:desert_sand,nether:rack
|
||||||
|
sneeker.spawn_nodes = core.settings:get("sneeker.spawn_nodes") or "default:dirt_with_dry_grass,default:dry_dirt,default:dry_dirt_with_dry_grass,default:desert_sand,nether:rack"
|
||||||
|
sneeker.spawn_nodes = sneeker.spawn_nodes:trim()
|
||||||
|
@@ -50,3 +50,6 @@ sneeker.spawn_maxheight (Sneeker max spawn height) int 31000
|
|||||||
|
|
||||||
# Limits the number of entities that can spawn per mapblock (16x16x16).
|
# Limits the number of entities that can spawn per mapblock (16x16x16).
|
||||||
sneeker.spawn_mapblock_limit (Sneeker spawn limit) int 1
|
sneeker.spawn_mapblock_limit (Sneeker spawn limit) int 1
|
||||||
|
|
||||||
|
# Comma-separated list of nodes on which sneeker can spawn.
|
||||||
|
sneeker.spawn_nodes (Sneeker spawn nodes) string default:dirt_with_dry_grass,default:dry_dirt,default:dry_dirt_with_dry_grass,default:desert_sand,nether:rack
|
||||||
|
27
spawn.lua
27
spawn.lua
@@ -1,19 +1,20 @@
|
|||||||
|
|
||||||
local spawn_nodes = {
|
local spawn_nodes = {}
|
||||||
"default:dirt_with_dry_grass",
|
if sneeker.spawn_nodes ~= "" then
|
||||||
"default:dry_dirt",
|
if not sneeker.spawn_nodes:find(",") then
|
||||||
"default:dry_dirt_with_dry_grass",
|
table.insert(spawn_nodes, sneeker.spawn_nodes)
|
||||||
"default:desert_sand",
|
else
|
||||||
}
|
for _, node in ipairs(sneeker.spawn_nodes:split(",")) do
|
||||||
|
local node = node:trim()
|
||||||
if core.global_exists("nether") then
|
if node ~= "" then
|
||||||
table.insert(spawn_nodes, "nether:rack")
|
table.insert(spawn_nodes, node)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, node_name in ipairs(spawn_nodes) do
|
if #spawn_nodes == 0 then
|
||||||
if not core.registered_nodes[node_name] then
|
sneeker.log("warning", "no spawning nodes set, cannot spawn")
|
||||||
sneeker.log("warning", "Invalid node for spawn: " .. node_name)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@@ -164,8 +164,21 @@ local function add_drop(drops, item)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function is_protected(pos, name) return core.is_protected(pos, name) end
|
||||||
|
if core.global_exists("s_protect") then
|
||||||
|
is_protected = function(pos, name)
|
||||||
|
local s_protect_name = name
|
||||||
|
-- simple_protection ignores names with empty strings
|
||||||
|
if s_protect_name == "" then
|
||||||
|
s_protect_name = " "
|
||||||
|
end
|
||||||
|
|
||||||
|
return core.is_protected(pos, name) or not s_protect.can_access(pos, s_protect_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function destroy(drops, pos, cid)
|
local function destroy(drops, pos, cid)
|
||||||
if core.is_protected(pos, "") then
|
if is_protected(pos, "") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local def = cid_data[cid]
|
local def = cid_data[cid]
|
||||||
@@ -288,6 +301,8 @@ local function explode(pos, radius)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function sneeker.boom(pos, large)
|
function sneeker.boom(pos, large)
|
||||||
|
if not pos then return end
|
||||||
|
|
||||||
local radius = radius
|
local radius = radius
|
||||||
if large then
|
if large then
|
||||||
radius = large_radius
|
radius = large_radius
|
||||||
@@ -299,4 +314,5 @@ function sneeker.boom(pos, large)
|
|||||||
entity_physics(pos, radius)
|
entity_physics(pos, radius)
|
||||||
eject_drops(drops, pos, radius)
|
eject_drops(drops, pos, radius)
|
||||||
add_effects(pos, radius)
|
add_effects(pos, radius)
|
||||||
|
core.remove_node(pos)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user