Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
e1496df0a6 | ||
|
2289f6a261 | ||
|
fa8363fef6 | ||
|
00dcdda702 | ||
|
793f75e5ca | ||
|
4b2bf116d7 | ||
|
7df19604b0 | ||
|
e75731dcff | ||
|
f9c850c55d | ||
|
6033dbf52a | ||
|
b2494a40f7 | ||
|
76edba7a48 |
@@ -18,8 +18,8 @@ Settings documented in [reference][].
|
|||||||
|
|
||||||
### Requirements:
|
### Requirements:
|
||||||
|
|
||||||
- Depends: default, tnt
|
- Depends: cmer, default, tnt
|
||||||
- Optional depends: nether, sounds, simple_protection
|
- Optional depends: nether, sounds
|
||||||
|
|
||||||
### Links:
|
### Links:
|
||||||
|
|
||||||
|
9
TODO.txt
9
TODO.txt
@@ -2,4 +2,11 @@
|
|||||||
TODO:
|
TODO:
|
||||||
- add version using mobs_redo API
|
- add version using mobs_redo API
|
||||||
- add version using cmer API
|
- add version using cmer API
|
||||||
- add griefing option
|
- add wear to armor when exploding
|
||||||
|
- add no-griefing setting
|
||||||
|
- disable attacking if damage disabled
|
||||||
|
- make powered versions run faster when chasing
|
||||||
|
- fix knockback when chasing
|
||||||
|
- fix hit sound when chasing
|
||||||
|
- make sneeker stop when within 2 of player
|
||||||
|
- use asm_spawneggs for egg
|
||||||
|
@@ -3,9 +3,8 @@ v1.1
|
|||||||
----
|
----
|
||||||
- added sound when hit
|
- added sound when hit
|
||||||
- fixed entity vertical positioning
|
- fixed entity vertical positioning
|
||||||
- fixed tnt:boom node left after explosion
|
|
||||||
- added setting to customize spawn nodes
|
- added setting to customize spawn nodes
|
||||||
- added simple_protection support
|
- fixed tnt:boom node left after explosion
|
||||||
|
|
||||||
v1.0
|
v1.0
|
||||||
----
|
----
|
||||||
|
@@ -104,10 +104,6 @@
|
|||||||
<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/>
|
||||||
@@ -477,33 +473,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
</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>
|
||||||
|
|
||||||
@@ -512,7 +481,7 @@
|
|||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</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-07-20 11:23:32 </i>
|
<i style="float:right;">Last updated 2021-07-19 17:34:41 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
245
entity.lua
245
entity.lua
@@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
|
--[[
|
||||||
|
local sounds_enabled = core.get_modpath("sounds") ~= nil
|
||||||
local hit_sound
|
local hit_sound
|
||||||
|
|
||||||
if core.get_modpath("default") then
|
if sounds_enabled then
|
||||||
hit_sound = "player_damage"
|
|
||||||
elseif core.get_modpath("sounds") then
|
|
||||||
hit_sound = "sounds_entity_hit"
|
hit_sound = "sounds_entity_hit"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -52,12 +52,10 @@ local function random_turn(self)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local walk_speed = 1.5
|
|
||||||
|
|
||||||
local def = {
|
local def = {
|
||||||
hp_max = 20,
|
hp_max = 20,
|
||||||
physical = true,
|
physical = true,
|
||||||
collisionbox = {-0.25, 0.3, -0.25, 0.25, 1.8, 0.25},
|
collisionbox = {-0.25, -0.7, -0.25, 0.25, 0.8, 0.25},
|
||||||
visual = "mesh",
|
visual = "mesh",
|
||||||
mesh = "character.b3d",
|
mesh = "character.b3d",
|
||||||
textures = {"sneeker.png"},
|
textures = {"sneeker.png"},
|
||||||
@@ -70,29 +68,110 @@ local def = {
|
|||||||
walk_START = 168,
|
walk_START = 168,
|
||||||
walk_END = 187
|
walk_END = 187
|
||||||
},
|
},
|
||||||
walk_speed = walk_speed,
|
walk_speed = 1.5,
|
||||||
jump_height = 5,
|
jump_height = 5,
|
||||||
animation_speed = 30,
|
animation_speed = 30,
|
||||||
knockback_level = 2
|
knockback_level = 2
|
||||||
}
|
}
|
||||||
|
]]
|
||||||
|
|
||||||
def.on_activate = function(self, staticdata)
|
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
|
||||||
|
|
||||||
|
if #spawn_nodes == 0 then
|
||||||
|
sneeker.log("warning", "no spawning nodes set, cannot spawn")
|
||||||
|
end
|
||||||
|
|
||||||
|
local item_drops = {}
|
||||||
|
if core.registered_items["tnt:gunpowder"] then
|
||||||
|
table.insert(item_drops, {"tnt:gunpowder", {min=1, max=2}, chance=0.66})
|
||||||
|
end
|
||||||
|
|
||||||
|
local def = {
|
||||||
|
name = "sneeker:sneeker",
|
||||||
|
nametag = "Sneeker",
|
||||||
|
stats = {
|
||||||
|
hp = 20,
|
||||||
|
hostile_2 = true,
|
||||||
|
lifetime = sneeker.lifetime,
|
||||||
|
can_jump = 5,
|
||||||
|
can_swim = true,
|
||||||
|
has_knockback = true,
|
||||||
|
sneaky = true,
|
||||||
|
},
|
||||||
|
modes = {
|
||||||
|
idle = {chance=0.3},
|
||||||
|
walk = {chance=0.7, moving_speed=1.5},
|
||||||
|
--chase = {moving_speed=1.5},
|
||||||
|
--death = {},
|
||||||
|
},
|
||||||
|
model = {
|
||||||
|
mesh = "character.b3d",
|
||||||
|
textures = {"sneeker.png"},
|
||||||
|
collisionbox = {-0.25, 0.3, -0.25, 0.25, 1.8, 0.25},
|
||||||
|
rotation = -90,
|
||||||
|
animations = {
|
||||||
|
idle = {start=0, stop=79, speed=30},
|
||||||
|
walk = {start=168, stop=187, speed=30},
|
||||||
|
--chase = {start=168, stop=187, speed=30},
|
||||||
|
--death = {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
--sounds = {},
|
||||||
|
drops = item_drops,
|
||||||
|
--[[
|
||||||
|
combat = {
|
||||||
|
search_enemy = true,
|
||||||
|
},
|
||||||
|
]]
|
||||||
|
spawning = {
|
||||||
|
abm_nodes = {
|
||||||
|
spawn_on = spawn_nodes,
|
||||||
|
},
|
||||||
|
abm_interval = sneeker.spawn_interval,
|
||||||
|
abm_chance = sneeker.spawn_chance,
|
||||||
|
number = 1,
|
||||||
|
light = {min=sneeker.spawn_minlight, max=sneeker.spawn_maxlight},
|
||||||
|
height_limit = {min=sneeker.spawn_minheight, max=sneeker.spawn_maxheight},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
def.on_activate = function(self, staticdata, dtime_s)
|
||||||
|
--[[
|
||||||
self.yaw = 0
|
self.yaw = 0
|
||||||
self.anim = 1
|
self.anim = 1
|
||||||
self.timer = 0
|
self.timer = 0
|
||||||
|
]]
|
||||||
self.visualx = 1
|
self.visualx = 1
|
||||||
|
--[[
|
||||||
self.jump_timer = 0
|
self.jump_timer = 0
|
||||||
self.turn_timer = 0
|
self.turn_timer = 0
|
||||||
self.turn_speed = 0
|
self.turn_speed = 0
|
||||||
|
]]
|
||||||
self.powered = false
|
self.powered = false
|
||||||
|
--[[
|
||||||
self.knockback = false
|
self.knockback = false
|
||||||
self.state = math.random(1, 2)
|
self.state = math.random(1, 2)
|
||||||
self.old_y = self.object:get_pos().y
|
self.old_y = self.object:get_pos().y
|
||||||
|
]]
|
||||||
|
|
||||||
|
--[[
|
||||||
-- despawning
|
-- despawning
|
||||||
self.lifetime = sneeker.lifetime
|
self.lifetime = sneeker.lifetime
|
||||||
self.lifetimer = 0
|
self.lifetimer = 0
|
||||||
self.check_despawn_player_distance = true
|
self.check_despawn_player_distance = true
|
||||||
|
]]
|
||||||
|
|
||||||
local data = core.deserialize(staticdata)
|
local data = core.deserialize(staticdata)
|
||||||
if data and type(data) == "table" then
|
if data and type(data) == "table" then
|
||||||
@@ -114,7 +193,7 @@ local function isnan(n)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function expand(self)
|
local function expand(self)
|
||||||
if self.chase and self.visualx < 2 then
|
if self.expanding and self.visualx < 2 then
|
||||||
if self.hiss == false then
|
if self.hiss == false then
|
||||||
core.sound_play("sneeker_hiss", {object=self.object, gain=1.5, max_hear_distance=2*64})
|
core.sound_play("sneeker_hiss", {object=self.object, gain=1.5, max_hear_distance=2*64})
|
||||||
end
|
end
|
||||||
@@ -138,39 +217,51 @@ local function explode(self, pos)
|
|||||||
core.sound_play("sneeker_explode", {object=self.object, gain=sneeker.boom_gain, max_hear_distance=2*64})
|
core.sound_play("sneeker_explode", {object=self.object, gain=sneeker.boom_gain, max_hear_distance=2*64})
|
||||||
end
|
end
|
||||||
|
|
||||||
local function h_collides(pos, collision_info, touching_ground)
|
local function chase(self, target)
|
||||||
if not touching_ground or type(collision_info) ~= "table" or #collision_info == 0 then
|
-- FIXME: why does setting mode = "chase" not work?
|
||||||
return false
|
if not self.chase_anim then
|
||||||
|
self.object:set_animation({x=168, y=187}, 30, 0)
|
||||||
|
self.chase_anim = true
|
||||||
end
|
end
|
||||||
|
|
||||||
local pos_y = math.floor(pos.y)
|
local pos = self.object:get_pos()
|
||||||
local h_col
|
local tpos = target:get_pos()
|
||||||
|
|
||||||
for _, col in ipairs(collision_info) do
|
local vec = {x=tpos.x-pos.x, y=tpos.y-pos.y, z=tpos.z-pos.z}
|
||||||
local npos = col.node_pos
|
local yaw = math.atan(vec.z/vec.x)+math.pi^2
|
||||||
if npos and col.type == "node" then
|
if tpos.x > pos.x then
|
||||||
-- exclude ground collisions
|
yaw = yaw+math.pi
|
||||||
if math.floor(npos.y) > pos_y then
|
end
|
||||||
h_col = col
|
yaw = yaw-2
|
||||||
break
|
self.object:set_yaw(yaw)
|
||||||
end
|
local direction = {x=math.sin(yaw)*-1, y=0, z=math.cos(yaw)}
|
||||||
|
|
||||||
|
-- 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
|
||||||
end
|
end
|
||||||
|
|
||||||
if not h_col then return false end
|
if can_set then
|
||||||
|
self.object:set_velocity({x=direction.x*2.5, y=self.object:get_velocity().y, z=direction.z*2.5})
|
||||||
local h_vel = {
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
def.on_step = function(self, dtime, moveresult)
|
local function end_chase(self)
|
||||||
|
self.chasing = nil
|
||||||
|
self.chase_anim = false
|
||||||
|
self.mode = "idle"
|
||||||
|
self.expanding = false
|
||||||
|
end
|
||||||
|
|
||||||
|
def.on_step = function(self, staticdata, dtime_s)
|
||||||
|
--[[
|
||||||
-- update lifetime timer
|
-- update lifetime timer
|
||||||
-- FIXME: this is longer than realtime
|
-- FIXME: this is longer than realtime
|
||||||
self.lifetimer = self.lifetimer + dtime
|
self.lifetimer = self.lifetimer + dtime_s
|
||||||
if self.lifetimer >= self.lifetime then
|
if self.lifetimer >= self.lifetime then
|
||||||
-- TODO: should have a death animation
|
-- TODO: should have a death animation
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
@@ -183,9 +274,11 @@ def.on_step = function(self, dtime, moveresult)
|
|||||||
|
|
||||||
local ANIM_STAND = 1
|
local ANIM_STAND = 1
|
||||||
local ANIM_WALK = 2
|
local ANIM_WALK = 2
|
||||||
|
]]
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
|
|
||||||
|
--[[
|
||||||
if sneeker.despawn_player_far then
|
if sneeker.despawn_player_far then
|
||||||
-- run check about once per 60 seconds
|
-- run check about once per 60 seconds
|
||||||
local interval_reached = math.floor(self.lifetimer % 60) == 0
|
local interval_reached = math.floor(self.lifetimer % 60) == 0
|
||||||
@@ -212,13 +305,6 @@ def.on_step = function(self, dtime, moveresult)
|
|||||||
end
|
end
|
||||||
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 yaw = self.object:get_yaw()
|
||||||
local inside = core.get_objects_inside_radius(pos, 10)
|
local inside = core.get_objects_inside_radius(pos, 10)
|
||||||
local walk_speed = self.walk_speed
|
local walk_speed = self.walk_speed
|
||||||
@@ -246,9 +332,22 @@ def.on_step = function(self, dtime, moveresult)
|
|||||||
self.yaw = self.yaw-self.turn_speed
|
self.yaw = self.yaw-self.turn_speed
|
||||||
self.object:set_yaw(self.yaw)
|
self.object:set_yaw(self.yaw)
|
||||||
end
|
end
|
||||||
|
]]
|
||||||
|
|
||||||
expand(self)
|
expand(self)
|
||||||
|
|
||||||
|
local players_within_10 = {}
|
||||||
|
for _, object in ipairs(core.get_objects_inside_radius(pos, 10)) do
|
||||||
|
if object:is_player() then
|
||||||
|
table.insert(players_within_10, object)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not self.chasing then
|
||||||
|
self.chasing = players_within_10[1]
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
self.chase = false
|
self.chase = false
|
||||||
|
|
||||||
for _, object in ipairs(inside) do
|
for _, object in ipairs(inside) do
|
||||||
@@ -301,9 +400,55 @@ def.on_step = function(self, dtime, moveresult)
|
|||||||
self.turn_speed = 0.05*math.random()
|
self.turn_speed = 0.05*math.random()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if self.state == "chase" then
|
-- Jump
|
||||||
|
if self.jump_timer > 0.2 then
|
||||||
|
jump(self, pos, self.direction)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
]]
|
||||||
|
|
||||||
|
if self.chasing then
|
||||||
|
if self.chasing:get_hp() > 0 then
|
||||||
|
self.mode = "chase"
|
||||||
|
|
||||||
|
local within_2 = false
|
||||||
|
for _, object in ipairs(core.get_objects_inside_radius(pos, 2)) do
|
||||||
|
if object == self.chasing then
|
||||||
|
within_2 = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if within_2 then
|
||||||
|
if self.visualx >= 2 then
|
||||||
|
explode(self, pos)
|
||||||
|
self.chasing = nil
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
self.expanding = true
|
||||||
|
else
|
||||||
|
self.expanding = false
|
||||||
|
end
|
||||||
|
|
||||||
|
local within_10 = false
|
||||||
|
for _, object in ipairs(players_within_10) do
|
||||||
|
if object == self.chasing then
|
||||||
|
within_10 = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if within_10 then
|
||||||
|
-- follow player
|
||||||
|
chase(self, self.chasing)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end_chase(self)
|
||||||
|
|
||||||
|
--[[
|
||||||
if self.anim ~= ANIM_WALK then
|
if self.anim ~= ANIM_WALK then
|
||||||
self.object:set_animation({x=animation.walk_START, y=animation.walk_END}, anim_speed, 0)
|
self.object:set_animation({x=animation.walk_START, y=animation.walk_END}, anim_speed, 0)
|
||||||
self.anim = ANIM_WALK
|
self.anim = ANIM_WALK
|
||||||
@@ -325,7 +470,9 @@ def.on_step = function(self, dtime, moveresult)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
]]
|
||||||
|
|
||||||
|
--[[
|
||||||
if #inside ~= 0 then
|
if #inside ~= 0 then
|
||||||
for _, object in ipairs(inside) do
|
for _, object in ipairs(inside) do
|
||||||
if object:is_player() and object:get_hp() ~= 0 then
|
if object:is_player() and object:get_hp() ~= 0 then
|
||||||
@@ -367,13 +514,22 @@ def.on_step = function(self, dtime, moveresult)
|
|||||||
if can_set then
|
if can_set then
|
||||||
self.object:set_velocity({x=direction.x*2.5, y=velocity.y, z=direction.z*2.5})
|
self.object:set_velocity({x=direction.x*2.5, y=velocity.y, z=direction.z*2.5})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Jump
|
||||||
|
if self.jump_timer > 0.2 then
|
||||||
|
jump(self, pos, direction)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
self.state = "stand"
|
self.state = "stand"
|
||||||
end
|
end
|
||||||
|
]]
|
||||||
|
elseif self.mode == "chase" then
|
||||||
|
self.mode = "idle"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
-- Swim
|
-- Swim
|
||||||
local node = core.get_node(pos)
|
local node = core.get_node(pos)
|
||||||
if core.get_item_group(node.name, "water") ~= 0 then
|
if core.get_item_group(node.name, "water") ~= 0 then
|
||||||
@@ -389,8 +545,10 @@ def.on_step = function(self, dtime, moveresult)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
]]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
def.on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
|
def.on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
|
||||||
if hit_sound then
|
if hit_sound then
|
||||||
core.sound_play(hit_sound, {object=self.object}, parameters, true)
|
core.sound_play(hit_sound, {object=self.object}, parameters, true)
|
||||||
@@ -416,6 +574,7 @@ def.on_punch = function(self, puncher, time_from_last_punch, tool_capabilities,
|
|||||||
local obj = core.add_item(p, {name="tnt:gunpowder", count=math.random(0, 2)})
|
local obj = core.add_item(p, {name="tnt:gunpowder", count=math.random(0, 2)})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
]]
|
||||||
|
|
||||||
def.get_staticdata = function(self)
|
def.get_staticdata = function(self)
|
||||||
return core.serialize({
|
return core.serialize({
|
||||||
@@ -423,7 +582,11 @@ def.get_staticdata = function(self)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
core.register_entity("sneeker:sneeker", def)
|
core.register_entity("sneeker:sneeker", def)
|
||||||
|
]]
|
||||||
|
|
||||||
|
cmer.register_mob(def)
|
||||||
|
|
||||||
core.register_craftitem("sneeker:spawnegg", {
|
core.register_craftitem("sneeker:spawnegg", {
|
||||||
description = "Sneeker Spawn Egg",
|
description = "Sneeker Spawn Egg",
|
||||||
|
1
init.lua
1
init.lua
@@ -28,7 +28,6 @@ end
|
|||||||
local scripts = {
|
local scripts = {
|
||||||
"settings",
|
"settings",
|
||||||
"tnt_function",
|
"tnt_function",
|
||||||
"spawn",
|
|
||||||
"entity",
|
"entity",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
9
mod.conf
9
mod.conf
@@ -1,7 +1,8 @@
|
|||||||
name = sneeker
|
name = sneeker
|
||||||
title = Sneeker
|
title = Sneeker
|
||||||
description = An explosive nuisance.
|
description = An explosive nuisance.
|
||||||
version = 1.1
|
license = MIT
|
||||||
author = Rui
|
version = 1.0
|
||||||
depends = default, tnt
|
author = Rui, Jordan Irwin (AntumDeluge)
|
||||||
optional_depends = nether, sounds, simple_protection
|
depends = cmer, default, tnt
|
||||||
|
optional_depends = nether, sounds
|
||||||
|
71
spawn.lua
71
spawn.lua
@@ -1,71 +0,0 @@
|
|||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
if #spawn_nodes == 0 then
|
|
||||||
sneeker.log("warning", "no spawning nodes set, cannot spawn")
|
|
||||||
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
|
|
||||||
})
|
|
@@ -164,21 +164,8 @@ 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("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)
|
local function destroy(drops, pos, cid)
|
||||||
if is_protected(pos, "") then
|
if core.is_protected(pos, "") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local def = cid_data[cid]
|
local def = cid_data[cid]
|
||||||
|
Reference in New Issue
Block a user