Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
1a4166560c | ||
|
22e81d5d27 | ||
|
8e32772287 | ||
|
c599620e9d | ||
|
8ab2107d37 | ||
|
c8757c94a0 | ||
|
e6ff7a1b70 | ||
|
12e6bd79db | ||
|
4b8452538e | ||
|
031664d275 |
@@ -19,7 +19,7 @@ Settings documented in [reference][].
|
||||
### Requirements:
|
||||
|
||||
- Depends: default, tnt
|
||||
- Optional depends: nether, sounds
|
||||
- Optional depends: nether, sounds, simple_protection
|
||||
|
||||
### Links:
|
||||
|
||||
|
2
TODO.txt
2
TODO.txt
@@ -2,4 +2,4 @@
|
||||
TODO:
|
||||
- add version using mobs_redo API
|
||||
- add version using cmer API
|
||||
- fix vertical position
|
||||
- add griefing option
|
||||
|
@@ -2,6 +2,10 @@
|
||||
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
|
||||
----
|
||||
|
@@ -104,6 +104,10 @@
|
||||
<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>
|
||||
</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>
|
||||
|
||||
<br/>
|
||||
@@ -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>
|
||||
</dl>
|
||||
|
||||
@@ -481,7 +512,7 @@
|
||||
</div> <!-- id="main" -->
|
||||
<div id="about">
|
||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
||||
<i style="float:right;">Last updated 2021-07-19 17:34:41 </i>
|
||||
<i style="float:right;">Last updated 2021-07-20 11:23:32 </i>
|
||||
</div> <!-- id="about" -->
|
||||
</div> <!-- id="container" -->
|
||||
</body>
|
||||
|
59
entity.lua
59
entity.lua
@@ -1,8 +1,9 @@
|
||||
|
||||
local sounds_enabled = core.get_modpath("sounds") ~= nil
|
||||
local hit_sound
|
||||
|
||||
if sounds_enabled then
|
||||
if core.get_modpath("default") then
|
||||
hit_sound = "player_damage"
|
||||
elseif core.get_modpath("sounds") then
|
||||
hit_sound = "sounds_entity_hit"
|
||||
end
|
||||
|
||||
@@ -51,10 +52,12 @@ local function random_turn(self)
|
||||
end
|
||||
end
|
||||
|
||||
local walk_speed = 1.5
|
||||
|
||||
local def = {
|
||||
hp_max = 20,
|
||||
physical = true,
|
||||
collisionbox = {-0.25, -0.7, -0.25, 0.25, 0.8, 0.25},
|
||||
collisionbox = {-0.25, 0.3, -0.25, 0.25, 1.8, 0.25},
|
||||
visual = "mesh",
|
||||
mesh = "character.b3d",
|
||||
textures = {"sneeker.png"},
|
||||
@@ -67,7 +70,7 @@ local def = {
|
||||
walk_START = 168,
|
||||
walk_END = 187
|
||||
},
|
||||
walk_speed = 1.5,
|
||||
walk_speed = walk_speed,
|
||||
jump_height = 5,
|
||||
animation_speed = 30,
|
||||
knockback_level = 2
|
||||
@@ -135,7 +138,36 @@ local function explode(self, pos)
|
||||
core.sound_play("sneeker_explode", {object=self.object, gain=sneeker.boom_gain, max_hear_distance=2*64})
|
||||
end
|
||||
|
||||
def.on_step = function(self, dtime)
|
||||
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
|
||||
@@ -180,6 +212,13 @@ def.on_step = function(self, dtime)
|
||||
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
|
||||
@@ -262,11 +301,6 @@ def.on_step = function(self, dtime)
|
||||
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
|
||||
@@ -333,11 +367,6 @@ def.on_step = function(self, dtime)
|
||||
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
|
||||
|
4
mod.conf
4
mod.conf
@@ -1,7 +1,7 @@
|
||||
name = sneeker
|
||||
title = Sneeker
|
||||
description = An explosive nuisance.
|
||||
version = 1.0
|
||||
version = 1.1
|
||||
author = Rui
|
||||
depends = default, tnt
|
||||
optional_depends = nether, sounds
|
||||
optional_depends = nether, sounds, simple_protection
|
||||
|
@@ -106,3 +106,11 @@ sneeker.spawn_maxheight = tonumber(core.settings:get("sneeker.spawn_maxheight")
|
||||
-- @settype int
|
||||
-- @default 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).
|
||||
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 = {
|
||||
"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")
|
||||
local spawn_nodes = {}
|
||||
if sneeker.spawn_nodes ~= "" then
|
||||
if not sneeker.spawn_nodes:find(",") then
|
||||
table.insert(spawn_nodes, sneeker.spawn_nodes)
|
||||
else
|
||||
for _, node in ipairs(sneeker.spawn_nodes:split(",")) do
|
||||
local node = node:trim()
|
||||
if node ~= "" then
|
||||
table.insert(spawn_nodes, node)
|
||||
end
|
||||
end
|
||||
end
|
||||
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
|
||||
if #spawn_nodes == 0 then
|
||||
sneeker.log("warning", "no spawning nodes set, cannot spawn")
|
||||
end
|
||||
|
||||
|
||||
|
@@ -164,8 +164,21 @@ local function add_drop(drops, item)
|
||||
end
|
||||
end
|
||||
|
||||
local function is_protected(pos, name) return core.is_protected(pos, name) end
|
||||
if core.global_exists("simple_protection") and simple_protection.can_access 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 simple_protection.can_access(pos, s_protect_name)
|
||||
end
|
||||
end
|
||||
|
||||
local function destroy(drops, pos, cid)
|
||||
if core.is_protected(pos, "") then
|
||||
if is_protected(pos, "") then
|
||||
return
|
||||
end
|
||||
local def = cid_data[cid]
|
||||
@@ -301,4 +314,5 @@ function sneeker.boom(pos, large)
|
||||
entity_physics(pos, radius)
|
||||
eject_drops(drops, pos, radius)
|
||||
add_effects(pos, radius)
|
||||
core.remove_node(pos)
|
||||
end
|
||||
|
Reference in New Issue
Block a user