local reg_nodes = minetest.registered_nodes

local function standing_check(self)
	if self.movement == "air"
	then
		return false
	end

	if self.object:getvelocity().y ~= 0
	then
		return false
	end

	-- Check the four bottom corners for collision
	local p = self.object:get_pos()
	p.y = p.y + self.collisionbox[2] - 0.25
	local corners = {
		vector.add(p, {x = self.collisionbox[1], y = 0, z = self.collisionbox[3]}),
		vector.add(p, {x = self.collisionbox[1], y = 0, z = self.collisionbox[6]}),
		vector.add(p, {x = self.collisionbox[4], y = 0, z = self.collisionbox[3]}),
		vector.add(p, {x = self.collisionbox[4], y = 0, z = self.collisionbox[6]}),
	}
	for _,c in ipairs(corners)
	do
		local node = minetest.get_node_or_nil(c)
		
		if not node or
			(reg_nodes[node.name] or {walkable = true}).walkable
		then
			return true
		end
	end
	
	return false
end

function defense_mob_api.library.is_standing(self)
	self.standing = standing_check(self)
end
