diff --git a/init.lua b/init.lua index 5881a3e..b6a8d69 100644 --- a/init.lua +++ b/init.lua @@ -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,25 +38,26 @@ 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 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}) + 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 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 = {} + local def, def2 = {} if node and node.name then def = core.registered_items[node.name] end @@ -68,16 +68,16 @@ local function jump(self,pos,direction) 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 + 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 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 @@ -93,7 +93,7 @@ end local def = { hp_max = 20, physical = true, - collisionbox = {-0.25,-0.7,-0.25, 0.25,0.8,0.25}, + collisionbox = {-0.25, -0.7, -0.25, 0.25, 0.8, 0.25}, visual = "mesh", mesh = "character.b3d", textures = {"sneeker.png"}, @@ -112,7 +112,7 @@ local def = { knockback_level = 2 } -def.on_activate = function(self,staticdata) +def.on_activate = function(self, staticdata) self.yaw = 0 self.anim = 1 self.timer = 0 @@ -122,7 +122,7 @@ def.on_activate = function(self,staticdata) self.turn_speed = 0 self.powered = false self.knockback = false - self.state = math.random(1,2) + self.state = math.random(1, 2) self.old_y = self.object:get_pos().y local data = core.deserialize(staticdata) @@ -132,18 +132,13 @@ def.on_activate = function(self,staticdata) self.object:set_properties({textures = {"sneeker_powered.png"}}) end else - if math.random(0,20) == 20 then + 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) if self.knockback then return @@ -154,7 +149,7 @@ def.on_step = function(self, dtime) local pos = self.object:get_pos() 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 animation = self.animation local anim_speed = self.animation_speed @@ -165,7 +160,7 @@ def.on_step = function(self, dtime) self.jump_timer = self.jump_timer+0.01 if not self.chase - and self.timer > math.random(2,5) then + and self.timer > math.random(2, 5) then if math.random() > 0.8 then self.state = "stand" else @@ -184,24 +179,24 @@ def.on_step = function(self, dtime) 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}) + 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} + 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} + visual_size = {x=self.visualx, y=1} }) self.hiss = false end self.chase = false - for _,object in ipairs(inside) do + for _, object in ipairs(inside) do if object:is_player() then self.state = "chase" end @@ -209,7 +204,7 @@ def.on_step = function(self, dtime) 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.object:set_animation({x=animation.stand_START, y=animation.stand_END}, anim_speed, 0) self.anim = ANIM_STAND end @@ -217,19 +212,19 @@ def.on_step = function(self, dtime) if velocity.x ~= 0 or velocity.z ~= 0 then - self.object:set_velocity({x=0,y=velocity.y,z=0}) + 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.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)} + 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}) + self.object:set_velocity({x=self.direction.x*walk_speed, y=velocity.y, z=self.direction.z*walk_speed}) end random_turn(self) @@ -238,10 +233,10 @@ def.on_step = function(self, dtime) 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} + 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) + local select_turn = math.random(1, 2) if select_turn == 1 then self.turn = "left" elseif select_turn == 2 then @@ -254,79 +249,67 @@ def.on_step = function(self, dtime) -- Jump if self.jump_timer > 0.2 then - jump(self,pos,self.direction) + 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.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) + local inside_2 = core.get_objects_inside_radius(pos, 2) -- Boom if #inside_2 ~= 0 then - for _,object in ipairs(inside_2) do + 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=1.5,max_hear_distance=2*64}) + sneeker.boom(pos, self.powered) + core.sound_play("sneeker_explode", {pos=pos, gain=1.5, max_hear_distance=2*64}) end end end end 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 #inside_2 ~= 0 then - for _,object in ipairs(inside_2) do + 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.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}) + 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.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)} + 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 + self.object:set_velocity({x=direction.x*2.5, y=velocity.y, z=direction.z*2.5}) -- Jump if self.jump_timer > 0.2 then - jump(self,pos,direction) + jump(self, pos, direction) end end end @@ -337,38 +320,38 @@ def.on_step = function(self, dtime) -- 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}) + 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}) + 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}) + self.object:set_velocity({x=0, y=velocity.y+1, z=0}) end else - self.object:set_acceleration({x=0,y=-10,z=0}) + self.object:set_acceleration({x=0, y=-10, z=0}) 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 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.object:set_velocity({x=dir.x*knockback_level, y=3, z=dir.z*knockback_level}) self.knockback = true - core.after(0.6,function() + 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 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)}) + local obj = core.add_item(p, {name="tnt:gunpowder", count=math.random(0, 2)}) end end @@ -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({ diff --git a/mod.conf b/mod.conf index d830e51..431af16 100644 --- a/mod.conf +++ b/mod.conf @@ -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