Begin porting to creatures (cmer) mob engine

This commit is contained in:
Jordan Irwin 2021-05-05 20:26:10 -07:00
parent ff01e876f5
commit 9046b0fad7
2 changed files with 123 additions and 75 deletions

@ -1,5 +1,3 @@
-- Original code by Rui: WTFPL
sneeker = {}
sneeker.modname = core.get_current_modname()
@ -29,7 +27,8 @@ end
sneeker.log("debug", "Debugging is on")
if core.settings:get_bool("log_mods", false) then
if core.settings:get_bool("log_mods") then
core.log("action", "Loading mod \"" .. sneeker.modname .. "\" ...")
end
@ -39,13 +38,14 @@ local old_spawnegg_name = "sneeker:spawnegg"
local scripts = {
"functions",
"tnt_function",
"spawn",
--"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
@ -139,11 +139,6 @@ def.on_activate = function(self,staticdata)
end
end
local function isnan(n)
return tostring(n) == tostring((-1)^.5)
end
def.on_step = function(self, dtime)
if self.knockback then
return
@ -310,19 +305,7 @@ def.on_step = function(self, dtime)
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
@ -379,6 +362,71 @@ def.get_staticdata = function(self)
end
core.register_entity(sneeker.mob_name, def)
--]]
local spawn_nodes = {
"default:dirt",
"default:dirt_with_grass",
"default:dry_dirt_with_dry_grass",
"default:desert_sand",
"default:sand",
}
if core.global_exists("nether") then
table.insert(spawn_nodes, "nether:rack")
end
cmer.register_mob({
name = sneeker.mob_name,
stats = {
hp = 20,
hostile = true,
lifetime = 15 * 60, -- 15 minutes
can_jump = 5,
has_kockback = true,
sneaky = true,
},
modes = {
idle = {chance=0.3, moving_speed=0,},
walk = {chance=0.7, moving_speed=1.5,},
},
model = {
mesh = "character.b3d",
textures = {"sneeker.png"},
collisionbox = {-0.25, -0.7, -0.25, 0.25, 0.8, 0.25},
animations = {
idle = {start=0, stop=79, speed=30,},
walk = {start=168, stop=187, speed=30,},
},
},
sounds = {},
drops = {
{"tnt:gunpowder", {min=1, max=2}, chance=0.66},
},
combat = {
--[[
attack_damage = ,
attack_speed = ,
attack_radius = ,
search_enemy = true,
search_timer = ,
search_radius = ,
search_type = "player",
]]
},
spawning = {
abm_nodes = spawn_nodes,
abm_interval = sneeker.spawn_interval,
abm_chance = sneeker.spawn_chance,
max_number = 1,
number = 1,
time_range = {min=0, max=23999},
light = {min=sneeker.spawn_minlight, max=sneeker.spawn_maxlight},
height_limit = {min=sneeker.spawn_minheight, max=sneeker.spawn_maxheight},
},
})
if core.global_exists("asm") then
asm.addEgg({

@ -2,5 +2,5 @@ name = sneeker
title = Sneeker
description = An explosive nuisance.
author = Rui
depends = default, tnt
depends = cmer, default, tnt
optional_depends = asm_spawneggs, nether