-- File: codersea/seasprites.lua -- Purpose: CoderSea sprite-creatures support -- Credits: See "codersea.md" -- Licenses: See "LICENSE" -- NODES minetest.register_node ("codersea:sandalgae", { description = "Sandalgae", tiles = {"default_sand.png^clams_algae.png"}, paramtype = "light", is_ground_content = true, groups = { crumbly = 3, falling_node=1, sand=1, seasand=1 } , sounds = default.node_sound_sand_defaults(), }) minetest.register_node ("codersea:dirtalgae", { description = "Dirtalgae", tiles = {"default_dirt.png^clams_algae.png"}, paramtype = "light", is_ground_content = true, groups = { crumbly=3, seasoil=1 } , sounds = default.node_sound_dirt_defaults(), }) function StartsWith (String, Start) return string.sub (String, 1, string.len (Start)) == Start end function EndsWith (String, End) return End == '' or string.sub (String, -string.len (End)) == End end -- ENTITIES -- The registration of the entities' code is adapted from -- celeron55's old mob code (the DM's fireball) local function makeseasprite (params) minetest.register_entity ("codersea:" .. params.basename, { collisionbox = { -0.2, -0.2, -0.2, 0.2, 0.2, 0.2 } , description = params.description , drops = params.drops , hp_max = params.hp_mx , initial_sprite_basepos = { x=0, y=0 } , phase = 0 , phasetimer = 0 , physical = true , spritediv = params.spritediv , textures = params.textures , visual = "sprite" , visual_size = params.visual_size , -- on_activate = function (self, staticdata) -- minetest.log (params.basename .. " activated") -- end , on_step = function(self, dtime) self.phasetimer = self.phasetimer + dtime if self.phasetimer > params.phasetime then self.phasetimer = self.phasetimer - params.phasetime self.phase = self.phase + 1 if self.phase >= params.numphases then self.phase = 0 end self.object:setsprite ({ x = 0, y = self.phase }) local armor = nil if params.phasearmor ~= nil then armor = params.phasearmor [self.phase] if armor == nil then armor = params.phasearmor [0] end end if armor == nil then if params.fleshy == nil then armor = { fleshy = 75 } else armor = { fleshy = params.fleshy } end end self.object:set_armor_groups (armor) end end, on_punch = function(self, hitter) if self.object:get_hp() <= 0 then if hitter and hitter:is_player() and hitter:get_inventory() then for _,drop in ipairs(self.drops) do if math.random(1, drop.chance) == 1 then hitter:get_inventory():add_item ("main", ItemStack (drop.name .. " " .. math.random (drop.min, drop.max))) end end else for _,drop in ipairs(self.drops) do if math.random(1, drop.chance) == 1 then for i=1,math.random(drop.min, drop.max) do local obj = minetest.add_item (self.object:getpos(), drop.name) if obj then obj:get_luaentity().collect = true local x = math.random(1, 5) if math.random(1,2) == 1 then x = -x end local z = math.random(1, 5) if math.random(1,2) == 1 then z = -z end obj:setvelocity ({ x=1/x, y=obj:getvelocity().y, z=1/z}) end end end end end end end , }) end local params_clam = { basename = "whiteshell" , description = "Clam" , hp_max = 0 , spritediv = { x=1, y=3 } , phasetime = 2.0 , numphases = 3 , visual_size = { x=0.5, y=0.5 } , textures = { "clams_whiteshell.png^[makealpha:128,128,0" , } , drops = { { name = "default:glass", chance = 1, min = 1, max = 4 }, } , phasearmor = { [0] = { fleshy = 0 } , [1] = { fleshy = 30 } , [2] = { fleshy = 70 } , } , } local params_starfish = { basename = "starfish" , description = "Starfish" , hp_max = 15 , spritediv = { x = 1, y = 5 } , numphases = 5 , phasetime = 1.5 , visual_size = { x=0.5, y=0.5 } , textures = { "starfishsprite.png^[makealpha:128,128,0" , } , drops = { { name = "default:wood", chance = 1, min = 1, max = 4 } , } , phasearmor = { [0] = { fleshy = 10 } , } , } local params_oddfish = { fleshy = 20 , basename = "oddfish" , description = "Odd fish" , hp_max = 15 , spritediv = { x = 1, y = 2 } , numphases = 2 , phasetime = 4.0 , visual_size = { x=1.0, y=1.0 } , textures = { "oddfish01.png^[makealpha:128,128,0" , } , drops = { { name = "default:wood", chance = 1, min = 1, max = 4 } , } , } makeseasprite (params_clam ) makeseasprite (params_starfish ) params_oddfish.basename = "oddfish01" params_oddfish.textures = { "oddfish01.png^[makealpha:128,128,0" } makeseasprite (params_oddfish ) params_oddfish.basename = "oddfish02" params_oddfish.textures = { "oddfish02.png^[makealpha:128,128,0" } makeseasprite (params_oddfish ) params_oddfish.basename = "oddfish03" params_oddfish.textures = { "oddfish03.png^[makealpha:128,128,0" } makeseasprite (params_oddfish ) params_oddfish.basename = "oddfish04" params_oddfish.textures = { "oddfish04.png^[makealpha:128,128,0" } makeseasprite (params_oddfish ) -- CRAFT ITEMS minetest.register_craftitem ("codersea:collectedalgae", { description = "Collected algae", inventory_image = "clams_collectedalgae.png", }) minetest.register_craftitem ("codersea:crushedwhite", { description = "Crushed white shell", inventory_image = "clams_crushedwhite.png", }) minetest.register_abm ({ catch_up = false , nodenames = { "codersea:dirtalgae", "codersea:sandalgae" } , interval = 20 , chance = 5 , action = function (pos, node, aocb, aocw) if (aocb + aocw) > 40 then return end local ya = {x = pos.x, y = pos.y + 1, z = pos.z } if not is_water (ya) then return end local yy = {x = pos.x, y = pos.y + 2, z = pos.z } if not is_water (yy) then return end local ptable = { "codersea:starfish" , "codersea:whiteshell" , } if math.random (1, 12) == 1 then ptable = { "codersea:oddfish01" , "codersea:oddfish02" , "codersea:oddfish03" , "codersea:oddfish04" , } end local ent = nil local nument = 0 local tnob = minetest.get_objects_inside_radius (ya, 0.5) local nnob = table.getn (tnob) if (nnob > 0) then for foo,obj in ipairs (tnob) do ent = obj:get_luaentity() if ent ~= nil then nument = nument + 1 end end end if (nument > 1) then for foo,obj in ipairs (tnob) do ent = obj:get_luaentity() if ent ~= nil then obj:remove() end end nument = 0 end if (nument == 0) then local newobj = ptable [math.random (#ptable)] minetest.add_entity (ya, newobj) end end }) minetest.register_privilege ("seaadmin", { description = "Can use /deleteentsea" , give_to_singleplayer = false }) function deleteentsea (radius) local pos = player:getpos() local ent = nil local tnob = minetest.get_objects_inside_radius (pos, radius) local nnob = table.getn (tnob) if (nnob > 0) then for foo,obj in ipairs (tnob) do ent = obj:get_luaentity() if ent ~= nil and ent.name ~= nil then if StartsWith (ent.name, "codersea:") then obj:remove() end end end end end minetest.register_on_chat_message (function (name, message) local cmd = "/deleteentsea" if message:sub (0, #cmd) ~= cmd or message ~= cmd then return false end local player = minetest.env:get_player_by_name (name) if not minetest.check_player_privs (name, { seaadmin=true }) then minetest.chat_send_player (name, "Sorry, you don't have privileges for that") return false end deleteentsea (15) return true end)