defense_mob_api.register_mob("mob_unggoy:unggoy", {
	hp_max = 11,
	collisionbox = {-0.4, -0.01, -0.4, 0.4, 1.3, 0.4},
	mesh = "mob_unggoy_unggoy.b3d",
	textures = {"mob_unggoy_unggoy.png"},
	makes_footstep_sound = true,

	animation = {
		idle = {a=0, b=39, rate=30},
		jump = {a=40, b=49, rate=15},
		fall = {a=50, b=64, rate=20},
		attack = {a=65, b=72, rate=15},
		move = {a=75, b=99, rate=40},
		move_attack = {a=100, b=113, rate=20},
	},
	smart_path = false,
	smart_path_for = 0, --initializing to 0 >= 0 means it's going to switch on and off
	swarm = true,

	mass = 4,
	move_speed = 5,
	jump_height = 2,
	armor = 0,
	attack_damage = 1,
	attack_range = 1.5,
	attack_interval = 0.6,

	wander = false,


	on_activate = function(self, staticdata)
		self.swarm:signup(self)
		defense_mob_api.default_prototype.on_activate(self, staticdata)
		staticdata = minetest.deserialize(staticdata) or {}
		if staticdata.spawn_with_bombs
		then
			local bombref = minetest.add_entity(
				self.object:get_pos(),
				"gunpowder_barrels:barrel_entity")
			if bombref
			then
				bombref:set_attach(
					self.object,
					"",
					{x = 0, y = 15, z = 0},
					{x = 0, y = 0, z = 0})
				bombref:get_luaentity():start_fuse(math.random() * 400 + 200)
			end
		end
		-- Some monkeys can jump higher
		if math.random() < 0.1
		then
			self.jump_height = self.jump_height + math.random() * 2
		end
	end,

	on_step = function(self, dtime)
		defense_mob_api.default_prototype.on_step(self, dtime)
		if self.wander
		then

			local g = vector.add(
				self.object:get_pos(),
				{x = math.random(-12, 12) + 4, y = 0, z = math.random(-12, 12) + 4}
			)
			local node = minetest.get_node_or_nil(g)
			node = minetest.registered_nodes[node] or {walkable = true}
			if  not node.walkable
			then
				self.destination = g
			end
			self.wander = false
		elseif math.random() < 0.006
		then
			self.wander = true
		end
		self:hunt()
	end,

	is_standing = function(self)
		-- Able to stand on top of others
		if defense_mob_api.default_prototype.is_standing(self)
		then
			return true
		else
			local vel = self.object:getvelocity()
			if math.abs(vel.y) > 0.2
			then
				return false
			end

			local pos = self.object:get_pos()
			pos.y = pos.y - 1
			for _,o in ipairs(minetest.get_objects_inside_radius(pos, 1))
			do
				if o ~= self.object
				then
					local e = o:get_luaentity()
					if e and e.name == self.name
					then
						return true
					end
				end
			end
			return false
		end
	end,
	--[[
	on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
	defense_mob_api.default_prototype.on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
		self.swarm:alert(self.object:get_pos(), 3,
			function(selfobj, dist)
				selfobj:remove()
			end)
	end,
	]]
})
minetest.register_alias("unggoy", "mob_unggoy:unggoy")
