forked from Mirrorlandia_minetest/mod-sneeker
Begin converting to cmer API
This commit is contained in:
parent
1321b3092f
commit
76edba7a48
107
entity.lua
107
entity.lua
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
--[[
|
||||||
local sounds_enabled = core.get_modpath("sounds") ~= nil
|
local sounds_enabled = core.get_modpath("sounds") ~= nil
|
||||||
local hit_sound
|
local hit_sound
|
||||||
|
|
||||||
@ -72,24 +73,99 @@ local def = {
|
|||||||
animation_speed = 30,
|
animation_speed = 30,
|
||||||
knockback_level = 2
|
knockback_level = 2
|
||||||
}
|
}
|
||||||
|
]]
|
||||||
|
|
||||||
def.on_activate = function(self, staticdata)
|
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
|
||||||
|
|
||||||
|
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},
|
||||||
|
follow = {radius=10},
|
||||||
|
--death = {},
|
||||||
|
},
|
||||||
|
model = {
|
||||||
|
mesh = "character.b3d",
|
||||||
|
textures = {"sneeker.png"},
|
||||||
|
collisionbox = {-0.25, -0.7, -0.25, 0.25, 0.8, 0.25},
|
||||||
|
rotation = -90,
|
||||||
|
animations = {
|
||||||
|
idle = {start=0, stop=79, speed=30},
|
||||||
|
walk = {start=168, stop=187, speed=30},
|
||||||
|
follow = {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
|
||||||
@ -106,9 +182,11 @@ def.on_activate = function(self, staticdata)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--[[
|
||||||
local function isnan(n)
|
local function isnan(n)
|
||||||
return tostring(n) == tostring((-1)^.5)
|
return tostring(n) == tostring((-1)^.5)
|
||||||
end
|
end
|
||||||
|
]]
|
||||||
|
|
||||||
local function expand(self)
|
local function expand(self)
|
||||||
if self.chase and self.visualx < 2 then
|
if self.chase and self.visualx < 2 then
|
||||||
@ -135,10 +213,16 @@ 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
|
||||||
|
|
||||||
def.on_step = function(self, dtime)
|
local item_drops = {}
|
||||||
|
if core.registered_items["tnt:gunpowder"] then
|
||||||
|
table.insert(item_drops, {"tnt:gunpowder", {min=1, max=2}, chance=0.66})
|
||||||
|
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()
|
||||||
@ -151,9 +235,11 @@ def.on_step = function(self, dtime)
|
|||||||
|
|
||||||
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
|
||||||
@ -207,9 +293,11 @@ def.on_step = function(self, dtime)
|
|||||||
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)
|
||||||
|
|
||||||
|
--[[
|
||||||
self.chase = false
|
self.chase = false
|
||||||
|
|
||||||
for _, object in ipairs(inside) do
|
for _, object in ipairs(inside) do
|
||||||
@ -268,14 +356,17 @@ def.on_step = function(self, dtime)
|
|||||||
jump(self, pos, self.direction)
|
jump(self, pos, self.direction)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
]]
|
||||||
|
|
||||||
if self.state == "chase" then
|
if self.state == "chase" then
|
||||||
|
--[[
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
self.turn = "straight"
|
self.turn = "straight"
|
||||||
|
]]
|
||||||
|
|
||||||
local inside_2 = core.get_objects_inside_radius(pos, 2)
|
local inside_2 = core.get_objects_inside_radius(pos, 2)
|
||||||
|
|
||||||
@ -292,6 +383,7 @@ def.on_step = function(self, dtime)
|
|||||||
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
|
||||||
@ -343,8 +435,10 @@ def.on_step = function(self, dtime)
|
|||||||
else
|
else
|
||||||
self.state = "stand"
|
self.state = "stand"
|
||||||
end
|
end
|
||||||
|
]]
|
||||||
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
|
||||||
@ -360,8 +454,10 @@ def.on_step = function(self, dtime)
|
|||||||
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)
|
||||||
@ -387,6 +483,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({
|
||||||
@ -394,7 +491,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",
|
||||||
|
5
mod.conf
5
mod.conf
@ -1,7 +1,8 @@
|
|||||||
name = sneeker
|
name = sneeker
|
||||||
title = Sneeker
|
title = Sneeker
|
||||||
description = An explosive nuisance.
|
description = An explosive nuisance.
|
||||||
|
license = MIT
|
||||||
version = 1.0
|
version = 1.0
|
||||||
author = Rui
|
author = Rui, Jordan Irwin (AntumDeluge)
|
||||||
depends = default, tnt
|
depends = cmer, default, tnt
|
||||||
optional_depends = nether, sounds
|
optional_depends = nether, sounds
|
||||||
|
Loading…
Reference in New Issue
Block a user