mobs_mc/enderman.lua

144 lines
3.4 KiB
Lua

--MCmobs v0.4
--maikerumine
--made for MC like Survival game
--License for code WTFPL and otherwise stated in readmes
--dofile(minetest.get_modpath("mobs").."/api.lua")
--###################
--################### ENDERMAN
--###################
local pr = PseudoRandom(os.time()*(-334))
local takable = {
-- For entensions
"enderman_takable",
-- Generic
"sand",
"flower",
-- Minetest Game
"default:dirt",
"default:dirt_with_grass",
"default:dirt_with_dry_grass",
"default:dirt_with_snow",
"default:dirt_with_rainforest_litter",
"default:dirt_with_grass_footsteps",
"default:cactus",
"default:gravel",
"default:clay",
"flowers:mushroom_red",
"flowers:mushroom_brown",
"tnt:tnt",
-- Nether mod
"nether:rack",
}
mobs:register_mob("mobs_mc:enderman", {
type = "monster",
runaway = true,
pathfinding = 2,
stepheight = 1.2,
hp_min = 40,
hp_max = 40,
collisionbox = {-0.3, -0.01, -0.3, 0.3, 2.89, 0.3},
rotate = -180,
visual = "mesh",
mesh = "enderman.b3d",
textures = {
{"mobs_mc_enderman.png^(mobs_mc_enderman_eyes.png^[makealpha:0,0,0)"},
},
visual_size = {x=3, y=3},
makes_footstep_sound = true,
sounds = {
random = "mobs_sandmonster",
death = "green_slime_death",
damage = "Creeperdeath",
},
walk_velocity = 0.2,
run_velocity = 3.4,
damage = 7,
drops = {
{name = "farorb:farorb",
chance = 3,
min = 0,
max = 1,},
{name = "mobs_mc:enderman_head",
chance = 50,
min = 0,
max = 1,},
},
animation = {
speed_normal = 25, speed_run = 50,
stand_start = 40, stand_end = 80,
walk_start = 0, walk_end = 40,
run_start = 0, run_end = 40,
},
_taken_node = "",
do_custom = function(self, dtime)
-- Take and put nodes
if not self._take_place_timer then
self._take_place_timer = 0
return
end
self._take_place_timer = self._take_place_timer + dtime
if (self._taken_node == nil or self._taken_node == "") and self._take_place_timer >= 10 then
-- Take random node
self._take_place_timer = 0
local pos = self.object:getpos()
local takable_nodes = minetest.find_nodes_in_area({x=pos.x-2, y=pos.y-1, z=pos.z-2}, {x=pos.x+2, y=pos.y+1, z=pos.z+2}, takable)
if #takable_nodes >= 1 then
local r = pr:next(1, #takable_nodes)
local take_pos = takable_nodes[r]
local node = minetest.get_node(take_pos)
local dug = minetest.dig_node(take_pos)
if dug then
self._taken_node = node.name
-- TODO: Update enderman model
minetest.sound_play(sound, {pos=pos, max_hear_distance = 16})
end
end
elseif self._taken_node ~= nil and self._taken_node ~= "" and self._take_place_timer >= 10 then
-- Place taken node
self._take_place_timer = 0
local pos = self.object:getpos()
-- TODO: Place around enderman
minetest.place_node({x=pos.x+1, y=pos.y, z=pos.z}, {name = self._taken_node})
self._taken_node = ""
end
end,
on_die = function(self, pos)
-- Drop carried node on death
if self._taken_node ~= nil and self._taken_node ~= "" then
minetest.add_item(pos, self._taken_node)
end
end,
drawtype = "front",
water_damage = 8,
lava_damage = 5,
light_damage = 0,
view_range = 16,
fear_height = 10,
attack_type = "dogfight",
})
--spawn on solid blocks
mobs:register_spawn("mobs_mc:enderman", { "group:crumbly", "group:cracky", "group:solid" }, 7, 0, 9000, 1, 31000)
-- spawn eggs
mobs:register_egg("mobs_mc:enderman", "Enderman", "mobs_mc_spawn_icon_enderman.png", 0)
if minetest.settings:get_bool("log_mods") then
minetest.log("action", "MC Enderman loaded")
end